{-# 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.AutoScaling.Types.PredictiveScalingMetricSpecification
-- 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.AutoScaling.Types.PredictiveScalingMetricSpecification where

import Amazonka.AutoScaling.Types.PredictiveScalingPredefinedLoadMetric
import Amazonka.AutoScaling.Types.PredictiveScalingPredefinedMetricPair
import Amazonka.AutoScaling.Types.PredictiveScalingPredefinedScalingMetric
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | This structure specifies the metrics and target utilization settings for
-- a predictive scaling policy.
--
-- You must specify either a metric pair, or a load metric and a scaling
-- metric individually. Specifying a metric pair instead of individual
-- metrics provides a simpler way to configure metrics for a scaling
-- policy. You choose the metric pair, and the policy automatically knows
-- the correct sum and average statistics to use for the load metric and
-- the scaling metric.
--
-- Example
--
-- -   You create a predictive scaling policy and specify @ALBRequestCount@
--     as the value for the metric pair and @1000.0@ as the target value.
--     For this type of metric, you must provide the metric dimension for
--     the corresponding target group, so you also provide a resource label
--     for the Application Load Balancer target group that is attached to
--     your Auto Scaling group.
--
-- -   The number of requests the target group receives per minute provides
--     the load metric, and the request count averaged between the members
--     of the target group provides the scaling metric. In CloudWatch, this
--     refers to the @RequestCount@ and @RequestCountPerTarget@ metrics,
--     respectively.
--
-- -   For optimal use of predictive scaling, you adhere to the best
--     practice of using a dynamic scaling policy to automatically scale
--     between the minimum capacity and maximum capacity in response to
--     real-time changes in resource utilization.
--
-- -   Amazon EC2 Auto Scaling consumes data points for the load metric
--     over the last 14 days and creates an hourly load forecast for
--     predictive scaling. (A minimum of 24 hours of data is required.)
--
-- -   After creating the load forecast, Amazon EC2 Auto Scaling determines
--     when to reduce or increase the capacity of your Auto Scaling group
--     in each hour of the forecast period so that the average number of
--     requests received by each instance is as close to 1000 requests per
--     minute as possible at all times.
--
-- /See:/ 'newPredictiveScalingMetricSpecification' smart constructor.
data PredictiveScalingMetricSpecification = PredictiveScalingMetricSpecification'
  { -- | The scaling metric specification.
    PredictiveScalingMetricSpecification
-> Maybe PredictiveScalingPredefinedScalingMetric
predefinedScalingMetricSpecification :: Prelude.Maybe PredictiveScalingPredefinedScalingMetric,
    -- | The metric pair specification from which Amazon EC2 Auto Scaling
    -- determines the appropriate scaling metric and load metric to use.
    PredictiveScalingMetricSpecification
-> Maybe PredictiveScalingPredefinedMetricPair
predefinedMetricPairSpecification :: Prelude.Maybe PredictiveScalingPredefinedMetricPair,
    -- | The load metric specification.
    PredictiveScalingMetricSpecification
-> Maybe PredictiveScalingPredefinedLoadMetric
predefinedLoadMetricSpecification :: Prelude.Maybe PredictiveScalingPredefinedLoadMetric,
    -- | Specifies the target utilization.
    PredictiveScalingMetricSpecification -> Double
targetValue :: Prelude.Double
  }
  deriving (PredictiveScalingMetricSpecification
-> PredictiveScalingMetricSpecification -> Bool
(PredictiveScalingMetricSpecification
 -> PredictiveScalingMetricSpecification -> Bool)
-> (PredictiveScalingMetricSpecification
    -> PredictiveScalingMetricSpecification -> Bool)
-> Eq PredictiveScalingMetricSpecification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PredictiveScalingMetricSpecification
-> PredictiveScalingMetricSpecification -> Bool
$c/= :: PredictiveScalingMetricSpecification
-> PredictiveScalingMetricSpecification -> Bool
== :: PredictiveScalingMetricSpecification
-> PredictiveScalingMetricSpecification -> Bool
$c== :: PredictiveScalingMetricSpecification
-> PredictiveScalingMetricSpecification -> Bool
Prelude.Eq, ReadPrec [PredictiveScalingMetricSpecification]
ReadPrec PredictiveScalingMetricSpecification
Int -> ReadS PredictiveScalingMetricSpecification
ReadS [PredictiveScalingMetricSpecification]
(Int -> ReadS PredictiveScalingMetricSpecification)
-> ReadS [PredictiveScalingMetricSpecification]
-> ReadPrec PredictiveScalingMetricSpecification
-> ReadPrec [PredictiveScalingMetricSpecification]
-> Read PredictiveScalingMetricSpecification
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PredictiveScalingMetricSpecification]
$creadListPrec :: ReadPrec [PredictiveScalingMetricSpecification]
readPrec :: ReadPrec PredictiveScalingMetricSpecification
$creadPrec :: ReadPrec PredictiveScalingMetricSpecification
readList :: ReadS [PredictiveScalingMetricSpecification]
$creadList :: ReadS [PredictiveScalingMetricSpecification]
readsPrec :: Int -> ReadS PredictiveScalingMetricSpecification
$creadsPrec :: Int -> ReadS PredictiveScalingMetricSpecification
Prelude.Read, Int -> PredictiveScalingMetricSpecification -> ShowS
[PredictiveScalingMetricSpecification] -> ShowS
PredictiveScalingMetricSpecification -> String
(Int -> PredictiveScalingMetricSpecification -> ShowS)
-> (PredictiveScalingMetricSpecification -> String)
-> ([PredictiveScalingMetricSpecification] -> ShowS)
-> Show PredictiveScalingMetricSpecification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PredictiveScalingMetricSpecification] -> ShowS
$cshowList :: [PredictiveScalingMetricSpecification] -> ShowS
show :: PredictiveScalingMetricSpecification -> String
$cshow :: PredictiveScalingMetricSpecification -> String
showsPrec :: Int -> PredictiveScalingMetricSpecification -> ShowS
$cshowsPrec :: Int -> PredictiveScalingMetricSpecification -> ShowS
Prelude.Show, (forall x.
 PredictiveScalingMetricSpecification
 -> Rep PredictiveScalingMetricSpecification x)
-> (forall x.
    Rep PredictiveScalingMetricSpecification x
    -> PredictiveScalingMetricSpecification)
-> Generic PredictiveScalingMetricSpecification
forall x.
Rep PredictiveScalingMetricSpecification x
-> PredictiveScalingMetricSpecification
forall x.
PredictiveScalingMetricSpecification
-> Rep PredictiveScalingMetricSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PredictiveScalingMetricSpecification x
-> PredictiveScalingMetricSpecification
$cfrom :: forall x.
PredictiveScalingMetricSpecification
-> Rep PredictiveScalingMetricSpecification x
Prelude.Generic)

-- |
-- Create a value of 'PredictiveScalingMetricSpecification' 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:
--
-- 'predefinedScalingMetricSpecification', 'predictiveScalingMetricSpecification_predefinedScalingMetricSpecification' - The scaling metric specification.
--
-- 'predefinedMetricPairSpecification', 'predictiveScalingMetricSpecification_predefinedMetricPairSpecification' - The metric pair specification from which Amazon EC2 Auto Scaling
-- determines the appropriate scaling metric and load metric to use.
--
-- 'predefinedLoadMetricSpecification', 'predictiveScalingMetricSpecification_predefinedLoadMetricSpecification' - The load metric specification.
--
-- 'targetValue', 'predictiveScalingMetricSpecification_targetValue' - Specifies the target utilization.
newPredictiveScalingMetricSpecification ::
  -- | 'targetValue'
  Prelude.Double ->
  PredictiveScalingMetricSpecification
newPredictiveScalingMetricSpecification :: Double -> PredictiveScalingMetricSpecification
newPredictiveScalingMetricSpecification Double
pTargetValue_ =
  PredictiveScalingMetricSpecification' :: Maybe PredictiveScalingPredefinedScalingMetric
-> Maybe PredictiveScalingPredefinedMetricPair
-> Maybe PredictiveScalingPredefinedLoadMetric
-> Double
-> PredictiveScalingMetricSpecification
PredictiveScalingMetricSpecification'
    { $sel:predefinedScalingMetricSpecification:PredictiveScalingMetricSpecification' :: Maybe PredictiveScalingPredefinedScalingMetric
predefinedScalingMetricSpecification =
        Maybe PredictiveScalingPredefinedScalingMetric
forall a. Maybe a
Prelude.Nothing,
      $sel:predefinedMetricPairSpecification:PredictiveScalingMetricSpecification' :: Maybe PredictiveScalingPredefinedMetricPair
predefinedMetricPairSpecification =
        Maybe PredictiveScalingPredefinedMetricPair
forall a. Maybe a
Prelude.Nothing,
      $sel:predefinedLoadMetricSpecification:PredictiveScalingMetricSpecification' :: Maybe PredictiveScalingPredefinedLoadMetric
predefinedLoadMetricSpecification =
        Maybe PredictiveScalingPredefinedLoadMetric
forall a. Maybe a
Prelude.Nothing,
      $sel:targetValue:PredictiveScalingMetricSpecification' :: Double
targetValue = Double
pTargetValue_
    }

-- | The scaling metric specification.
predictiveScalingMetricSpecification_predefinedScalingMetricSpecification :: Lens.Lens' PredictiveScalingMetricSpecification (Prelude.Maybe PredictiveScalingPredefinedScalingMetric)
predictiveScalingMetricSpecification_predefinedScalingMetricSpecification :: (Maybe PredictiveScalingPredefinedScalingMetric
 -> f (Maybe PredictiveScalingPredefinedScalingMetric))
-> PredictiveScalingMetricSpecification
-> f PredictiveScalingMetricSpecification
predictiveScalingMetricSpecification_predefinedScalingMetricSpecification = (PredictiveScalingMetricSpecification
 -> Maybe PredictiveScalingPredefinedScalingMetric)
-> (PredictiveScalingMetricSpecification
    -> Maybe PredictiveScalingPredefinedScalingMetric
    -> PredictiveScalingMetricSpecification)
-> Lens
     PredictiveScalingMetricSpecification
     PredictiveScalingMetricSpecification
     (Maybe PredictiveScalingPredefinedScalingMetric)
     (Maybe PredictiveScalingPredefinedScalingMetric)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredictiveScalingMetricSpecification' {Maybe PredictiveScalingPredefinedScalingMetric
predefinedScalingMetricSpecification :: Maybe PredictiveScalingPredefinedScalingMetric
$sel:predefinedScalingMetricSpecification:PredictiveScalingMetricSpecification' :: PredictiveScalingMetricSpecification
-> Maybe PredictiveScalingPredefinedScalingMetric
predefinedScalingMetricSpecification} -> Maybe PredictiveScalingPredefinedScalingMetric
predefinedScalingMetricSpecification) (\s :: PredictiveScalingMetricSpecification
s@PredictiveScalingMetricSpecification' {} Maybe PredictiveScalingPredefinedScalingMetric
a -> PredictiveScalingMetricSpecification
s {$sel:predefinedScalingMetricSpecification:PredictiveScalingMetricSpecification' :: Maybe PredictiveScalingPredefinedScalingMetric
predefinedScalingMetricSpecification = Maybe PredictiveScalingPredefinedScalingMetric
a} :: PredictiveScalingMetricSpecification)

-- | The metric pair specification from which Amazon EC2 Auto Scaling
-- determines the appropriate scaling metric and load metric to use.
predictiveScalingMetricSpecification_predefinedMetricPairSpecification :: Lens.Lens' PredictiveScalingMetricSpecification (Prelude.Maybe PredictiveScalingPredefinedMetricPair)
predictiveScalingMetricSpecification_predefinedMetricPairSpecification :: (Maybe PredictiveScalingPredefinedMetricPair
 -> f (Maybe PredictiveScalingPredefinedMetricPair))
-> PredictiveScalingMetricSpecification
-> f PredictiveScalingMetricSpecification
predictiveScalingMetricSpecification_predefinedMetricPairSpecification = (PredictiveScalingMetricSpecification
 -> Maybe PredictiveScalingPredefinedMetricPair)
-> (PredictiveScalingMetricSpecification
    -> Maybe PredictiveScalingPredefinedMetricPair
    -> PredictiveScalingMetricSpecification)
-> Lens
     PredictiveScalingMetricSpecification
     PredictiveScalingMetricSpecification
     (Maybe PredictiveScalingPredefinedMetricPair)
     (Maybe PredictiveScalingPredefinedMetricPair)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredictiveScalingMetricSpecification' {Maybe PredictiveScalingPredefinedMetricPair
predefinedMetricPairSpecification :: Maybe PredictiveScalingPredefinedMetricPair
$sel:predefinedMetricPairSpecification:PredictiveScalingMetricSpecification' :: PredictiveScalingMetricSpecification
-> Maybe PredictiveScalingPredefinedMetricPair
predefinedMetricPairSpecification} -> Maybe PredictiveScalingPredefinedMetricPair
predefinedMetricPairSpecification) (\s :: PredictiveScalingMetricSpecification
s@PredictiveScalingMetricSpecification' {} Maybe PredictiveScalingPredefinedMetricPair
a -> PredictiveScalingMetricSpecification
s {$sel:predefinedMetricPairSpecification:PredictiveScalingMetricSpecification' :: Maybe PredictiveScalingPredefinedMetricPair
predefinedMetricPairSpecification = Maybe PredictiveScalingPredefinedMetricPair
a} :: PredictiveScalingMetricSpecification)

-- | The load metric specification.
predictiveScalingMetricSpecification_predefinedLoadMetricSpecification :: Lens.Lens' PredictiveScalingMetricSpecification (Prelude.Maybe PredictiveScalingPredefinedLoadMetric)
predictiveScalingMetricSpecification_predefinedLoadMetricSpecification :: (Maybe PredictiveScalingPredefinedLoadMetric
 -> f (Maybe PredictiveScalingPredefinedLoadMetric))
-> PredictiveScalingMetricSpecification
-> f PredictiveScalingMetricSpecification
predictiveScalingMetricSpecification_predefinedLoadMetricSpecification = (PredictiveScalingMetricSpecification
 -> Maybe PredictiveScalingPredefinedLoadMetric)
-> (PredictiveScalingMetricSpecification
    -> Maybe PredictiveScalingPredefinedLoadMetric
    -> PredictiveScalingMetricSpecification)
-> Lens
     PredictiveScalingMetricSpecification
     PredictiveScalingMetricSpecification
     (Maybe PredictiveScalingPredefinedLoadMetric)
     (Maybe PredictiveScalingPredefinedLoadMetric)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredictiveScalingMetricSpecification' {Maybe PredictiveScalingPredefinedLoadMetric
predefinedLoadMetricSpecification :: Maybe PredictiveScalingPredefinedLoadMetric
$sel:predefinedLoadMetricSpecification:PredictiveScalingMetricSpecification' :: PredictiveScalingMetricSpecification
-> Maybe PredictiveScalingPredefinedLoadMetric
predefinedLoadMetricSpecification} -> Maybe PredictiveScalingPredefinedLoadMetric
predefinedLoadMetricSpecification) (\s :: PredictiveScalingMetricSpecification
s@PredictiveScalingMetricSpecification' {} Maybe PredictiveScalingPredefinedLoadMetric
a -> PredictiveScalingMetricSpecification
s {$sel:predefinedLoadMetricSpecification:PredictiveScalingMetricSpecification' :: Maybe PredictiveScalingPredefinedLoadMetric
predefinedLoadMetricSpecification = Maybe PredictiveScalingPredefinedLoadMetric
a} :: PredictiveScalingMetricSpecification)

-- | Specifies the target utilization.
predictiveScalingMetricSpecification_targetValue :: Lens.Lens' PredictiveScalingMetricSpecification Prelude.Double
predictiveScalingMetricSpecification_targetValue :: (Double -> f Double)
-> PredictiveScalingMetricSpecification
-> f PredictiveScalingMetricSpecification
predictiveScalingMetricSpecification_targetValue = (PredictiveScalingMetricSpecification -> Double)
-> (PredictiveScalingMetricSpecification
    -> Double -> PredictiveScalingMetricSpecification)
-> Lens
     PredictiveScalingMetricSpecification
     PredictiveScalingMetricSpecification
     Double
     Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredictiveScalingMetricSpecification' {Double
targetValue :: Double
$sel:targetValue:PredictiveScalingMetricSpecification' :: PredictiveScalingMetricSpecification -> Double
targetValue} -> Double
targetValue) (\s :: PredictiveScalingMetricSpecification
s@PredictiveScalingMetricSpecification' {} Double
a -> PredictiveScalingMetricSpecification
s {$sel:targetValue:PredictiveScalingMetricSpecification' :: Double
targetValue = Double
a} :: PredictiveScalingMetricSpecification)

instance
  Core.FromXML
    PredictiveScalingMetricSpecification
  where
  parseXML :: [Node] -> Either String PredictiveScalingMetricSpecification
parseXML [Node]
x =
    Maybe PredictiveScalingPredefinedScalingMetric
-> Maybe PredictiveScalingPredefinedMetricPair
-> Maybe PredictiveScalingPredefinedLoadMetric
-> Double
-> PredictiveScalingMetricSpecification
PredictiveScalingMetricSpecification'
      (Maybe PredictiveScalingPredefinedScalingMetric
 -> Maybe PredictiveScalingPredefinedMetricPair
 -> Maybe PredictiveScalingPredefinedLoadMetric
 -> Double
 -> PredictiveScalingMetricSpecification)
-> Either String (Maybe PredictiveScalingPredefinedScalingMetric)
-> Either
     String
     (Maybe PredictiveScalingPredefinedMetricPair
      -> Maybe PredictiveScalingPredefinedLoadMetric
      -> Double
      -> PredictiveScalingMetricSpecification)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node]
-> Text
-> Either String (Maybe PredictiveScalingPredefinedScalingMetric)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"PredefinedScalingMetricSpecification")
      Either
  String
  (Maybe PredictiveScalingPredefinedMetricPair
   -> Maybe PredictiveScalingPredefinedLoadMetric
   -> Double
   -> PredictiveScalingMetricSpecification)
-> Either String (Maybe PredictiveScalingPredefinedMetricPair)
-> Either
     String
     (Maybe PredictiveScalingPredefinedLoadMetric
      -> Double -> PredictiveScalingMetricSpecification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node]
-> Text
-> Either String (Maybe PredictiveScalingPredefinedMetricPair)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"PredefinedMetricPairSpecification")
      Either
  String
  (Maybe PredictiveScalingPredefinedLoadMetric
   -> Double -> PredictiveScalingMetricSpecification)
-> Either String (Maybe PredictiveScalingPredefinedLoadMetric)
-> Either String (Double -> PredictiveScalingMetricSpecification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node]
-> Text
-> Either String (Maybe PredictiveScalingPredefinedLoadMetric)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"PredefinedLoadMetricSpecification")
      Either String (Double -> PredictiveScalingMetricSpecification)
-> Either String Double
-> Either String PredictiveScalingMetricSpecification
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Double
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"TargetValue")

instance
  Prelude.Hashable
    PredictiveScalingMetricSpecification

instance
  Prelude.NFData
    PredictiveScalingMetricSpecification

instance
  Core.ToQuery
    PredictiveScalingMetricSpecification
  where
  toQuery :: PredictiveScalingMetricSpecification -> QueryString
toQuery PredictiveScalingMetricSpecification' {Double
Maybe PredictiveScalingPredefinedLoadMetric
Maybe PredictiveScalingPredefinedMetricPair
Maybe PredictiveScalingPredefinedScalingMetric
targetValue :: Double
predefinedLoadMetricSpecification :: Maybe PredictiveScalingPredefinedLoadMetric
predefinedMetricPairSpecification :: Maybe PredictiveScalingPredefinedMetricPair
predefinedScalingMetricSpecification :: Maybe PredictiveScalingPredefinedScalingMetric
$sel:targetValue:PredictiveScalingMetricSpecification' :: PredictiveScalingMetricSpecification -> Double
$sel:predefinedLoadMetricSpecification:PredictiveScalingMetricSpecification' :: PredictiveScalingMetricSpecification
-> Maybe PredictiveScalingPredefinedLoadMetric
$sel:predefinedMetricPairSpecification:PredictiveScalingMetricSpecification' :: PredictiveScalingMetricSpecification
-> Maybe PredictiveScalingPredefinedMetricPair
$sel:predefinedScalingMetricSpecification:PredictiveScalingMetricSpecification' :: PredictiveScalingMetricSpecification
-> Maybe PredictiveScalingPredefinedScalingMetric
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"PredefinedScalingMetricSpecification"
          ByteString
-> Maybe PredictiveScalingPredefinedScalingMetric -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe PredictiveScalingPredefinedScalingMetric
predefinedScalingMetricSpecification,
        ByteString
"PredefinedMetricPairSpecification"
          ByteString
-> Maybe PredictiveScalingPredefinedMetricPair -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe PredictiveScalingPredefinedMetricPair
predefinedMetricPairSpecification,
        ByteString
"PredefinedLoadMetricSpecification"
          ByteString
-> Maybe PredictiveScalingPredefinedLoadMetric -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe PredictiveScalingPredefinedLoadMetric
predefinedLoadMetricSpecification,
        ByteString
"TargetValue" ByteString -> Double -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Double
targetValue
      ]