module Aws.Kinesis.Reshard.Options where
import qualified Data.Text as T
import Options.Applicative
import Control.Applicative.Unicode
import Control.Lens
import Data.Monoid.Unicode
import Prelude.Unicode
data Options
= Options
{ _oAccessKey ∷ !T.Text
, _oSecretAccessKey ∷ !T.Text
, _oRegion ∷ !T.Text
, _oStreamName ∷ !T.Text
, _oSampleDuration ∷ !Integer
, _oShardCapacityThreshold ∷ !Double
, _oMaximumShardCount ∷ !Int
, _oReshardingInterval ∷ !Int
} deriving Show
makeLenses ''Options
accessKeyParser ∷ Parser T.Text
accessKeyParser =
fmap T.pack ∘ option str $
long "access-key"
⊕ metavar "AK"
⊕ help "Your AWS access key"
secretAccessKeyParser ∷ Parser T.Text
secretAccessKeyParser =
fmap T.pack ∘ option str $
long "secret-access-key"
⊕ metavar "SK"
⊕ help "Your AWS secret access key"
regionParser ∷ Parser T.Text
regionParser =
fmap T.pack ∘ option str $
long "region"
⊕ short 'r'
⊕ metavar "R"
⊕ help "The AWS region"
⊕ value "us-west-2"
⊕ showDefault
streamNameParser ∷ Parser T.Text
streamNameParser =
fmap T.pack ∘ option str $
long "stream-name"
⊕ short 's'
⊕ metavar "SN"
⊕ help "The Kinesis stream name"
sampleDurationParser ∷ Parser Integer
sampleDurationParser =
option auto $
long "sample-duration"
⊕ short 'd'
⊕ metavar "SD"
⊕ help "The sample duration in seconds"
⊕ value (60 * 60)
⊕ showDefault
capacityThresholdReader ∷ ReadM Double
capacityThresholdReader = do
cap ← auto
if | cap > 0 ∧ cap ≤ 1 → return cap
| otherwise → readerError "Capacity threshold must be in range (0,1]"
capacityThresholdParser ∷ Parser Double
capacityThresholdParser =
option capacityThresholdReader $
long "shard-capacity-threshold"
⊕ short 't'
⊕ metavar "SCT"
⊕ help "The threshold percent capacity per shard (max: 1)"
⊕ value 0.1
⊕ showDefault
maximumShardCountReader ∷ ReadM Int
maximumShardCountReader = do
count ← auto
if | count > 0 ∧ count <= 10 → return count
| otherwise → readerError "Maximum shard count must be in range [1,10]"
maximumShardCountParser ∷ Parser Int
maximumShardCountParser =
option maximumShardCountReader $
long "maximum-shard-count"
⊕ short 'c'
⊕ metavar "MSC"
⊕ help "The maximum number of shards permitted on this stream (max: 10)"
⊕ value 5
⊕ showDefault
reshardingIntervalParser ∷ Parser Int
reshardingIntervalParser =
option auto $
long "resharding-interval"
⊕ short 'i'
⊕ metavar "RI"
⊕ help "The time to wait before reanalyzing the stream in seconds"
⊕ value 60000000
⊕ showDefault
optionsParser ∷ Parser Options
optionsParser =
pure Options
⊛ accessKeyParser
⊛ secretAccessKeyParser
⊛ regionParser
⊛ streamNameParser
⊛ sampleDurationParser
⊛ capacityThresholdParser
⊛ maximumShardCountParser
⊛ reshardingIntervalParser
parserInfo ∷ ParserInfo Options
parserInfo =
info (helper ⊛ optionsParser) $
fullDesc
⊕ progDesc "Monitor Kinesis throughput and reshard accordingly"
⊕ header "The Kinesis Resharder CLI"