{-# 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.AppMesh.Types.OutlierDetection
-- 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.AppMesh.Types.OutlierDetection where

import Amazonka.AppMesh.Types.Duration
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

-- | An object that represents the outlier detection for a virtual node\'s
-- listener.
--
-- /See:/ 'newOutlierDetection' smart constructor.
data OutlierDetection = OutlierDetection'
  { -- | The base amount of time for which a host is ejected.
    OutlierDetection -> Duration
baseEjectionDuration :: Duration,
    -- | The time interval between ejection sweep analysis.
    OutlierDetection -> Duration
interval :: Duration,
    -- | Maximum percentage of hosts in load balancing pool for upstream service
    -- that can be ejected. Will eject at least one host regardless of the
    -- value.
    OutlierDetection -> Natural
maxEjectionPercent :: Prelude.Natural,
    -- | Number of consecutive @5xx@ errors required for ejection.
    OutlierDetection -> Natural
maxServerErrors :: Prelude.Natural
  }
  deriving (OutlierDetection -> OutlierDetection -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OutlierDetection -> OutlierDetection -> Bool
$c/= :: OutlierDetection -> OutlierDetection -> Bool
== :: OutlierDetection -> OutlierDetection -> Bool
$c== :: OutlierDetection -> OutlierDetection -> Bool
Prelude.Eq, ReadPrec [OutlierDetection]
ReadPrec OutlierDetection
Int -> ReadS OutlierDetection
ReadS [OutlierDetection]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OutlierDetection]
$creadListPrec :: ReadPrec [OutlierDetection]
readPrec :: ReadPrec OutlierDetection
$creadPrec :: ReadPrec OutlierDetection
readList :: ReadS [OutlierDetection]
$creadList :: ReadS [OutlierDetection]
readsPrec :: Int -> ReadS OutlierDetection
$creadsPrec :: Int -> ReadS OutlierDetection
Prelude.Read, Int -> OutlierDetection -> ShowS
[OutlierDetection] -> ShowS
OutlierDetection -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OutlierDetection] -> ShowS
$cshowList :: [OutlierDetection] -> ShowS
show :: OutlierDetection -> String
$cshow :: OutlierDetection -> String
showsPrec :: Int -> OutlierDetection -> ShowS
$cshowsPrec :: Int -> OutlierDetection -> ShowS
Prelude.Show, forall x. Rep OutlierDetection x -> OutlierDetection
forall x. OutlierDetection -> Rep OutlierDetection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OutlierDetection x -> OutlierDetection
$cfrom :: forall x. OutlierDetection -> Rep OutlierDetection x
Prelude.Generic)

-- |
-- Create a value of 'OutlierDetection' 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:
--
-- 'baseEjectionDuration', 'outlierDetection_baseEjectionDuration' - The base amount of time for which a host is ejected.
--
-- 'interval', 'outlierDetection_interval' - The time interval between ejection sweep analysis.
--
-- 'maxEjectionPercent', 'outlierDetection_maxEjectionPercent' - Maximum percentage of hosts in load balancing pool for upstream service
-- that can be ejected. Will eject at least one host regardless of the
-- value.
--
-- 'maxServerErrors', 'outlierDetection_maxServerErrors' - Number of consecutive @5xx@ errors required for ejection.
newOutlierDetection ::
  -- | 'baseEjectionDuration'
  Duration ->
  -- | 'interval'
  Duration ->
  -- | 'maxEjectionPercent'
  Prelude.Natural ->
  -- | 'maxServerErrors'
  Prelude.Natural ->
  OutlierDetection
newOutlierDetection :: Duration -> Duration -> Natural -> Natural -> OutlierDetection
newOutlierDetection
  Duration
pBaseEjectionDuration_
  Duration
pInterval_
  Natural
pMaxEjectionPercent_
  Natural
pMaxServerErrors_ =
    OutlierDetection'
      { $sel:baseEjectionDuration:OutlierDetection' :: Duration
baseEjectionDuration =
          Duration
pBaseEjectionDuration_,
        $sel:interval:OutlierDetection' :: Duration
interval = Duration
pInterval_,
        $sel:maxEjectionPercent:OutlierDetection' :: Natural
maxEjectionPercent = Natural
pMaxEjectionPercent_,
        $sel:maxServerErrors:OutlierDetection' :: Natural
maxServerErrors = Natural
pMaxServerErrors_
      }

-- | The base amount of time for which a host is ejected.
outlierDetection_baseEjectionDuration :: Lens.Lens' OutlierDetection Duration
outlierDetection_baseEjectionDuration :: Lens' OutlierDetection Duration
outlierDetection_baseEjectionDuration = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OutlierDetection' {Duration
baseEjectionDuration :: Duration
$sel:baseEjectionDuration:OutlierDetection' :: OutlierDetection -> Duration
baseEjectionDuration} -> Duration
baseEjectionDuration) (\s :: OutlierDetection
s@OutlierDetection' {} Duration
a -> OutlierDetection
s {$sel:baseEjectionDuration:OutlierDetection' :: Duration
baseEjectionDuration = Duration
a} :: OutlierDetection)

-- | The time interval between ejection sweep analysis.
outlierDetection_interval :: Lens.Lens' OutlierDetection Duration
outlierDetection_interval :: Lens' OutlierDetection Duration
outlierDetection_interval = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OutlierDetection' {Duration
interval :: Duration
$sel:interval:OutlierDetection' :: OutlierDetection -> Duration
interval} -> Duration
interval) (\s :: OutlierDetection
s@OutlierDetection' {} Duration
a -> OutlierDetection
s {$sel:interval:OutlierDetection' :: Duration
interval = Duration
a} :: OutlierDetection)

-- | Maximum percentage of hosts in load balancing pool for upstream service
-- that can be ejected. Will eject at least one host regardless of the
-- value.
outlierDetection_maxEjectionPercent :: Lens.Lens' OutlierDetection Prelude.Natural
outlierDetection_maxEjectionPercent :: Lens' OutlierDetection Natural
outlierDetection_maxEjectionPercent = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OutlierDetection' {Natural
maxEjectionPercent :: Natural
$sel:maxEjectionPercent:OutlierDetection' :: OutlierDetection -> Natural
maxEjectionPercent} -> Natural
maxEjectionPercent) (\s :: OutlierDetection
s@OutlierDetection' {} Natural
a -> OutlierDetection
s {$sel:maxEjectionPercent:OutlierDetection' :: Natural
maxEjectionPercent = Natural
a} :: OutlierDetection)

-- | Number of consecutive @5xx@ errors required for ejection.
outlierDetection_maxServerErrors :: Lens.Lens' OutlierDetection Prelude.Natural
outlierDetection_maxServerErrors :: Lens' OutlierDetection Natural
outlierDetection_maxServerErrors = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OutlierDetection' {Natural
maxServerErrors :: Natural
$sel:maxServerErrors:OutlierDetection' :: OutlierDetection -> Natural
maxServerErrors} -> Natural
maxServerErrors) (\s :: OutlierDetection
s@OutlierDetection' {} Natural
a -> OutlierDetection
s {$sel:maxServerErrors:OutlierDetection' :: Natural
maxServerErrors = Natural
a} :: OutlierDetection)

instance Data.FromJSON OutlierDetection where
  parseJSON :: Value -> Parser OutlierDetection
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"OutlierDetection"
      ( \Object
x ->
          Duration -> Duration -> Natural -> Natural -> OutlierDetection
OutlierDetection'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"baseEjectionDuration")
            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
"interval")
            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
"maxEjectionPercent")
            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
"maxServerErrors")
      )

instance Prelude.Hashable OutlierDetection where
  hashWithSalt :: Int -> OutlierDetection -> Int
hashWithSalt Int
_salt OutlierDetection' {Natural
Duration
maxServerErrors :: Natural
maxEjectionPercent :: Natural
interval :: Duration
baseEjectionDuration :: Duration
$sel:maxServerErrors:OutlierDetection' :: OutlierDetection -> Natural
$sel:maxEjectionPercent:OutlierDetection' :: OutlierDetection -> Natural
$sel:interval:OutlierDetection' :: OutlierDetection -> Duration
$sel:baseEjectionDuration:OutlierDetection' :: OutlierDetection -> Duration
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Duration
baseEjectionDuration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Duration
interval
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
maxEjectionPercent
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
maxServerErrors

instance Prelude.NFData OutlierDetection where
  rnf :: OutlierDetection -> ()
rnf OutlierDetection' {Natural
Duration
maxServerErrors :: Natural
maxEjectionPercent :: Natural
interval :: Duration
baseEjectionDuration :: Duration
$sel:maxServerErrors:OutlierDetection' :: OutlierDetection -> Natural
$sel:maxEjectionPercent:OutlierDetection' :: OutlierDetection -> Natural
$sel:interval:OutlierDetection' :: OutlierDetection -> Duration
$sel:baseEjectionDuration:OutlierDetection' :: OutlierDetection -> Duration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Duration
baseEjectionDuration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Duration
interval
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
maxEjectionPercent
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
maxServerErrors

instance Data.ToJSON OutlierDetection where
  toJSON :: OutlierDetection -> Value
toJSON OutlierDetection' {Natural
Duration
maxServerErrors :: Natural
maxEjectionPercent :: Natural
interval :: Duration
baseEjectionDuration :: Duration
$sel:maxServerErrors:OutlierDetection' :: OutlierDetection -> Natural
$sel:maxEjectionPercent:OutlierDetection' :: OutlierDetection -> Natural
$sel:interval:OutlierDetection' :: OutlierDetection -> Duration
$sel:baseEjectionDuration:OutlierDetection' :: OutlierDetection -> Duration
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              ( Key
"baseEjectionDuration"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Duration
baseEjectionDuration
              ),
            forall a. a -> Maybe a
Prelude.Just (Key
"interval" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Duration
interval),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"maxEjectionPercent" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
maxEjectionPercent),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"maxServerErrors" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
maxServerErrors)
          ]
      )