{-# 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.ApplicationAutoScaling.Types.PredefinedMetricSpecification
-- 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.ApplicationAutoScaling.Types.PredefinedMetricSpecification where

import Amazonka.ApplicationAutoScaling.Types.MetricType
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

-- | Represents a predefined metric for a target tracking scaling policy to
-- use with Application Auto Scaling.
--
-- Only the Amazon Web Services that you\'re using send metrics to Amazon
-- CloudWatch. To determine whether a desired metric already exists by
-- looking up its namespace and dimension using the CloudWatch metrics
-- dashboard in the console, follow the procedure in
-- <https://docs.aws.amazon.com/autoscaling/application/userguide/monitoring-cloudwatch.html Building dashboards with CloudWatch>
-- in the /Application Auto Scaling User Guide/.
--
-- /See:/ 'newPredefinedMetricSpecification' smart constructor.
data PredefinedMetricSpecification = PredefinedMetricSpecification'
  { -- | 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 attached to the
    -- Spot Fleet 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 of the resource
    -- label is:
    --
    -- @app\/my-alb\/778d41231b141a0f\/targetgroup\/my-alb-target-group\/943f017f100becff@.
    --
    -- 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.
    --
    -- 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.
    PredefinedMetricSpecification -> Maybe Text
resourceLabel :: Prelude.Maybe Prelude.Text,
    -- | The metric type. The @ALBRequestCountPerTarget@ metric type applies only
    -- to Spot Fleets and ECS services.
    PredefinedMetricSpecification -> MetricType
predefinedMetricType :: MetricType
  }
  deriving (PredefinedMetricSpecification
-> PredefinedMetricSpecification -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PredefinedMetricSpecification
-> PredefinedMetricSpecification -> Bool
$c/= :: PredefinedMetricSpecification
-> PredefinedMetricSpecification -> Bool
== :: PredefinedMetricSpecification
-> PredefinedMetricSpecification -> Bool
$c== :: PredefinedMetricSpecification
-> PredefinedMetricSpecification -> Bool
Prelude.Eq, ReadPrec [PredefinedMetricSpecification]
ReadPrec PredefinedMetricSpecification
Int -> ReadS PredefinedMetricSpecification
ReadS [PredefinedMetricSpecification]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PredefinedMetricSpecification]
$creadListPrec :: ReadPrec [PredefinedMetricSpecification]
readPrec :: ReadPrec PredefinedMetricSpecification
$creadPrec :: ReadPrec PredefinedMetricSpecification
readList :: ReadS [PredefinedMetricSpecification]
$creadList :: ReadS [PredefinedMetricSpecification]
readsPrec :: Int -> ReadS PredefinedMetricSpecification
$creadsPrec :: Int -> ReadS PredefinedMetricSpecification
Prelude.Read, Int -> PredefinedMetricSpecification -> ShowS
[PredefinedMetricSpecification] -> ShowS
PredefinedMetricSpecification -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PredefinedMetricSpecification] -> ShowS
$cshowList :: [PredefinedMetricSpecification] -> ShowS
show :: PredefinedMetricSpecification -> String
$cshow :: PredefinedMetricSpecification -> String
showsPrec :: Int -> PredefinedMetricSpecification -> ShowS
$cshowsPrec :: Int -> PredefinedMetricSpecification -> ShowS
Prelude.Show, forall x.
Rep PredefinedMetricSpecification x
-> PredefinedMetricSpecification
forall x.
PredefinedMetricSpecification
-> Rep PredefinedMetricSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PredefinedMetricSpecification x
-> PredefinedMetricSpecification
$cfrom :: forall x.
PredefinedMetricSpecification
-> Rep PredefinedMetricSpecification x
Prelude.Generic)

-- |
-- Create a value of 'PredefinedMetricSpecification' 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', 'predefinedMetricSpecification_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 attached to the
-- Spot Fleet 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 of the resource
-- label is:
--
-- @app\/my-alb\/778d41231b141a0f\/targetgroup\/my-alb-target-group\/943f017f100becff@.
--
-- 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.
--
-- 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.
--
-- 'predefinedMetricType', 'predefinedMetricSpecification_predefinedMetricType' - The metric type. The @ALBRequestCountPerTarget@ metric type applies only
-- to Spot Fleets and ECS services.
newPredefinedMetricSpecification ::
  -- | 'predefinedMetricType'
  MetricType ->
  PredefinedMetricSpecification
newPredefinedMetricSpecification :: MetricType -> PredefinedMetricSpecification
newPredefinedMetricSpecification
  MetricType
pPredefinedMetricType_ =
    PredefinedMetricSpecification'
      { $sel:resourceLabel:PredefinedMetricSpecification' :: Maybe Text
resourceLabel =
          forall a. Maybe a
Prelude.Nothing,
        $sel:predefinedMetricType:PredefinedMetricSpecification' :: MetricType
predefinedMetricType =
          MetricType
pPredefinedMetricType_
      }

-- | 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 attached to the
-- Spot Fleet 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 of the resource
-- label is:
--
-- @app\/my-alb\/778d41231b141a0f\/targetgroup\/my-alb-target-group\/943f017f100becff@.
--
-- 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.
--
-- 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.
predefinedMetricSpecification_resourceLabel :: Lens.Lens' PredefinedMetricSpecification (Prelude.Maybe Prelude.Text)
predefinedMetricSpecification_resourceLabel :: Lens' PredefinedMetricSpecification (Maybe Text)
predefinedMetricSpecification_resourceLabel = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredefinedMetricSpecification' {Maybe Text
resourceLabel :: Maybe Text
$sel:resourceLabel:PredefinedMetricSpecification' :: PredefinedMetricSpecification -> Maybe Text
resourceLabel} -> Maybe Text
resourceLabel) (\s :: PredefinedMetricSpecification
s@PredefinedMetricSpecification' {} Maybe Text
a -> PredefinedMetricSpecification
s {$sel:resourceLabel:PredefinedMetricSpecification' :: Maybe Text
resourceLabel = Maybe Text
a} :: PredefinedMetricSpecification)

-- | The metric type. The @ALBRequestCountPerTarget@ metric type applies only
-- to Spot Fleets and ECS services.
predefinedMetricSpecification_predefinedMetricType :: Lens.Lens' PredefinedMetricSpecification MetricType
predefinedMetricSpecification_predefinedMetricType :: Lens' PredefinedMetricSpecification MetricType
predefinedMetricSpecification_predefinedMetricType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredefinedMetricSpecification' {MetricType
predefinedMetricType :: MetricType
$sel:predefinedMetricType:PredefinedMetricSpecification' :: PredefinedMetricSpecification -> MetricType
predefinedMetricType} -> MetricType
predefinedMetricType) (\s :: PredefinedMetricSpecification
s@PredefinedMetricSpecification' {} MetricType
a -> PredefinedMetricSpecification
s {$sel:predefinedMetricType:PredefinedMetricSpecification' :: MetricType
predefinedMetricType = MetricType
a} :: PredefinedMetricSpecification)

instance Data.FromJSON PredefinedMetricSpecification where
  parseJSON :: Value -> Parser PredefinedMetricSpecification
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PredefinedMetricSpecification"
      ( \Object
x ->
          Maybe Text -> MetricType -> PredefinedMetricSpecification
PredefinedMetricSpecification'
            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
"ResourceLabel")
            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
"PredefinedMetricType")
      )

instance
  Prelude.Hashable
    PredefinedMetricSpecification
  where
  hashWithSalt :: Int -> PredefinedMetricSpecification -> Int
hashWithSalt Int
_salt PredefinedMetricSpecification' {Maybe Text
MetricType
predefinedMetricType :: MetricType
resourceLabel :: Maybe Text
$sel:predefinedMetricType:PredefinedMetricSpecification' :: PredefinedMetricSpecification -> MetricType
$sel:resourceLabel:PredefinedMetricSpecification' :: PredefinedMetricSpecification -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
resourceLabel
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` MetricType
predefinedMetricType

instance Prelude.NFData PredefinedMetricSpecification where
  rnf :: PredefinedMetricSpecification -> ()
rnf PredefinedMetricSpecification' {Maybe Text
MetricType
predefinedMetricType :: MetricType
resourceLabel :: Maybe Text
$sel:predefinedMetricType:PredefinedMetricSpecification' :: PredefinedMetricSpecification -> MetricType
$sel:resourceLabel:PredefinedMetricSpecification' :: PredefinedMetricSpecification -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
resourceLabel
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf MetricType
predefinedMetricType

instance Data.ToJSON PredefinedMetricSpecification where
  toJSON :: PredefinedMetricSpecification -> Value
toJSON PredefinedMetricSpecification' {Maybe Text
MetricType
predefinedMetricType :: MetricType
resourceLabel :: Maybe Text
$sel:predefinedMetricType:PredefinedMetricSpecification' :: PredefinedMetricSpecification -> MetricType
$sel:resourceLabel:PredefinedMetricSpecification' :: PredefinedMetricSpecification -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ResourceLabel" 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 Text
resourceLabel,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"PredefinedMetricType"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= MetricType
predefinedMetricType
              )
          ]
      )