{-# 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.Pi.Types.MetricQuery
-- 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.Pi.Types.MetricQuery where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Pi.Types.DimensionGroup
import qualified Amazonka.Prelude as Prelude

-- | A single query to be processed. You must provide the metric to query. If
-- no other parameters are specified, Performance Insights returns all data
-- points for the specified metric. Optionally, you can request that the
-- data points be aggregated by dimension group (@GroupBy@), and return
-- only those data points that match your criteria (@Filter@).
--
-- /See:/ 'newMetricQuery' smart constructor.
data MetricQuery = MetricQuery'
  { -- | One or more filters to apply in the request. Restrictions:
    --
    -- -   Any number of filters by the same dimension, as specified in the
    --     @GroupBy@ parameter.
    --
    -- -   A single filter for any other dimension in this dimension group.
    MetricQuery -> Maybe (HashMap Text Text)
filter' :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | A specification for how to aggregate the data points from a query
    -- result. You must specify a valid dimension group. Performance Insights
    -- will return all of the dimensions within that group, unless you provide
    -- the names of specific dimensions within that group. You can also request
    -- that Performance Insights return a limited number of values for a
    -- dimension.
    MetricQuery -> Maybe DimensionGroup
groupBy :: Prelude.Maybe DimensionGroup,
    -- | The name of a Performance Insights metric to be measured.
    --
    -- Valid values for @Metric@ are:
    --
    -- -   @db.load.avg@ - A scaled representation of the number of active
    --     sessions for the database engine.
    --
    -- -   @db.sampledload.avg@ - The raw number of active sessions for the
    --     database engine.
    --
    -- -   The counter metrics listed in
    --     <https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights_Counters.html#USER_PerfInsights_Counters.OS Performance Insights operating system counters>
    --     in the /Amazon Aurora User Guide/.
    --
    -- If the number of active sessions is less than an internal Performance
    -- Insights threshold, @db.load.avg@ and @db.sampledload.avg@ are the same
    -- value. If the number of active sessions is greater than the internal
    -- threshold, Performance Insights samples the active sessions, with
    -- @db.load.avg@ showing the scaled values, @db.sampledload.avg@ showing
    -- the raw values, and @db.sampledload.avg@ less than @db.load.avg@. For
    -- most use cases, you can query @db.load.avg@ only.
    MetricQuery -> Text
metric :: Prelude.Text
  }
  deriving (MetricQuery -> MetricQuery -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricQuery -> MetricQuery -> Bool
$c/= :: MetricQuery -> MetricQuery -> Bool
== :: MetricQuery -> MetricQuery -> Bool
$c== :: MetricQuery -> MetricQuery -> Bool
Prelude.Eq, ReadPrec [MetricQuery]
ReadPrec MetricQuery
Int -> ReadS MetricQuery
ReadS [MetricQuery]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricQuery]
$creadListPrec :: ReadPrec [MetricQuery]
readPrec :: ReadPrec MetricQuery
$creadPrec :: ReadPrec MetricQuery
readList :: ReadS [MetricQuery]
$creadList :: ReadS [MetricQuery]
readsPrec :: Int -> ReadS MetricQuery
$creadsPrec :: Int -> ReadS MetricQuery
Prelude.Read, Int -> MetricQuery -> ShowS
[MetricQuery] -> ShowS
MetricQuery -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricQuery] -> ShowS
$cshowList :: [MetricQuery] -> ShowS
show :: MetricQuery -> String
$cshow :: MetricQuery -> String
showsPrec :: Int -> MetricQuery -> ShowS
$cshowsPrec :: Int -> MetricQuery -> ShowS
Prelude.Show, forall x. Rep MetricQuery x -> MetricQuery
forall x. MetricQuery -> Rep MetricQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricQuery x -> MetricQuery
$cfrom :: forall x. MetricQuery -> Rep MetricQuery x
Prelude.Generic)

-- |
-- Create a value of 'MetricQuery' 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:
--
-- 'filter'', 'metricQuery_filter' - One or more filters to apply in the request. Restrictions:
--
-- -   Any number of filters by the same dimension, as specified in the
--     @GroupBy@ parameter.
--
-- -   A single filter for any other dimension in this dimension group.
--
-- 'groupBy', 'metricQuery_groupBy' - A specification for how to aggregate the data points from a query
-- result. You must specify a valid dimension group. Performance Insights
-- will return all of the dimensions within that group, unless you provide
-- the names of specific dimensions within that group. You can also request
-- that Performance Insights return a limited number of values for a
-- dimension.
--
-- 'metric', 'metricQuery_metric' - The name of a Performance Insights metric to be measured.
--
-- Valid values for @Metric@ are:
--
-- -   @db.load.avg@ - A scaled representation of the number of active
--     sessions for the database engine.
--
-- -   @db.sampledload.avg@ - The raw number of active sessions for the
--     database engine.
--
-- -   The counter metrics listed in
--     <https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights_Counters.html#USER_PerfInsights_Counters.OS Performance Insights operating system counters>
--     in the /Amazon Aurora User Guide/.
--
-- If the number of active sessions is less than an internal Performance
-- Insights threshold, @db.load.avg@ and @db.sampledload.avg@ are the same
-- value. If the number of active sessions is greater than the internal
-- threshold, Performance Insights samples the active sessions, with
-- @db.load.avg@ showing the scaled values, @db.sampledload.avg@ showing
-- the raw values, and @db.sampledload.avg@ less than @db.load.avg@. For
-- most use cases, you can query @db.load.avg@ only.
newMetricQuery ::
  -- | 'metric'
  Prelude.Text ->
  MetricQuery
newMetricQuery :: Text -> MetricQuery
newMetricQuery Text
pMetric_ =
  MetricQuery'
    { $sel:filter':MetricQuery' :: Maybe (HashMap Text Text)
filter' = forall a. Maybe a
Prelude.Nothing,
      $sel:groupBy:MetricQuery' :: Maybe DimensionGroup
groupBy = forall a. Maybe a
Prelude.Nothing,
      $sel:metric:MetricQuery' :: Text
metric = Text
pMetric_
    }

-- | One or more filters to apply in the request. Restrictions:
--
-- -   Any number of filters by the same dimension, as specified in the
--     @GroupBy@ parameter.
--
-- -   A single filter for any other dimension in this dimension group.
metricQuery_filter :: Lens.Lens' MetricQuery (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
metricQuery_filter :: Lens' MetricQuery (Maybe (HashMap Text Text))
metricQuery_filter = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricQuery' {Maybe (HashMap Text Text)
filter' :: Maybe (HashMap Text Text)
$sel:filter':MetricQuery' :: MetricQuery -> Maybe (HashMap Text Text)
filter'} -> Maybe (HashMap Text Text)
filter') (\s :: MetricQuery
s@MetricQuery' {} Maybe (HashMap Text Text)
a -> MetricQuery
s {$sel:filter':MetricQuery' :: Maybe (HashMap Text Text)
filter' = Maybe (HashMap Text Text)
a} :: MetricQuery) 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

-- | A specification for how to aggregate the data points from a query
-- result. You must specify a valid dimension group. Performance Insights
-- will return all of the dimensions within that group, unless you provide
-- the names of specific dimensions within that group. You can also request
-- that Performance Insights return a limited number of values for a
-- dimension.
metricQuery_groupBy :: Lens.Lens' MetricQuery (Prelude.Maybe DimensionGroup)
metricQuery_groupBy :: Lens' MetricQuery (Maybe DimensionGroup)
metricQuery_groupBy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricQuery' {Maybe DimensionGroup
groupBy :: Maybe DimensionGroup
$sel:groupBy:MetricQuery' :: MetricQuery -> Maybe DimensionGroup
groupBy} -> Maybe DimensionGroup
groupBy) (\s :: MetricQuery
s@MetricQuery' {} Maybe DimensionGroup
a -> MetricQuery
s {$sel:groupBy:MetricQuery' :: Maybe DimensionGroup
groupBy = Maybe DimensionGroup
a} :: MetricQuery)

-- | The name of a Performance Insights metric to be measured.
--
-- Valid values for @Metric@ are:
--
-- -   @db.load.avg@ - A scaled representation of the number of active
--     sessions for the database engine.
--
-- -   @db.sampledload.avg@ - The raw number of active sessions for the
--     database engine.
--
-- -   The counter metrics listed in
--     <https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights_Counters.html#USER_PerfInsights_Counters.OS Performance Insights operating system counters>
--     in the /Amazon Aurora User Guide/.
--
-- If the number of active sessions is less than an internal Performance
-- Insights threshold, @db.load.avg@ and @db.sampledload.avg@ are the same
-- value. If the number of active sessions is greater than the internal
-- threshold, Performance Insights samples the active sessions, with
-- @db.load.avg@ showing the scaled values, @db.sampledload.avg@ showing
-- the raw values, and @db.sampledload.avg@ less than @db.load.avg@. For
-- most use cases, you can query @db.load.avg@ only.
metricQuery_metric :: Lens.Lens' MetricQuery Prelude.Text
metricQuery_metric :: Lens' MetricQuery Text
metricQuery_metric = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricQuery' {Text
metric :: Text
$sel:metric:MetricQuery' :: MetricQuery -> Text
metric} -> Text
metric) (\s :: MetricQuery
s@MetricQuery' {} Text
a -> MetricQuery
s {$sel:metric:MetricQuery' :: Text
metric = Text
a} :: MetricQuery)

instance Prelude.Hashable MetricQuery where
  hashWithSalt :: Int -> MetricQuery -> Int
hashWithSalt Int
_salt MetricQuery' {Maybe (HashMap Text Text)
Maybe DimensionGroup
Text
metric :: Text
groupBy :: Maybe DimensionGroup
filter' :: Maybe (HashMap Text Text)
$sel:metric:MetricQuery' :: MetricQuery -> Text
$sel:groupBy:MetricQuery' :: MetricQuery -> Maybe DimensionGroup
$sel:filter':MetricQuery' :: MetricQuery -> Maybe (HashMap Text Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
filter'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DimensionGroup
groupBy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
metric

instance Prelude.NFData MetricQuery where
  rnf :: MetricQuery -> ()
rnf MetricQuery' {Maybe (HashMap Text Text)
Maybe DimensionGroup
Text
metric :: Text
groupBy :: Maybe DimensionGroup
filter' :: Maybe (HashMap Text Text)
$sel:metric:MetricQuery' :: MetricQuery -> Text
$sel:groupBy:MetricQuery' :: MetricQuery -> Maybe DimensionGroup
$sel:filter':MetricQuery' :: MetricQuery -> Maybe (HashMap Text Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
filter'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe DimensionGroup
groupBy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
metric

instance Data.ToJSON MetricQuery where
  toJSON :: MetricQuery -> Value
toJSON MetricQuery' {Maybe (HashMap Text Text)
Maybe DimensionGroup
Text
metric :: Text
groupBy :: Maybe DimensionGroup
filter' :: Maybe (HashMap Text Text)
$sel:metric:MetricQuery' :: MetricQuery -> Text
$sel:groupBy:MetricQuery' :: MetricQuery -> Maybe DimensionGroup
$sel:filter':MetricQuery' :: MetricQuery -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Filter" 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)
filter',
            (Key
"GroupBy" 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 DimensionGroup
groupBy,
            forall a. a -> Maybe a
Prelude.Just (Key
"Metric" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
metric)
          ]
      )