{-# 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.AutoScalingPlans.Types.PredefinedScalingMetricSpecification
-- 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.AutoScalingPlans.Types.PredefinedScalingMetricSpecification where

import Amazonka.AutoScalingPlans.Types.ScalingMetricType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a predefined metric that can be used for dynamic scaling as
-- part of a target tracking scaling policy.
--
-- /See:/ 'newPredefinedScalingMetricSpecification' smart constructor.
data PredefinedScalingMetricSpecification = PredefinedScalingMetricSpecification'
  { -- | Identifies the resource associated with the metric type. You can\'t
    -- specify a resource label unless the metric type is
    -- @ALBRequestCountPerTarget@ and there is a target group for an
    -- Application Load Balancer attached to the Auto Scaling group, Spot Fleet
    -- request, or ECS service.
    --
    -- You create the resource label by appending the final portion of the load
    -- balancer ARN and the final portion of the target group ARN into a single
    -- value, separated by a forward slash (\/). The format is
    -- app\/\<load-balancer-name>\/\<load-balancer-id>\/targetgroup\/\<target-group-name>\/\<target-group-id>,
    -- where:
    --
    -- -   app\/\<load-balancer-name>\/\<load-balancer-id> is the final portion
    --     of the load balancer ARN
    --
    -- -   targetgroup\/\<target-group-name>\/\<target-group-id> is the final
    --     portion of the target group ARN.
    --
    -- This is an example:
    -- app\/EC2Co-EcsEl-1TKLTMITMM0EO\/f37c06a68c1748aa\/targetgroup\/EC2Co-Defau-LDNM7Q3ZH1ZN\/6d4ea56ca2d6a18d.
    --
    -- To find the ARN for an Application Load Balancer, use the
    -- <https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeLoadBalancers.html DescribeLoadBalancers>
    -- API operation. To find the ARN for the target group, use the
    -- <https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeTargetGroups.html DescribeTargetGroups>
    -- API operation.
    PredefinedScalingMetricSpecification -> Maybe Text
resourceLabel :: Prelude.Maybe Prelude.Text,
    -- | The metric type. The @ALBRequestCountPerTarget@ metric type applies only
    -- to Auto Scaling groups, Spot Fleet requests, and ECS services.
    PredefinedScalingMetricSpecification -> ScalingMetricType
predefinedScalingMetricType :: ScalingMetricType
  }
  deriving (PredefinedScalingMetricSpecification
-> PredefinedScalingMetricSpecification -> Bool
(PredefinedScalingMetricSpecification
 -> PredefinedScalingMetricSpecification -> Bool)
-> (PredefinedScalingMetricSpecification
    -> PredefinedScalingMetricSpecification -> Bool)
-> Eq PredefinedScalingMetricSpecification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PredefinedScalingMetricSpecification
-> PredefinedScalingMetricSpecification -> Bool
$c/= :: PredefinedScalingMetricSpecification
-> PredefinedScalingMetricSpecification -> Bool
== :: PredefinedScalingMetricSpecification
-> PredefinedScalingMetricSpecification -> Bool
$c== :: PredefinedScalingMetricSpecification
-> PredefinedScalingMetricSpecification -> Bool
Prelude.Eq, ReadPrec [PredefinedScalingMetricSpecification]
ReadPrec PredefinedScalingMetricSpecification
Int -> ReadS PredefinedScalingMetricSpecification
ReadS [PredefinedScalingMetricSpecification]
(Int -> ReadS PredefinedScalingMetricSpecification)
-> ReadS [PredefinedScalingMetricSpecification]
-> ReadPrec PredefinedScalingMetricSpecification
-> ReadPrec [PredefinedScalingMetricSpecification]
-> Read PredefinedScalingMetricSpecification
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PredefinedScalingMetricSpecification]
$creadListPrec :: ReadPrec [PredefinedScalingMetricSpecification]
readPrec :: ReadPrec PredefinedScalingMetricSpecification
$creadPrec :: ReadPrec PredefinedScalingMetricSpecification
readList :: ReadS [PredefinedScalingMetricSpecification]
$creadList :: ReadS [PredefinedScalingMetricSpecification]
readsPrec :: Int -> ReadS PredefinedScalingMetricSpecification
$creadsPrec :: Int -> ReadS PredefinedScalingMetricSpecification
Prelude.Read, Int -> PredefinedScalingMetricSpecification -> ShowS
[PredefinedScalingMetricSpecification] -> ShowS
PredefinedScalingMetricSpecification -> String
(Int -> PredefinedScalingMetricSpecification -> ShowS)
-> (PredefinedScalingMetricSpecification -> String)
-> ([PredefinedScalingMetricSpecification] -> ShowS)
-> Show PredefinedScalingMetricSpecification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PredefinedScalingMetricSpecification] -> ShowS
$cshowList :: [PredefinedScalingMetricSpecification] -> ShowS
show :: PredefinedScalingMetricSpecification -> String
$cshow :: PredefinedScalingMetricSpecification -> String
showsPrec :: Int -> PredefinedScalingMetricSpecification -> ShowS
$cshowsPrec :: Int -> PredefinedScalingMetricSpecification -> ShowS
Prelude.Show, (forall x.
 PredefinedScalingMetricSpecification
 -> Rep PredefinedScalingMetricSpecification x)
-> (forall x.
    Rep PredefinedScalingMetricSpecification x
    -> PredefinedScalingMetricSpecification)
-> Generic PredefinedScalingMetricSpecification
forall x.
Rep PredefinedScalingMetricSpecification x
-> PredefinedScalingMetricSpecification
forall x.
PredefinedScalingMetricSpecification
-> Rep PredefinedScalingMetricSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PredefinedScalingMetricSpecification x
-> PredefinedScalingMetricSpecification
$cfrom :: forall x.
PredefinedScalingMetricSpecification
-> Rep PredefinedScalingMetricSpecification x
Prelude.Generic)

-- |
-- Create a value of 'PredefinedScalingMetricSpecification' 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:
--
-- 'resourceLabel', 'predefinedScalingMetricSpecification_resourceLabel' - Identifies the resource associated with the metric type. You can\'t
-- specify a resource label unless the metric type is
-- @ALBRequestCountPerTarget@ and there is a target group for an
-- Application Load Balancer attached to the Auto Scaling group, Spot Fleet
-- request, or ECS service.
--
-- You create the resource label by appending the final portion of the load
-- balancer ARN and the final portion of the target group ARN into a single
-- value, separated by a forward slash (\/). The format is
-- app\/\<load-balancer-name>\/\<load-balancer-id>\/targetgroup\/\<target-group-name>\/\<target-group-id>,
-- where:
--
-- -   app\/\<load-balancer-name>\/\<load-balancer-id> is the final portion
--     of the load balancer ARN
--
-- -   targetgroup\/\<target-group-name>\/\<target-group-id> is the final
--     portion of the target group ARN.
--
-- This is an example:
-- app\/EC2Co-EcsEl-1TKLTMITMM0EO\/f37c06a68c1748aa\/targetgroup\/EC2Co-Defau-LDNM7Q3ZH1ZN\/6d4ea56ca2d6a18d.
--
-- To find the ARN for an Application Load Balancer, use the
-- <https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeLoadBalancers.html DescribeLoadBalancers>
-- API operation. To find the ARN for the target group, use the
-- <https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeTargetGroups.html DescribeTargetGroups>
-- API operation.
--
-- 'predefinedScalingMetricType', 'predefinedScalingMetricSpecification_predefinedScalingMetricType' - The metric type. The @ALBRequestCountPerTarget@ metric type applies only
-- to Auto Scaling groups, Spot Fleet requests, and ECS services.
newPredefinedScalingMetricSpecification ::
  -- | 'predefinedScalingMetricType'
  ScalingMetricType ->
  PredefinedScalingMetricSpecification
newPredefinedScalingMetricSpecification :: ScalingMetricType -> PredefinedScalingMetricSpecification
newPredefinedScalingMetricSpecification
  ScalingMetricType
pPredefinedScalingMetricType_ =
    PredefinedScalingMetricSpecification' :: Maybe Text
-> ScalingMetricType -> PredefinedScalingMetricSpecification
PredefinedScalingMetricSpecification'
      { $sel:resourceLabel:PredefinedScalingMetricSpecification' :: Maybe Text
resourceLabel =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:predefinedScalingMetricType:PredefinedScalingMetricSpecification' :: ScalingMetricType
predefinedScalingMetricType =
          ScalingMetricType
pPredefinedScalingMetricType_
      }

-- | Identifies the resource associated with the metric type. You can\'t
-- specify a resource label unless the metric type is
-- @ALBRequestCountPerTarget@ and there is a target group for an
-- Application Load Balancer attached to the Auto Scaling group, Spot Fleet
-- request, or ECS service.
--
-- You create the resource label by appending the final portion of the load
-- balancer ARN and the final portion of the target group ARN into a single
-- value, separated by a forward slash (\/). The format is
-- app\/\<load-balancer-name>\/\<load-balancer-id>\/targetgroup\/\<target-group-name>\/\<target-group-id>,
-- where:
--
-- -   app\/\<load-balancer-name>\/\<load-balancer-id> is the final portion
--     of the load balancer ARN
--
-- -   targetgroup\/\<target-group-name>\/\<target-group-id> is the final
--     portion of the target group ARN.
--
-- This is an example:
-- app\/EC2Co-EcsEl-1TKLTMITMM0EO\/f37c06a68c1748aa\/targetgroup\/EC2Co-Defau-LDNM7Q3ZH1ZN\/6d4ea56ca2d6a18d.
--
-- To find the ARN for an Application Load Balancer, use the
-- <https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeLoadBalancers.html DescribeLoadBalancers>
-- API operation. To find the ARN for the target group, use the
-- <https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeTargetGroups.html DescribeTargetGroups>
-- API operation.
predefinedScalingMetricSpecification_resourceLabel :: Lens.Lens' PredefinedScalingMetricSpecification (Prelude.Maybe Prelude.Text)
predefinedScalingMetricSpecification_resourceLabel :: (Maybe Text -> f (Maybe Text))
-> PredefinedScalingMetricSpecification
-> f PredefinedScalingMetricSpecification
predefinedScalingMetricSpecification_resourceLabel = (PredefinedScalingMetricSpecification -> Maybe Text)
-> (PredefinedScalingMetricSpecification
    -> Maybe Text -> PredefinedScalingMetricSpecification)
-> Lens
     PredefinedScalingMetricSpecification
     PredefinedScalingMetricSpecification
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredefinedScalingMetricSpecification' {Maybe Text
resourceLabel :: Maybe Text
$sel:resourceLabel:PredefinedScalingMetricSpecification' :: PredefinedScalingMetricSpecification -> Maybe Text
resourceLabel} -> Maybe Text
resourceLabel) (\s :: PredefinedScalingMetricSpecification
s@PredefinedScalingMetricSpecification' {} Maybe Text
a -> PredefinedScalingMetricSpecification
s {$sel:resourceLabel:PredefinedScalingMetricSpecification' :: Maybe Text
resourceLabel = Maybe Text
a} :: PredefinedScalingMetricSpecification)

-- | The metric type. The @ALBRequestCountPerTarget@ metric type applies only
-- to Auto Scaling groups, Spot Fleet requests, and ECS services.
predefinedScalingMetricSpecification_predefinedScalingMetricType :: Lens.Lens' PredefinedScalingMetricSpecification ScalingMetricType
predefinedScalingMetricSpecification_predefinedScalingMetricType :: (ScalingMetricType -> f ScalingMetricType)
-> PredefinedScalingMetricSpecification
-> f PredefinedScalingMetricSpecification
predefinedScalingMetricSpecification_predefinedScalingMetricType = (PredefinedScalingMetricSpecification -> ScalingMetricType)
-> (PredefinedScalingMetricSpecification
    -> ScalingMetricType -> PredefinedScalingMetricSpecification)
-> Lens
     PredefinedScalingMetricSpecification
     PredefinedScalingMetricSpecification
     ScalingMetricType
     ScalingMetricType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredefinedScalingMetricSpecification' {ScalingMetricType
predefinedScalingMetricType :: ScalingMetricType
$sel:predefinedScalingMetricType:PredefinedScalingMetricSpecification' :: PredefinedScalingMetricSpecification -> ScalingMetricType
predefinedScalingMetricType} -> ScalingMetricType
predefinedScalingMetricType) (\s :: PredefinedScalingMetricSpecification
s@PredefinedScalingMetricSpecification' {} ScalingMetricType
a -> PredefinedScalingMetricSpecification
s {$sel:predefinedScalingMetricType:PredefinedScalingMetricSpecification' :: ScalingMetricType
predefinedScalingMetricType = ScalingMetricType
a} :: PredefinedScalingMetricSpecification)

instance
  Core.FromJSON
    PredefinedScalingMetricSpecification
  where
  parseJSON :: Value -> Parser PredefinedScalingMetricSpecification
parseJSON =
    String
-> (Object -> Parser PredefinedScalingMetricSpecification)
-> Value
-> Parser PredefinedScalingMetricSpecification
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PredefinedScalingMetricSpecification"
      ( \Object
x ->
          Maybe Text
-> ScalingMetricType -> PredefinedScalingMetricSpecification
PredefinedScalingMetricSpecification'
            (Maybe Text
 -> ScalingMetricType -> PredefinedScalingMetricSpecification)
-> Parser (Maybe Text)
-> Parser
     (ScalingMetricType -> PredefinedScalingMetricSpecification)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ResourceLabel")
            Parser (ScalingMetricType -> PredefinedScalingMetricSpecification)
-> Parser ScalingMetricType
-> Parser PredefinedScalingMetricSpecification
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ScalingMetricType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"PredefinedScalingMetricType")
      )

instance
  Prelude.Hashable
    PredefinedScalingMetricSpecification

instance
  Prelude.NFData
    PredefinedScalingMetricSpecification

instance
  Core.ToJSON
    PredefinedScalingMetricSpecification
  where
  toJSON :: PredefinedScalingMetricSpecification -> Value
toJSON PredefinedScalingMetricSpecification' {Maybe Text
ScalingMetricType
predefinedScalingMetricType :: ScalingMetricType
resourceLabel :: Maybe Text
$sel:predefinedScalingMetricType:PredefinedScalingMetricSpecification' :: PredefinedScalingMetricSpecification -> ScalingMetricType
$sel:resourceLabel:PredefinedScalingMetricSpecification' :: PredefinedScalingMetricSpecification -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ResourceLabel" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
resourceLabel,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"PredefinedScalingMetricType"
                  Text -> ScalingMetricType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ScalingMetricType
predefinedScalingMetricType
              )
          ]
      )