{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Kinesis.EnableEnhancedMonitoring
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Enables enhanced Kinesis data stream monitoring for shard-level metrics.
module Amazonka.Kinesis.EnableEnhancedMonitoring
  ( -- * Creating a Request
    EnableEnhancedMonitoring (..),
    newEnableEnhancedMonitoring,

    -- * Request Lenses
    enableEnhancedMonitoring_streamName,
    enableEnhancedMonitoring_shardLevelMetrics,

    -- * Destructuring the Response
    EnhancedMonitoringOutput (..),
    newEnhancedMonitoringOutput,

    -- * Response Lenses
    enhancedMonitoringOutput_desiredShardLevelMetrics,
    enhancedMonitoringOutput_currentShardLevelMetrics,
    enhancedMonitoringOutput_streamName,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Kinesis.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Represents the input for EnableEnhancedMonitoring.
--
-- /See:/ 'newEnableEnhancedMonitoring' smart constructor.
data EnableEnhancedMonitoring = EnableEnhancedMonitoring'
  { -- | The name of the stream for which to enable enhanced monitoring.
    EnableEnhancedMonitoring -> Text
streamName :: Prelude.Text,
    -- | List of shard-level metrics to enable.
    --
    -- The following are the valid shard-level metrics. The value \"@ALL@\"
    -- enables every metric.
    --
    -- -   @IncomingBytes@
    --
    -- -   @IncomingRecords@
    --
    -- -   @OutgoingBytes@
    --
    -- -   @OutgoingRecords@
    --
    -- -   @WriteProvisionedThroughputExceeded@
    --
    -- -   @ReadProvisionedThroughputExceeded@
    --
    -- -   @IteratorAgeMilliseconds@
    --
    -- -   @ALL@
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/kinesis/latest/dev/monitoring-with-cloudwatch.html Monitoring the Amazon Kinesis Data Streams Service with Amazon CloudWatch>
    -- in the /Amazon Kinesis Data Streams Developer Guide/.
    EnableEnhancedMonitoring -> [MetricsName]
shardLevelMetrics :: [MetricsName]
  }
  deriving (EnableEnhancedMonitoring -> EnableEnhancedMonitoring -> Bool
(EnableEnhancedMonitoring -> EnableEnhancedMonitoring -> Bool)
-> (EnableEnhancedMonitoring -> EnableEnhancedMonitoring -> Bool)
-> Eq EnableEnhancedMonitoring
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableEnhancedMonitoring -> EnableEnhancedMonitoring -> Bool
$c/= :: EnableEnhancedMonitoring -> EnableEnhancedMonitoring -> Bool
== :: EnableEnhancedMonitoring -> EnableEnhancedMonitoring -> Bool
$c== :: EnableEnhancedMonitoring -> EnableEnhancedMonitoring -> Bool
Prelude.Eq, ReadPrec [EnableEnhancedMonitoring]
ReadPrec EnableEnhancedMonitoring
Int -> ReadS EnableEnhancedMonitoring
ReadS [EnableEnhancedMonitoring]
(Int -> ReadS EnableEnhancedMonitoring)
-> ReadS [EnableEnhancedMonitoring]
-> ReadPrec EnableEnhancedMonitoring
-> ReadPrec [EnableEnhancedMonitoring]
-> Read EnableEnhancedMonitoring
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnableEnhancedMonitoring]
$creadListPrec :: ReadPrec [EnableEnhancedMonitoring]
readPrec :: ReadPrec EnableEnhancedMonitoring
$creadPrec :: ReadPrec EnableEnhancedMonitoring
readList :: ReadS [EnableEnhancedMonitoring]
$creadList :: ReadS [EnableEnhancedMonitoring]
readsPrec :: Int -> ReadS EnableEnhancedMonitoring
$creadsPrec :: Int -> ReadS EnableEnhancedMonitoring
Prelude.Read, Int -> EnableEnhancedMonitoring -> ShowS
[EnableEnhancedMonitoring] -> ShowS
EnableEnhancedMonitoring -> String
(Int -> EnableEnhancedMonitoring -> ShowS)
-> (EnableEnhancedMonitoring -> String)
-> ([EnableEnhancedMonitoring] -> ShowS)
-> Show EnableEnhancedMonitoring
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableEnhancedMonitoring] -> ShowS
$cshowList :: [EnableEnhancedMonitoring] -> ShowS
show :: EnableEnhancedMonitoring -> String
$cshow :: EnableEnhancedMonitoring -> String
showsPrec :: Int -> EnableEnhancedMonitoring -> ShowS
$cshowsPrec :: Int -> EnableEnhancedMonitoring -> ShowS
Prelude.Show, (forall x.
 EnableEnhancedMonitoring -> Rep EnableEnhancedMonitoring x)
-> (forall x.
    Rep EnableEnhancedMonitoring x -> EnableEnhancedMonitoring)
-> Generic EnableEnhancedMonitoring
forall x.
Rep EnableEnhancedMonitoring x -> EnableEnhancedMonitoring
forall x.
EnableEnhancedMonitoring -> Rep EnableEnhancedMonitoring x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep EnableEnhancedMonitoring x -> EnableEnhancedMonitoring
$cfrom :: forall x.
EnableEnhancedMonitoring -> Rep EnableEnhancedMonitoring x
Prelude.Generic)

-- |
-- Create a value of 'EnableEnhancedMonitoring' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'streamName', 'enableEnhancedMonitoring_streamName' - The name of the stream for which to enable enhanced monitoring.
--
-- 'shardLevelMetrics', 'enableEnhancedMonitoring_shardLevelMetrics' - List of shard-level metrics to enable.
--
-- The following are the valid shard-level metrics. The value \"@ALL@\"
-- enables every metric.
--
-- -   @IncomingBytes@
--
-- -   @IncomingRecords@
--
-- -   @OutgoingBytes@
--
-- -   @OutgoingRecords@
--
-- -   @WriteProvisionedThroughputExceeded@
--
-- -   @ReadProvisionedThroughputExceeded@
--
-- -   @IteratorAgeMilliseconds@
--
-- -   @ALL@
--
-- For more information, see
-- <https://docs.aws.amazon.com/kinesis/latest/dev/monitoring-with-cloudwatch.html Monitoring the Amazon Kinesis Data Streams Service with Amazon CloudWatch>
-- in the /Amazon Kinesis Data Streams Developer Guide/.
newEnableEnhancedMonitoring ::
  -- | 'streamName'
  Prelude.Text ->
  EnableEnhancedMonitoring
newEnableEnhancedMonitoring :: Text -> EnableEnhancedMonitoring
newEnableEnhancedMonitoring Text
pStreamName_ =
  EnableEnhancedMonitoring' :: Text -> [MetricsName] -> EnableEnhancedMonitoring
EnableEnhancedMonitoring'
    { $sel:streamName:EnableEnhancedMonitoring' :: Text
streamName =
        Text
pStreamName_,
      $sel:shardLevelMetrics:EnableEnhancedMonitoring' :: [MetricsName]
shardLevelMetrics = [MetricsName]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the stream for which to enable enhanced monitoring.
enableEnhancedMonitoring_streamName :: Lens.Lens' EnableEnhancedMonitoring Prelude.Text
enableEnhancedMonitoring_streamName :: (Text -> f Text)
-> EnableEnhancedMonitoring -> f EnableEnhancedMonitoring
enableEnhancedMonitoring_streamName = (EnableEnhancedMonitoring -> Text)
-> (EnableEnhancedMonitoring -> Text -> EnableEnhancedMonitoring)
-> Lens EnableEnhancedMonitoring EnableEnhancedMonitoring Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableEnhancedMonitoring' {Text
streamName :: Text
$sel:streamName:EnableEnhancedMonitoring' :: EnableEnhancedMonitoring -> Text
streamName} -> Text
streamName) (\s :: EnableEnhancedMonitoring
s@EnableEnhancedMonitoring' {} Text
a -> EnableEnhancedMonitoring
s {$sel:streamName:EnableEnhancedMonitoring' :: Text
streamName = Text
a} :: EnableEnhancedMonitoring)

-- | List of shard-level metrics to enable.
--
-- The following are the valid shard-level metrics. The value \"@ALL@\"
-- enables every metric.
--
-- -   @IncomingBytes@
--
-- -   @IncomingRecords@
--
-- -   @OutgoingBytes@
--
-- -   @OutgoingRecords@
--
-- -   @WriteProvisionedThroughputExceeded@
--
-- -   @ReadProvisionedThroughputExceeded@
--
-- -   @IteratorAgeMilliseconds@
--
-- -   @ALL@
--
-- For more information, see
-- <https://docs.aws.amazon.com/kinesis/latest/dev/monitoring-with-cloudwatch.html Monitoring the Amazon Kinesis Data Streams Service with Amazon CloudWatch>
-- in the /Amazon Kinesis Data Streams Developer Guide/.
enableEnhancedMonitoring_shardLevelMetrics :: Lens.Lens' EnableEnhancedMonitoring [MetricsName]
enableEnhancedMonitoring_shardLevelMetrics :: ([MetricsName] -> f [MetricsName])
-> EnableEnhancedMonitoring -> f EnableEnhancedMonitoring
enableEnhancedMonitoring_shardLevelMetrics = (EnableEnhancedMonitoring -> [MetricsName])
-> (EnableEnhancedMonitoring
    -> [MetricsName] -> EnableEnhancedMonitoring)
-> Lens
     EnableEnhancedMonitoring
     EnableEnhancedMonitoring
     [MetricsName]
     [MetricsName]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableEnhancedMonitoring' {[MetricsName]
shardLevelMetrics :: [MetricsName]
$sel:shardLevelMetrics:EnableEnhancedMonitoring' :: EnableEnhancedMonitoring -> [MetricsName]
shardLevelMetrics} -> [MetricsName]
shardLevelMetrics) (\s :: EnableEnhancedMonitoring
s@EnableEnhancedMonitoring' {} [MetricsName]
a -> EnableEnhancedMonitoring
s {$sel:shardLevelMetrics:EnableEnhancedMonitoring' :: [MetricsName]
shardLevelMetrics = [MetricsName]
a} :: EnableEnhancedMonitoring) (([MetricsName] -> f [MetricsName])
 -> EnableEnhancedMonitoring -> f EnableEnhancedMonitoring)
-> (([MetricsName] -> f [MetricsName])
    -> [MetricsName] -> f [MetricsName])
-> ([MetricsName] -> f [MetricsName])
-> EnableEnhancedMonitoring
-> f EnableEnhancedMonitoring
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([MetricsName] -> f [MetricsName])
-> [MetricsName] -> f [MetricsName]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest EnableEnhancedMonitoring where
  type
    AWSResponse EnableEnhancedMonitoring =
      EnhancedMonitoringOutput
  request :: EnableEnhancedMonitoring -> Request EnableEnhancedMonitoring
request = Service
-> EnableEnhancedMonitoring -> Request EnableEnhancedMonitoring
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy EnableEnhancedMonitoring
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse EnableEnhancedMonitoring)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse EnableEnhancedMonitoring))
-> Logger
-> Service
-> Proxy EnableEnhancedMonitoring
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse EnableEnhancedMonitoring)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> Object -> Either String EnhancedMonitoringOutput
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable EnableEnhancedMonitoring

instance Prelude.NFData EnableEnhancedMonitoring

instance Core.ToHeaders EnableEnhancedMonitoring where
  toHeaders :: EnableEnhancedMonitoring -> ResponseHeaders
toHeaders =
    ResponseHeaders -> EnableEnhancedMonitoring -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"Kinesis_20131202.EnableEnhancedMonitoring" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON EnableEnhancedMonitoring where
  toJSON :: EnableEnhancedMonitoring -> Value
toJSON EnableEnhancedMonitoring' {[MetricsName]
Text
shardLevelMetrics :: [MetricsName]
streamName :: Text
$sel:shardLevelMetrics:EnableEnhancedMonitoring' :: EnableEnhancedMonitoring -> [MetricsName]
$sel:streamName:EnableEnhancedMonitoring' :: EnableEnhancedMonitoring -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"StreamName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
streamName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ShardLevelMetrics" Text -> [MetricsName] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [MetricsName]
shardLevelMetrics)
          ]
      )

instance Core.ToPath EnableEnhancedMonitoring where
  toPath :: EnableEnhancedMonitoring -> ByteString
toPath = ByteString -> EnableEnhancedMonitoring -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery EnableEnhancedMonitoring where
  toQuery :: EnableEnhancedMonitoring -> QueryString
toQuery = QueryString -> EnableEnhancedMonitoring -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty