{-# 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.XRay.Types.SamplingTargetDocument
-- 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.XRay.Types.SamplingTargetDocument where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Temporary changes to a sampling rule configuration. To meet the global
-- sampling target for a rule, X-Ray calculates a new reservoir for each
-- service based on the recent sampling results of all services that called
-- <https://docs.aws.amazon.com/xray/latest/api/API_GetSamplingTargets.html GetSamplingTargets>.
--
-- /See:/ 'newSamplingTargetDocument' smart constructor.
data SamplingTargetDocument = SamplingTargetDocument'
  { -- | The number of requests per second that X-Ray allocated for this service.
    SamplingTargetDocument -> Maybe Int
reservoirQuota :: Prelude.Maybe Prelude.Int,
    -- | The name of the sampling rule.
    SamplingTargetDocument -> Maybe Text
ruleName :: Prelude.Maybe Prelude.Text,
    -- | The percentage of matching requests to instrument, after the reservoir
    -- is exhausted.
    SamplingTargetDocument -> Maybe Double
fixedRate :: Prelude.Maybe Prelude.Double,
    -- | The number of seconds for the service to wait before getting sampling
    -- targets again.
    SamplingTargetDocument -> Maybe Int
interval :: Prelude.Maybe Prelude.Int,
    -- | When the reservoir quota expires.
    SamplingTargetDocument -> Maybe POSIX
reservoirQuotaTTL :: Prelude.Maybe Core.POSIX
  }
  deriving (SamplingTargetDocument -> SamplingTargetDocument -> Bool
(SamplingTargetDocument -> SamplingTargetDocument -> Bool)
-> (SamplingTargetDocument -> SamplingTargetDocument -> Bool)
-> Eq SamplingTargetDocument
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SamplingTargetDocument -> SamplingTargetDocument -> Bool
$c/= :: SamplingTargetDocument -> SamplingTargetDocument -> Bool
== :: SamplingTargetDocument -> SamplingTargetDocument -> Bool
$c== :: SamplingTargetDocument -> SamplingTargetDocument -> Bool
Prelude.Eq, ReadPrec [SamplingTargetDocument]
ReadPrec SamplingTargetDocument
Int -> ReadS SamplingTargetDocument
ReadS [SamplingTargetDocument]
(Int -> ReadS SamplingTargetDocument)
-> ReadS [SamplingTargetDocument]
-> ReadPrec SamplingTargetDocument
-> ReadPrec [SamplingTargetDocument]
-> Read SamplingTargetDocument
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SamplingTargetDocument]
$creadListPrec :: ReadPrec [SamplingTargetDocument]
readPrec :: ReadPrec SamplingTargetDocument
$creadPrec :: ReadPrec SamplingTargetDocument
readList :: ReadS [SamplingTargetDocument]
$creadList :: ReadS [SamplingTargetDocument]
readsPrec :: Int -> ReadS SamplingTargetDocument
$creadsPrec :: Int -> ReadS SamplingTargetDocument
Prelude.Read, Int -> SamplingTargetDocument -> ShowS
[SamplingTargetDocument] -> ShowS
SamplingTargetDocument -> String
(Int -> SamplingTargetDocument -> ShowS)
-> (SamplingTargetDocument -> String)
-> ([SamplingTargetDocument] -> ShowS)
-> Show SamplingTargetDocument
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SamplingTargetDocument] -> ShowS
$cshowList :: [SamplingTargetDocument] -> ShowS
show :: SamplingTargetDocument -> String
$cshow :: SamplingTargetDocument -> String
showsPrec :: Int -> SamplingTargetDocument -> ShowS
$cshowsPrec :: Int -> SamplingTargetDocument -> ShowS
Prelude.Show, (forall x. SamplingTargetDocument -> Rep SamplingTargetDocument x)
-> (forall x.
    Rep SamplingTargetDocument x -> SamplingTargetDocument)
-> Generic SamplingTargetDocument
forall x. Rep SamplingTargetDocument x -> SamplingTargetDocument
forall x. SamplingTargetDocument -> Rep SamplingTargetDocument x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SamplingTargetDocument x -> SamplingTargetDocument
$cfrom :: forall x. SamplingTargetDocument -> Rep SamplingTargetDocument x
Prelude.Generic)

-- |
-- Create a value of 'SamplingTargetDocument' 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:
--
-- 'reservoirQuota', 'samplingTargetDocument_reservoirQuota' - The number of requests per second that X-Ray allocated for this service.
--
-- 'ruleName', 'samplingTargetDocument_ruleName' - The name of the sampling rule.
--
-- 'fixedRate', 'samplingTargetDocument_fixedRate' - The percentage of matching requests to instrument, after the reservoir
-- is exhausted.
--
-- 'interval', 'samplingTargetDocument_interval' - The number of seconds for the service to wait before getting sampling
-- targets again.
--
-- 'reservoirQuotaTTL', 'samplingTargetDocument_reservoirQuotaTTL' - When the reservoir quota expires.
newSamplingTargetDocument ::
  SamplingTargetDocument
newSamplingTargetDocument :: SamplingTargetDocument
newSamplingTargetDocument =
  SamplingTargetDocument' :: Maybe Int
-> Maybe Text
-> Maybe Double
-> Maybe Int
-> Maybe POSIX
-> SamplingTargetDocument
SamplingTargetDocument'
    { $sel:reservoirQuota:SamplingTargetDocument' :: Maybe Int
reservoirQuota =
        Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:ruleName:SamplingTargetDocument' :: Maybe Text
ruleName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:fixedRate:SamplingTargetDocument' :: Maybe Double
fixedRate = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:interval:SamplingTargetDocument' :: Maybe Int
interval = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:reservoirQuotaTTL:SamplingTargetDocument' :: Maybe POSIX
reservoirQuotaTTL = Maybe POSIX
forall a. Maybe a
Prelude.Nothing
    }

-- | The number of requests per second that X-Ray allocated for this service.
samplingTargetDocument_reservoirQuota :: Lens.Lens' SamplingTargetDocument (Prelude.Maybe Prelude.Int)
samplingTargetDocument_reservoirQuota :: (Maybe Int -> f (Maybe Int))
-> SamplingTargetDocument -> f SamplingTargetDocument
samplingTargetDocument_reservoirQuota = (SamplingTargetDocument -> Maybe Int)
-> (SamplingTargetDocument -> Maybe Int -> SamplingTargetDocument)
-> Lens
     SamplingTargetDocument
     SamplingTargetDocument
     (Maybe Int)
     (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingTargetDocument' {Maybe Int
reservoirQuota :: Maybe Int
$sel:reservoirQuota:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Int
reservoirQuota} -> Maybe Int
reservoirQuota) (\s :: SamplingTargetDocument
s@SamplingTargetDocument' {} Maybe Int
a -> SamplingTargetDocument
s {$sel:reservoirQuota:SamplingTargetDocument' :: Maybe Int
reservoirQuota = Maybe Int
a} :: SamplingTargetDocument)

-- | The name of the sampling rule.
samplingTargetDocument_ruleName :: Lens.Lens' SamplingTargetDocument (Prelude.Maybe Prelude.Text)
samplingTargetDocument_ruleName :: (Maybe Text -> f (Maybe Text))
-> SamplingTargetDocument -> f SamplingTargetDocument
samplingTargetDocument_ruleName = (SamplingTargetDocument -> Maybe Text)
-> (SamplingTargetDocument -> Maybe Text -> SamplingTargetDocument)
-> Lens
     SamplingTargetDocument
     SamplingTargetDocument
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingTargetDocument' {Maybe Text
ruleName :: Maybe Text
$sel:ruleName:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Text
ruleName} -> Maybe Text
ruleName) (\s :: SamplingTargetDocument
s@SamplingTargetDocument' {} Maybe Text
a -> SamplingTargetDocument
s {$sel:ruleName:SamplingTargetDocument' :: Maybe Text
ruleName = Maybe Text
a} :: SamplingTargetDocument)

-- | The percentage of matching requests to instrument, after the reservoir
-- is exhausted.
samplingTargetDocument_fixedRate :: Lens.Lens' SamplingTargetDocument (Prelude.Maybe Prelude.Double)
samplingTargetDocument_fixedRate :: (Maybe Double -> f (Maybe Double))
-> SamplingTargetDocument -> f SamplingTargetDocument
samplingTargetDocument_fixedRate = (SamplingTargetDocument -> Maybe Double)
-> (SamplingTargetDocument
    -> Maybe Double -> SamplingTargetDocument)
-> Lens
     SamplingTargetDocument
     SamplingTargetDocument
     (Maybe Double)
     (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingTargetDocument' {Maybe Double
fixedRate :: Maybe Double
$sel:fixedRate:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Double
fixedRate} -> Maybe Double
fixedRate) (\s :: SamplingTargetDocument
s@SamplingTargetDocument' {} Maybe Double
a -> SamplingTargetDocument
s {$sel:fixedRate:SamplingTargetDocument' :: Maybe Double
fixedRate = Maybe Double
a} :: SamplingTargetDocument)

-- | The number of seconds for the service to wait before getting sampling
-- targets again.
samplingTargetDocument_interval :: Lens.Lens' SamplingTargetDocument (Prelude.Maybe Prelude.Int)
samplingTargetDocument_interval :: (Maybe Int -> f (Maybe Int))
-> SamplingTargetDocument -> f SamplingTargetDocument
samplingTargetDocument_interval = (SamplingTargetDocument -> Maybe Int)
-> (SamplingTargetDocument -> Maybe Int -> SamplingTargetDocument)
-> Lens
     SamplingTargetDocument
     SamplingTargetDocument
     (Maybe Int)
     (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingTargetDocument' {Maybe Int
interval :: Maybe Int
$sel:interval:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Int
interval} -> Maybe Int
interval) (\s :: SamplingTargetDocument
s@SamplingTargetDocument' {} Maybe Int
a -> SamplingTargetDocument
s {$sel:interval:SamplingTargetDocument' :: Maybe Int
interval = Maybe Int
a} :: SamplingTargetDocument)

-- | When the reservoir quota expires.
samplingTargetDocument_reservoirQuotaTTL :: Lens.Lens' SamplingTargetDocument (Prelude.Maybe Prelude.UTCTime)
samplingTargetDocument_reservoirQuotaTTL :: (Maybe UTCTime -> f (Maybe UTCTime))
-> SamplingTargetDocument -> f SamplingTargetDocument
samplingTargetDocument_reservoirQuotaTTL = (SamplingTargetDocument -> Maybe POSIX)
-> (SamplingTargetDocument
    -> Maybe POSIX -> SamplingTargetDocument)
-> Lens
     SamplingTargetDocument
     SamplingTargetDocument
     (Maybe POSIX)
     (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingTargetDocument' {Maybe POSIX
reservoirQuotaTTL :: Maybe POSIX
$sel:reservoirQuotaTTL:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe POSIX
reservoirQuotaTTL} -> Maybe POSIX
reservoirQuotaTTL) (\s :: SamplingTargetDocument
s@SamplingTargetDocument' {} Maybe POSIX
a -> SamplingTargetDocument
s {$sel:reservoirQuotaTTL:SamplingTargetDocument' :: Maybe POSIX
reservoirQuotaTTL = Maybe POSIX
a} :: SamplingTargetDocument) ((Maybe POSIX -> f (Maybe POSIX))
 -> SamplingTargetDocument -> f SamplingTargetDocument)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> SamplingTargetDocument
-> f SamplingTargetDocument
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Core.FromJSON SamplingTargetDocument where
  parseJSON :: Value -> Parser SamplingTargetDocument
parseJSON =
    String
-> (Object -> Parser SamplingTargetDocument)
-> Value
-> Parser SamplingTargetDocument
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SamplingTargetDocument"
      ( \Object
x ->
          Maybe Int
-> Maybe Text
-> Maybe Double
-> Maybe Int
-> Maybe POSIX
-> SamplingTargetDocument
SamplingTargetDocument'
            (Maybe Int
 -> Maybe Text
 -> Maybe Double
 -> Maybe Int
 -> Maybe POSIX
 -> SamplingTargetDocument)
-> Parser (Maybe Int)
-> Parser
     (Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Maybe POSIX
      -> SamplingTargetDocument)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ReservoirQuota")
            Parser
  (Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Maybe POSIX
   -> SamplingTargetDocument)
-> Parser (Maybe Text)
-> Parser
     (Maybe Double
      -> Maybe Int -> Maybe POSIX -> SamplingTargetDocument)
forall (f :: * -> *) a b. Applicative f => 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
"RuleName")
            Parser
  (Maybe Double
   -> Maybe Int -> Maybe POSIX -> SamplingTargetDocument)
-> Parser (Maybe Double)
-> Parser (Maybe Int -> Maybe POSIX -> SamplingTargetDocument)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"FixedRate")
            Parser (Maybe Int -> Maybe POSIX -> SamplingTargetDocument)
-> Parser (Maybe Int)
-> Parser (Maybe POSIX -> SamplingTargetDocument)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Interval")
            Parser (Maybe POSIX -> SamplingTargetDocument)
-> Parser (Maybe POSIX) -> Parser SamplingTargetDocument
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ReservoirQuotaTTL")
      )

instance Prelude.Hashable SamplingTargetDocument

instance Prelude.NFData SamplingTargetDocument