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

import Amazonka.AppMesh.Types.Duration
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(OutlierDetection -> OutlierDetection -> Bool)
-> (OutlierDetection -> OutlierDetection -> Bool)
-> Eq OutlierDetection
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]
(Int -> ReadS OutlierDetection)
-> ReadS [OutlierDetection]
-> ReadPrec OutlierDetection
-> ReadPrec [OutlierDetection]
-> Read 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
(Int -> OutlierDetection -> ShowS)
-> (OutlierDetection -> String)
-> ([OutlierDetection] -> ShowS)
-> Show OutlierDetection
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. OutlierDetection -> Rep OutlierDetection x)
-> (forall x. Rep OutlierDetection x -> OutlierDetection)
-> Generic OutlierDetection
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' :: Duration -> Duration -> Natural -> Natural -> OutlierDetection
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 :: (Duration -> f Duration) -> OutlierDetection -> f OutlierDetection
outlierDetection_baseEjectionDuration = (OutlierDetection -> Duration)
-> (OutlierDetection -> Duration -> OutlierDetection)
-> Lens OutlierDetection OutlierDetection Duration Duration
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 :: (Duration -> f Duration) -> OutlierDetection -> f OutlierDetection
outlierDetection_interval = (OutlierDetection -> Duration)
-> (OutlierDetection -> Duration -> OutlierDetection)
-> Lens OutlierDetection OutlierDetection Duration Duration
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 :: (Natural -> f Natural) -> OutlierDetection -> f OutlierDetection
outlierDetection_maxEjectionPercent = (OutlierDetection -> Natural)
-> (OutlierDetection -> Natural -> OutlierDetection)
-> Lens OutlierDetection OutlierDetection Natural Natural
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 :: (Natural -> f Natural) -> OutlierDetection -> f OutlierDetection
outlierDetection_maxServerErrors = (OutlierDetection -> Natural)
-> (OutlierDetection -> Natural -> OutlierDetection)
-> Lens OutlierDetection OutlierDetection Natural Natural
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 Core.FromJSON OutlierDetection where
  parseJSON :: Value -> Parser OutlierDetection
parseJSON =
    String
-> (Object -> Parser OutlierDetection)
-> Value
-> Parser OutlierDetection
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OutlierDetection"
      ( \Object
x ->
          Duration -> Duration -> Natural -> Natural -> OutlierDetection
OutlierDetection'
            (Duration -> Duration -> Natural -> Natural -> OutlierDetection)
-> Parser Duration
-> Parser (Duration -> Natural -> Natural -> OutlierDetection)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Duration
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"baseEjectionDuration")
            Parser (Duration -> Natural -> Natural -> OutlierDetection)
-> Parser Duration
-> Parser (Natural -> Natural -> OutlierDetection)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Duration
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"interval")
            Parser (Natural -> Natural -> OutlierDetection)
-> Parser Natural -> Parser (Natural -> OutlierDetection)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"maxEjectionPercent")
            Parser (Natural -> OutlierDetection)
-> Parser Natural -> Parser OutlierDetection
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"maxServerErrors")
      )

instance Prelude.Hashable OutlierDetection

instance Prelude.NFData OutlierDetection

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"baseEjectionDuration"
                  Text -> Duration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Duration
baseEjectionDuration
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"interval" Text -> Duration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Duration
interval),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"maxEjectionPercent" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
maxEjectionPercent),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"maxServerErrors" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
maxServerErrors)
          ]
      )