{-# 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.Rum.Types.MetricDefinition
-- 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.Rum.Types.MetricDefinition where

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

-- | A structure that displays the definition of one extended metric that RUM
-- sends to CloudWatch or CloudWatch Evidently. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-RUM-vended-metrics.html Additional metrics that you can send to CloudWatch and CloudWatch Evidently>.
--
-- /See:/ 'newMetricDefinition' smart constructor.
data MetricDefinition = MetricDefinition'
  { -- | This field is a map of field paths to dimension names. It defines the
    -- dimensions to associate with this metric in CloudWatch The value of this
    -- field is used only if the metric destination is @CloudWatch@. If the
    -- metric destination is @Evidently@, the value of @DimensionKeys@ is
    -- ignored.
    MetricDefinition -> Maybe (HashMap Text Text)
dimensionKeys :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The pattern that defines the metric. RUM checks events that happen in a
    -- user\'s session against the pattern, and events that match the pattern
    -- are sent to the metric destination.
    --
    -- If the metrics destination is @CloudWatch@ and the event also matches a
    -- value in @DimensionKeys@, then the metric is published with the
    -- specified dimensions.
    MetricDefinition -> Maybe Text
eventPattern :: Prelude.Maybe Prelude.Text,
    -- | Use this field only if you are sending this metric to CloudWatch. It
    -- defines the CloudWatch metric unit that this metric is measured in.
    MetricDefinition -> Maybe Text
unitLabel :: Prelude.Maybe Prelude.Text,
    -- | The field within the event object that the metric value is sourced from.
    MetricDefinition -> Maybe Text
valueKey :: Prelude.Maybe Prelude.Text,
    -- | The ID of this metric definition.
    MetricDefinition -> Text
metricDefinitionId :: Prelude.Text,
    -- | The name of the metric that is defined in this structure.
    MetricDefinition -> Text
name :: Prelude.Text
  }
  deriving (MetricDefinition -> MetricDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricDefinition -> MetricDefinition -> Bool
$c/= :: MetricDefinition -> MetricDefinition -> Bool
== :: MetricDefinition -> MetricDefinition -> Bool
$c== :: MetricDefinition -> MetricDefinition -> Bool
Prelude.Eq, ReadPrec [MetricDefinition]
ReadPrec MetricDefinition
Int -> ReadS MetricDefinition
ReadS [MetricDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricDefinition]
$creadListPrec :: ReadPrec [MetricDefinition]
readPrec :: ReadPrec MetricDefinition
$creadPrec :: ReadPrec MetricDefinition
readList :: ReadS [MetricDefinition]
$creadList :: ReadS [MetricDefinition]
readsPrec :: Int -> ReadS MetricDefinition
$creadsPrec :: Int -> ReadS MetricDefinition
Prelude.Read, Int -> MetricDefinition -> ShowS
[MetricDefinition] -> ShowS
MetricDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricDefinition] -> ShowS
$cshowList :: [MetricDefinition] -> ShowS
show :: MetricDefinition -> String
$cshow :: MetricDefinition -> String
showsPrec :: Int -> MetricDefinition -> ShowS
$cshowsPrec :: Int -> MetricDefinition -> ShowS
Prelude.Show, forall x. Rep MetricDefinition x -> MetricDefinition
forall x. MetricDefinition -> Rep MetricDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricDefinition x -> MetricDefinition
$cfrom :: forall x. MetricDefinition -> Rep MetricDefinition x
Prelude.Generic)

-- |
-- Create a value of 'MetricDefinition' 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:
--
-- 'dimensionKeys', 'metricDefinition_dimensionKeys' - This field is a map of field paths to dimension names. It defines the
-- dimensions to associate with this metric in CloudWatch The value of this
-- field is used only if the metric destination is @CloudWatch@. If the
-- metric destination is @Evidently@, the value of @DimensionKeys@ is
-- ignored.
--
-- 'eventPattern', 'metricDefinition_eventPattern' - The pattern that defines the metric. RUM checks events that happen in a
-- user\'s session against the pattern, and events that match the pattern
-- are sent to the metric destination.
--
-- If the metrics destination is @CloudWatch@ and the event also matches a
-- value in @DimensionKeys@, then the metric is published with the
-- specified dimensions.
--
-- 'unitLabel', 'metricDefinition_unitLabel' - Use this field only if you are sending this metric to CloudWatch. It
-- defines the CloudWatch metric unit that this metric is measured in.
--
-- 'valueKey', 'metricDefinition_valueKey' - The field within the event object that the metric value is sourced from.
--
-- 'metricDefinitionId', 'metricDefinition_metricDefinitionId' - The ID of this metric definition.
--
-- 'name', 'metricDefinition_name' - The name of the metric that is defined in this structure.
newMetricDefinition ::
  -- | 'metricDefinitionId'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  MetricDefinition
newMetricDefinition :: Text -> Text -> MetricDefinition
newMetricDefinition Text
pMetricDefinitionId_ Text
pName_ =
  MetricDefinition'
    { $sel:dimensionKeys:MetricDefinition' :: Maybe (HashMap Text Text)
dimensionKeys = forall a. Maybe a
Prelude.Nothing,
      $sel:eventPattern:MetricDefinition' :: Maybe Text
eventPattern = forall a. Maybe a
Prelude.Nothing,
      $sel:unitLabel:MetricDefinition' :: Maybe Text
unitLabel = forall a. Maybe a
Prelude.Nothing,
      $sel:valueKey:MetricDefinition' :: Maybe Text
valueKey = forall a. Maybe a
Prelude.Nothing,
      $sel:metricDefinitionId:MetricDefinition' :: Text
metricDefinitionId = Text
pMetricDefinitionId_,
      $sel:name:MetricDefinition' :: Text
name = Text
pName_
    }

-- | This field is a map of field paths to dimension names. It defines the
-- dimensions to associate with this metric in CloudWatch The value of this
-- field is used only if the metric destination is @CloudWatch@. If the
-- metric destination is @Evidently@, the value of @DimensionKeys@ is
-- ignored.
metricDefinition_dimensionKeys :: Lens.Lens' MetricDefinition (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
metricDefinition_dimensionKeys :: Lens' MetricDefinition (Maybe (HashMap Text Text))
metricDefinition_dimensionKeys = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDefinition' {Maybe (HashMap Text Text)
dimensionKeys :: Maybe (HashMap Text Text)
$sel:dimensionKeys:MetricDefinition' :: MetricDefinition -> Maybe (HashMap Text Text)
dimensionKeys} -> Maybe (HashMap Text Text)
dimensionKeys) (\s :: MetricDefinition
s@MetricDefinition' {} Maybe (HashMap Text Text)
a -> MetricDefinition
s {$sel:dimensionKeys:MetricDefinition' :: Maybe (HashMap Text Text)
dimensionKeys = Maybe (HashMap Text Text)
a} :: MetricDefinition) 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 pattern that defines the metric. RUM checks events that happen in a
-- user\'s session against the pattern, and events that match the pattern
-- are sent to the metric destination.
--
-- If the metrics destination is @CloudWatch@ and the event also matches a
-- value in @DimensionKeys@, then the metric is published with the
-- specified dimensions.
metricDefinition_eventPattern :: Lens.Lens' MetricDefinition (Prelude.Maybe Prelude.Text)
metricDefinition_eventPattern :: Lens' MetricDefinition (Maybe Text)
metricDefinition_eventPattern = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDefinition' {Maybe Text
eventPattern :: Maybe Text
$sel:eventPattern:MetricDefinition' :: MetricDefinition -> Maybe Text
eventPattern} -> Maybe Text
eventPattern) (\s :: MetricDefinition
s@MetricDefinition' {} Maybe Text
a -> MetricDefinition
s {$sel:eventPattern:MetricDefinition' :: Maybe Text
eventPattern = Maybe Text
a} :: MetricDefinition)

-- | Use this field only if you are sending this metric to CloudWatch. It
-- defines the CloudWatch metric unit that this metric is measured in.
metricDefinition_unitLabel :: Lens.Lens' MetricDefinition (Prelude.Maybe Prelude.Text)
metricDefinition_unitLabel :: Lens' MetricDefinition (Maybe Text)
metricDefinition_unitLabel = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDefinition' {Maybe Text
unitLabel :: Maybe Text
$sel:unitLabel:MetricDefinition' :: MetricDefinition -> Maybe Text
unitLabel} -> Maybe Text
unitLabel) (\s :: MetricDefinition
s@MetricDefinition' {} Maybe Text
a -> MetricDefinition
s {$sel:unitLabel:MetricDefinition' :: Maybe Text
unitLabel = Maybe Text
a} :: MetricDefinition)

-- | The field within the event object that the metric value is sourced from.
metricDefinition_valueKey :: Lens.Lens' MetricDefinition (Prelude.Maybe Prelude.Text)
metricDefinition_valueKey :: Lens' MetricDefinition (Maybe Text)
metricDefinition_valueKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDefinition' {Maybe Text
valueKey :: Maybe Text
$sel:valueKey:MetricDefinition' :: MetricDefinition -> Maybe Text
valueKey} -> Maybe Text
valueKey) (\s :: MetricDefinition
s@MetricDefinition' {} Maybe Text
a -> MetricDefinition
s {$sel:valueKey:MetricDefinition' :: Maybe Text
valueKey = Maybe Text
a} :: MetricDefinition)

-- | The ID of this metric definition.
metricDefinition_metricDefinitionId :: Lens.Lens' MetricDefinition Prelude.Text
metricDefinition_metricDefinitionId :: Lens' MetricDefinition Text
metricDefinition_metricDefinitionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDefinition' {Text
metricDefinitionId :: Text
$sel:metricDefinitionId:MetricDefinition' :: MetricDefinition -> Text
metricDefinitionId} -> Text
metricDefinitionId) (\s :: MetricDefinition
s@MetricDefinition' {} Text
a -> MetricDefinition
s {$sel:metricDefinitionId:MetricDefinition' :: Text
metricDefinitionId = Text
a} :: MetricDefinition)

-- | The name of the metric that is defined in this structure.
metricDefinition_name :: Lens.Lens' MetricDefinition Prelude.Text
metricDefinition_name :: Lens' MetricDefinition Text
metricDefinition_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDefinition' {Text
name :: Text
$sel:name:MetricDefinition' :: MetricDefinition -> Text
name} -> Text
name) (\s :: MetricDefinition
s@MetricDefinition' {} Text
a -> MetricDefinition
s {$sel:name:MetricDefinition' :: Text
name = Text
a} :: MetricDefinition)

instance Data.FromJSON MetricDefinition where
  parseJSON :: Value -> Parser MetricDefinition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MetricDefinition"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Text
-> Text
-> MetricDefinition
MetricDefinition'
            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
"DimensionKeys" 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
"EventPattern")
            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
"UnitLabel")
            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
"ValueKey")
            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
"MetricDefinitionId")
            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
"Name")
      )

instance Prelude.Hashable MetricDefinition where
  hashWithSalt :: Int -> MetricDefinition -> Int
hashWithSalt Int
_salt MetricDefinition' {Maybe Text
Maybe (HashMap Text Text)
Text
name :: Text
metricDefinitionId :: Text
valueKey :: Maybe Text
unitLabel :: Maybe Text
eventPattern :: Maybe Text
dimensionKeys :: Maybe (HashMap Text Text)
$sel:name:MetricDefinition' :: MetricDefinition -> Text
$sel:metricDefinitionId:MetricDefinition' :: MetricDefinition -> Text
$sel:valueKey:MetricDefinition' :: MetricDefinition -> Maybe Text
$sel:unitLabel:MetricDefinition' :: MetricDefinition -> Maybe Text
$sel:eventPattern:MetricDefinition' :: MetricDefinition -> Maybe Text
$sel:dimensionKeys:MetricDefinition' :: MetricDefinition -> Maybe (HashMap Text Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
dimensionKeys
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
eventPattern
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
unitLabel
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
valueKey
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
metricDefinitionId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData MetricDefinition where
  rnf :: MetricDefinition -> ()
rnf MetricDefinition' {Maybe Text
Maybe (HashMap Text Text)
Text
name :: Text
metricDefinitionId :: Text
valueKey :: Maybe Text
unitLabel :: Maybe Text
eventPattern :: Maybe Text
dimensionKeys :: Maybe (HashMap Text Text)
$sel:name:MetricDefinition' :: MetricDefinition -> Text
$sel:metricDefinitionId:MetricDefinition' :: MetricDefinition -> Text
$sel:valueKey:MetricDefinition' :: MetricDefinition -> Maybe Text
$sel:unitLabel:MetricDefinition' :: MetricDefinition -> Maybe Text
$sel:eventPattern:MetricDefinition' :: MetricDefinition -> Maybe Text
$sel:dimensionKeys:MetricDefinition' :: MetricDefinition -> Maybe (HashMap Text Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
dimensionKeys
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
eventPattern
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
unitLabel
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
valueKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
metricDefinitionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name