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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 of
-- the data points for that metric. You can optionally 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'
  { -- | 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,
    -- | 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),
    -- | 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.
    --
    -- 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
(MetricQuery -> MetricQuery -> Bool)
-> (MetricQuery -> MetricQuery -> Bool) -> Eq MetricQuery
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]
(Int -> ReadS MetricQuery)
-> ReadS [MetricQuery]
-> ReadPrec MetricQuery
-> ReadPrec [MetricQuery]
-> Read 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
(Int -> MetricQuery -> ShowS)
-> (MetricQuery -> String)
-> ([MetricQuery] -> ShowS)
-> Show MetricQuery
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. MetricQuery -> Rep MetricQuery x)
-> (forall x. Rep MetricQuery x -> MetricQuery)
-> Generic MetricQuery
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:
--
-- '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.
--
-- '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.
--
-- '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.
--
-- 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' :: Maybe DimensionGroup
-> Maybe (HashMap Text Text) -> Text -> MetricQuery
MetricQuery'
    { $sel:groupBy:MetricQuery' :: Maybe DimensionGroup
groupBy = Maybe DimensionGroup
forall a. Maybe a
Prelude.Nothing,
      $sel:filter':MetricQuery' :: Maybe (HashMap Text Text)
filter' = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:metric:MetricQuery' :: Text
metric = Text
pMetric_
    }

-- | 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 :: (Maybe DimensionGroup -> f (Maybe DimensionGroup))
-> MetricQuery -> f MetricQuery
metricQuery_groupBy = (MetricQuery -> Maybe DimensionGroup)
-> (MetricQuery -> Maybe DimensionGroup -> MetricQuery)
-> Lens
     MetricQuery
     MetricQuery
     (Maybe DimensionGroup)
     (Maybe DimensionGroup)
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)

-- | 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 :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> MetricQuery -> f MetricQuery
metricQuery_filter = (MetricQuery -> Maybe (HashMap Text Text))
-> (MetricQuery -> Maybe (HashMap Text Text) -> MetricQuery)
-> Lens
     MetricQuery
     MetricQuery
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> MetricQuery -> f MetricQuery)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> MetricQuery
-> f MetricQuery
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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 AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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.
--
-- 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 :: (Text -> f Text) -> MetricQuery -> f MetricQuery
metricQuery_metric = (MetricQuery -> Text)
-> (MetricQuery -> Text -> MetricQuery)
-> Lens MetricQuery MetricQuery Text Text
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

instance Prelude.NFData MetricQuery

instance Core.ToJSON MetricQuery where
  toJSON :: MetricQuery -> Value
toJSON MetricQuery' {Maybe (HashMap Text Text)
Maybe DimensionGroup
Text
metric :: Text
filter' :: Maybe (HashMap Text Text)
groupBy :: Maybe DimensionGroup
$sel:metric:MetricQuery' :: MetricQuery -> Text
$sel:filter':MetricQuery' :: MetricQuery -> Maybe (HashMap Text Text)
$sel:groupBy:MetricQuery' :: MetricQuery -> Maybe DimensionGroup
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"GroupBy" Text -> DimensionGroup -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (DimensionGroup -> Pair) -> Maybe DimensionGroup -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DimensionGroup
groupBy,
            (Text
"Filter" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
filter',
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Metric" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
metric)
          ]
      )