{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.XRay.Types.SamplingTargetDocument where

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

-- | 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 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,
    -- | The number of requests per second that X-Ray allocated for this service.
    SamplingTargetDocument -> Maybe Int
reservoirQuota :: Prelude.Maybe Prelude.Int,
    -- | When the reservoir quota expires.
    SamplingTargetDocument -> Maybe POSIX
reservoirQuotaTTL :: Prelude.Maybe Data.POSIX,
    -- | The name of the sampling rule.
    SamplingTargetDocument -> Maybe Text
ruleName :: Prelude.Maybe Prelude.Text
  }
  deriving (SamplingTargetDocument -> SamplingTargetDocument -> Bool
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]
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
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. 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:
--
-- '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.
--
-- 'reservoirQuota', 'samplingTargetDocument_reservoirQuota' - The number of requests per second that X-Ray allocated for this service.
--
-- 'reservoirQuotaTTL', 'samplingTargetDocument_reservoirQuotaTTL' - When the reservoir quota expires.
--
-- 'ruleName', 'samplingTargetDocument_ruleName' - The name of the sampling rule.
newSamplingTargetDocument ::
  SamplingTargetDocument
newSamplingTargetDocument :: SamplingTargetDocument
newSamplingTargetDocument =
  SamplingTargetDocument'
    { $sel:fixedRate:SamplingTargetDocument' :: Maybe Double
fixedRate =
        forall a. Maybe a
Prelude.Nothing,
      $sel:interval:SamplingTargetDocument' :: Maybe Int
interval = forall a. Maybe a
Prelude.Nothing,
      $sel:reservoirQuota:SamplingTargetDocument' :: Maybe Int
reservoirQuota = forall a. Maybe a
Prelude.Nothing,
      $sel:reservoirQuotaTTL:SamplingTargetDocument' :: Maybe POSIX
reservoirQuotaTTL = forall a. Maybe a
Prelude.Nothing,
      $sel:ruleName:SamplingTargetDocument' :: Maybe Text
ruleName = forall a. Maybe a
Prelude.Nothing
    }

-- | The percentage of matching requests to instrument, after the reservoir
-- is exhausted.
samplingTargetDocument_fixedRate :: Lens.Lens' SamplingTargetDocument (Prelude.Maybe Prelude.Double)
samplingTargetDocument_fixedRate :: Lens' SamplingTargetDocument (Maybe Double)
samplingTargetDocument_fixedRate = 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 :: Lens' SamplingTargetDocument (Maybe Int)
samplingTargetDocument_interval = 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)

-- | The number of requests per second that X-Ray allocated for this service.
samplingTargetDocument_reservoirQuota :: Lens.Lens' SamplingTargetDocument (Prelude.Maybe Prelude.Int)
samplingTargetDocument_reservoirQuota :: Lens' SamplingTargetDocument (Maybe Int)
samplingTargetDocument_reservoirQuota = 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)

-- | When the reservoir quota expires.
samplingTargetDocument_reservoirQuotaTTL :: Lens.Lens' SamplingTargetDocument (Prelude.Maybe Prelude.UTCTime)
samplingTargetDocument_reservoirQuotaTTL :: Lens' SamplingTargetDocument (Maybe UTCTime)
samplingTargetDocument_reservoirQuotaTTL = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The name of the sampling rule.
samplingTargetDocument_ruleName :: Lens.Lens' SamplingTargetDocument (Prelude.Maybe Prelude.Text)
samplingTargetDocument_ruleName :: Lens' SamplingTargetDocument (Maybe Text)
samplingTargetDocument_ruleName = 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)

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

instance Prelude.Hashable SamplingTargetDocument where
  hashWithSalt :: Int -> SamplingTargetDocument -> Int
hashWithSalt Int
_salt SamplingTargetDocument' {Maybe Double
Maybe Int
Maybe Text
Maybe POSIX
ruleName :: Maybe Text
reservoirQuotaTTL :: Maybe POSIX
reservoirQuota :: Maybe Int
interval :: Maybe Int
fixedRate :: Maybe Double
$sel:ruleName:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Text
$sel:reservoirQuotaTTL:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe POSIX
$sel:reservoirQuota:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Int
$sel:interval:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Int
$sel:fixedRate:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
fixedRate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
interval
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
reservoirQuota
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
reservoirQuotaTTL
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
ruleName

instance Prelude.NFData SamplingTargetDocument where
  rnf :: SamplingTargetDocument -> ()
rnf SamplingTargetDocument' {Maybe Double
Maybe Int
Maybe Text
Maybe POSIX
ruleName :: Maybe Text
reservoirQuotaTTL :: Maybe POSIX
reservoirQuota :: Maybe Int
interval :: Maybe Int
fixedRate :: Maybe Double
$sel:ruleName:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Text
$sel:reservoirQuotaTTL:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe POSIX
$sel:reservoirQuota:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Int
$sel:interval:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Int
$sel:fixedRate:SamplingTargetDocument' :: SamplingTargetDocument -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
fixedRate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
interval
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
reservoirQuota
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
reservoirQuotaTTL
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
ruleName