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

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

-- |
-- Module      : Amazonka.CloudWatchLogs.Types.MetricTransformation
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudWatchLogs.Types.MetricTransformation where

import Amazonka.CloudWatchLogs.Types.StandardUnit
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Indicates how to transform ingested log events to metric data in a
-- CloudWatch metric.
--
-- /See:/ 'newMetricTransformation' smart constructor.
data MetricTransformation = MetricTransformation'
  { -- | (Optional) The value to emit when a filter pattern does not match a log
    -- event. This value can be null.
    MetricTransformation -> Maybe Double
defaultValue :: Prelude.Maybe Prelude.Double,
    -- | The fields to use as dimensions for the metric. One metric filter can
    -- include as many as three dimensions.
    --
    -- Metrics extracted from log events are charged as custom metrics. To
    -- prevent unexpected high charges, do not specify high-cardinality fields
    -- such as @IPAddress@ or @requestID@ as dimensions. Each different value
    -- found for a dimension is treated as a separate metric and accrues
    -- charges as a separate custom metric.
    --
    -- CloudWatch Logs disables a metric filter if it generates 1000 different
    -- name\/value pairs for your specified dimensions within a certain amount
    -- of time. This helps to prevent accidental high charges.
    --
    -- You can also set up a billing alarm to alert you if your charges are
    -- higher than expected. For more information, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services Charges>.
    MetricTransformation -> Maybe (HashMap Text Text)
dimensions :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The unit to assign to the metric. If you omit this, the unit is set as
    -- @None@.
    MetricTransformation -> Maybe StandardUnit
unit :: Prelude.Maybe StandardUnit,
    -- | The name of the CloudWatch metric.
    MetricTransformation -> Text
metricName :: Prelude.Text,
    -- | A custom namespace to contain your metric in CloudWatch. Use namespaces
    -- to group together metrics that are similar. For more information, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace Namespaces>.
    MetricTransformation -> Text
metricNamespace :: Prelude.Text,
    -- | The value to publish to the CloudWatch metric when a filter pattern
    -- matches a log event.
    MetricTransformation -> Text
metricValue :: Prelude.Text
  }
  deriving (MetricTransformation -> MetricTransformation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricTransformation -> MetricTransformation -> Bool
$c/= :: MetricTransformation -> MetricTransformation -> Bool
== :: MetricTransformation -> MetricTransformation -> Bool
$c== :: MetricTransformation -> MetricTransformation -> Bool
Prelude.Eq, ReadPrec [MetricTransformation]
ReadPrec MetricTransformation
Int -> ReadS MetricTransformation
ReadS [MetricTransformation]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricTransformation]
$creadListPrec :: ReadPrec [MetricTransformation]
readPrec :: ReadPrec MetricTransformation
$creadPrec :: ReadPrec MetricTransformation
readList :: ReadS [MetricTransformation]
$creadList :: ReadS [MetricTransformation]
readsPrec :: Int -> ReadS MetricTransformation
$creadsPrec :: Int -> ReadS MetricTransformation
Prelude.Read, Int -> MetricTransformation -> ShowS
[MetricTransformation] -> ShowS
MetricTransformation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricTransformation] -> ShowS
$cshowList :: [MetricTransformation] -> ShowS
show :: MetricTransformation -> String
$cshow :: MetricTransformation -> String
showsPrec :: Int -> MetricTransformation -> ShowS
$cshowsPrec :: Int -> MetricTransformation -> ShowS
Prelude.Show, forall x. Rep MetricTransformation x -> MetricTransformation
forall x. MetricTransformation -> Rep MetricTransformation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricTransformation x -> MetricTransformation
$cfrom :: forall x. MetricTransformation -> Rep MetricTransformation x
Prelude.Generic)

-- |
-- Create a value of 'MetricTransformation' 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:
--
-- 'defaultValue', 'metricTransformation_defaultValue' - (Optional) The value to emit when a filter pattern does not match a log
-- event. This value can be null.
--
-- 'dimensions', 'metricTransformation_dimensions' - The fields to use as dimensions for the metric. One metric filter can
-- include as many as three dimensions.
--
-- Metrics extracted from log events are charged as custom metrics. To
-- prevent unexpected high charges, do not specify high-cardinality fields
-- such as @IPAddress@ or @requestID@ as dimensions. Each different value
-- found for a dimension is treated as a separate metric and accrues
-- charges as a separate custom metric.
--
-- CloudWatch Logs disables a metric filter if it generates 1000 different
-- name\/value pairs for your specified dimensions within a certain amount
-- of time. This helps to prevent accidental high charges.
--
-- You can also set up a billing alarm to alert you if your charges are
-- higher than expected. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services Charges>.
--
-- 'unit', 'metricTransformation_unit' - The unit to assign to the metric. If you omit this, the unit is set as
-- @None@.
--
-- 'metricName', 'metricTransformation_metricName' - The name of the CloudWatch metric.
--
-- 'metricNamespace', 'metricTransformation_metricNamespace' - A custom namespace to contain your metric in CloudWatch. Use namespaces
-- to group together metrics that are similar. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace Namespaces>.
--
-- 'metricValue', 'metricTransformation_metricValue' - The value to publish to the CloudWatch metric when a filter pattern
-- matches a log event.
newMetricTransformation ::
  -- | 'metricName'
  Prelude.Text ->
  -- | 'metricNamespace'
  Prelude.Text ->
  -- | 'metricValue'
  Prelude.Text ->
  MetricTransformation
newMetricTransformation :: Text -> Text -> Text -> MetricTransformation
newMetricTransformation
  Text
pMetricName_
  Text
pMetricNamespace_
  Text
pMetricValue_ =
    MetricTransformation'
      { $sel:defaultValue:MetricTransformation' :: Maybe Double
defaultValue =
          forall a. Maybe a
Prelude.Nothing,
        $sel:dimensions:MetricTransformation' :: Maybe (HashMap Text Text)
dimensions = forall a. Maybe a
Prelude.Nothing,
        $sel:unit:MetricTransformation' :: Maybe StandardUnit
unit = forall a. Maybe a
Prelude.Nothing,
        $sel:metricName:MetricTransformation' :: Text
metricName = Text
pMetricName_,
        $sel:metricNamespace:MetricTransformation' :: Text
metricNamespace = Text
pMetricNamespace_,
        $sel:metricValue:MetricTransformation' :: Text
metricValue = Text
pMetricValue_
      }

-- | (Optional) The value to emit when a filter pattern does not match a log
-- event. This value can be null.
metricTransformation_defaultValue :: Lens.Lens' MetricTransformation (Prelude.Maybe Prelude.Double)
metricTransformation_defaultValue :: Lens' MetricTransformation (Maybe Double)
metricTransformation_defaultValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricTransformation' {Maybe Double
defaultValue :: Maybe Double
$sel:defaultValue:MetricTransformation' :: MetricTransformation -> Maybe Double
defaultValue} -> Maybe Double
defaultValue) (\s :: MetricTransformation
s@MetricTransformation' {} Maybe Double
a -> MetricTransformation
s {$sel:defaultValue:MetricTransformation' :: Maybe Double
defaultValue = Maybe Double
a} :: MetricTransformation)

-- | The fields to use as dimensions for the metric. One metric filter can
-- include as many as three dimensions.
--
-- Metrics extracted from log events are charged as custom metrics. To
-- prevent unexpected high charges, do not specify high-cardinality fields
-- such as @IPAddress@ or @requestID@ as dimensions. Each different value
-- found for a dimension is treated as a separate metric and accrues
-- charges as a separate custom metric.
--
-- CloudWatch Logs disables a metric filter if it generates 1000 different
-- name\/value pairs for your specified dimensions within a certain amount
-- of time. This helps to prevent accidental high charges.
--
-- You can also set up a billing alarm to alert you if your charges are
-- higher than expected. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services Charges>.
metricTransformation_dimensions :: Lens.Lens' MetricTransformation (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
metricTransformation_dimensions :: Lens' MetricTransformation (Maybe (HashMap Text Text))
metricTransformation_dimensions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricTransformation' {Maybe (HashMap Text Text)
dimensions :: Maybe (HashMap Text Text)
$sel:dimensions:MetricTransformation' :: MetricTransformation -> Maybe (HashMap Text Text)
dimensions} -> Maybe (HashMap Text Text)
dimensions) (\s :: MetricTransformation
s@MetricTransformation' {} Maybe (HashMap Text Text)
a -> MetricTransformation
s {$sel:dimensions:MetricTransformation' :: Maybe (HashMap Text Text)
dimensions = Maybe (HashMap Text Text)
a} :: MetricTransformation) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The unit to assign to the metric. If you omit this, the unit is set as
-- @None@.
metricTransformation_unit :: Lens.Lens' MetricTransformation (Prelude.Maybe StandardUnit)
metricTransformation_unit :: Lens' MetricTransformation (Maybe StandardUnit)
metricTransformation_unit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricTransformation' {Maybe StandardUnit
unit :: Maybe StandardUnit
$sel:unit:MetricTransformation' :: MetricTransformation -> Maybe StandardUnit
unit} -> Maybe StandardUnit
unit) (\s :: MetricTransformation
s@MetricTransformation' {} Maybe StandardUnit
a -> MetricTransformation
s {$sel:unit:MetricTransformation' :: Maybe StandardUnit
unit = Maybe StandardUnit
a} :: MetricTransformation)

-- | The name of the CloudWatch metric.
metricTransformation_metricName :: Lens.Lens' MetricTransformation Prelude.Text
metricTransformation_metricName :: Lens' MetricTransformation Text
metricTransformation_metricName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricTransformation' {Text
metricName :: Text
$sel:metricName:MetricTransformation' :: MetricTransformation -> Text
metricName} -> Text
metricName) (\s :: MetricTransformation
s@MetricTransformation' {} Text
a -> MetricTransformation
s {$sel:metricName:MetricTransformation' :: Text
metricName = Text
a} :: MetricTransformation)

-- | A custom namespace to contain your metric in CloudWatch. Use namespaces
-- to group together metrics that are similar. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace Namespaces>.
metricTransformation_metricNamespace :: Lens.Lens' MetricTransformation Prelude.Text
metricTransformation_metricNamespace :: Lens' MetricTransformation Text
metricTransformation_metricNamespace = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricTransformation' {Text
metricNamespace :: Text
$sel:metricNamespace:MetricTransformation' :: MetricTransformation -> Text
metricNamespace} -> Text
metricNamespace) (\s :: MetricTransformation
s@MetricTransformation' {} Text
a -> MetricTransformation
s {$sel:metricNamespace:MetricTransformation' :: Text
metricNamespace = Text
a} :: MetricTransformation)

-- | The value to publish to the CloudWatch metric when a filter pattern
-- matches a log event.
metricTransformation_metricValue :: Lens.Lens' MetricTransformation Prelude.Text
metricTransformation_metricValue :: Lens' MetricTransformation Text
metricTransformation_metricValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricTransformation' {Text
metricValue :: Text
$sel:metricValue:MetricTransformation' :: MetricTransformation -> Text
metricValue} -> Text
metricValue) (\s :: MetricTransformation
s@MetricTransformation' {} Text
a -> MetricTransformation
s {$sel:metricValue:MetricTransformation' :: Text
metricValue = Text
a} :: MetricTransformation)

instance Data.FromJSON MetricTransformation where
  parseJSON :: Value -> Parser MetricTransformation
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MetricTransformation"
      ( \Object
x ->
          Maybe Double
-> Maybe (HashMap Text Text)
-> Maybe StandardUnit
-> Text
-> Text
-> Text
-> MetricTransformation
MetricTransformation'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"defaultValue")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"dimensions" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"unit")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"metricName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"metricNamespace")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"metricValue")
      )

instance Prelude.Hashable MetricTransformation where
  hashWithSalt :: Int -> MetricTransformation -> Int
hashWithSalt Int
_salt MetricTransformation' {Maybe Double
Maybe (HashMap Text Text)
Maybe StandardUnit
Text
metricValue :: Text
metricNamespace :: Text
metricName :: Text
unit :: Maybe StandardUnit
dimensions :: Maybe (HashMap Text Text)
defaultValue :: Maybe Double
$sel:metricValue:MetricTransformation' :: MetricTransformation -> Text
$sel:metricNamespace:MetricTransformation' :: MetricTransformation -> Text
$sel:metricName:MetricTransformation' :: MetricTransformation -> Text
$sel:unit:MetricTransformation' :: MetricTransformation -> Maybe StandardUnit
$sel:dimensions:MetricTransformation' :: MetricTransformation -> Maybe (HashMap Text Text)
$sel:defaultValue:MetricTransformation' :: MetricTransformation -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
defaultValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
dimensions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe StandardUnit
unit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
metricName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
metricNamespace
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
metricValue

instance Prelude.NFData MetricTransformation where
  rnf :: MetricTransformation -> ()
rnf MetricTransformation' {Maybe Double
Maybe (HashMap Text Text)
Maybe StandardUnit
Text
metricValue :: Text
metricNamespace :: Text
metricName :: Text
unit :: Maybe StandardUnit
dimensions :: Maybe (HashMap Text Text)
defaultValue :: Maybe Double
$sel:metricValue:MetricTransformation' :: MetricTransformation -> Text
$sel:metricNamespace:MetricTransformation' :: MetricTransformation -> Text
$sel:metricName:MetricTransformation' :: MetricTransformation -> Text
$sel:unit:MetricTransformation' :: MetricTransformation -> Maybe StandardUnit
$sel:dimensions:MetricTransformation' :: MetricTransformation -> Maybe (HashMap Text Text)
$sel:defaultValue:MetricTransformation' :: MetricTransformation -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
defaultValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
dimensions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe StandardUnit
unit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
metricName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
metricNamespace
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
metricValue

instance Data.ToJSON MetricTransformation where
  toJSON :: MetricTransformation -> Value
toJSON MetricTransformation' {Maybe Double
Maybe (HashMap Text Text)
Maybe StandardUnit
Text
metricValue :: Text
metricNamespace :: Text
metricName :: Text
unit :: Maybe StandardUnit
dimensions :: Maybe (HashMap Text Text)
defaultValue :: Maybe Double
$sel:metricValue:MetricTransformation' :: MetricTransformation -> Text
$sel:metricNamespace:MetricTransformation' :: MetricTransformation -> Text
$sel:metricName:MetricTransformation' :: MetricTransformation -> Text
$sel:unit:MetricTransformation' :: MetricTransformation -> Maybe StandardUnit
$sel:dimensions:MetricTransformation' :: MetricTransformation -> Maybe (HashMap Text Text)
$sel:defaultValue:MetricTransformation' :: MetricTransformation -> Maybe Double
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"defaultValue" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
defaultValue,
            (Key
"dimensions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
dimensions,
            (Key
"unit" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe StandardUnit
unit,
            forall a. a -> Maybe a
Prelude.Just (Key
"metricName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
metricName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"metricNamespace" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
metricNamespace),
            forall a. a -> Maybe a
Prelude.Just (Key
"metricValue" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
metricValue)
          ]
      )