{-# 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.InsightEvent
-- 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.InsightEvent where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.XRay.Types.AnomalousService
import Amazonka.XRay.Types.RequestImpactStatistics

-- | X-Ray reevaluates insights periodically until they are resolved, and
-- records each intermediate state in an event. You can review incident
-- events in the Impact Timeline on the Inspect page in the X-Ray console.
--
-- /See:/ 'newInsightEvent' smart constructor.
data InsightEvent = InsightEvent'
  { -- | A brief description of the event.
    InsightEvent -> Maybe Text
summary :: Prelude.Maybe Prelude.Text,
    -- | The time, in Unix seconds, at which the event was recorded.
    InsightEvent -> Maybe POSIX
eventTime :: Prelude.Maybe Core.POSIX,
    -- | The impact statistics of the root cause service. This includes the
    -- number of requests to the client service and whether the requests were
    -- faults or okay.
    InsightEvent -> Maybe RequestImpactStatistics
rootCauseServiceRequestImpactStatistics :: Prelude.Maybe RequestImpactStatistics,
    -- | The service during the event that is most impacted by the incident.
    InsightEvent -> Maybe [AnomalousService]
topAnomalousServices :: Prelude.Maybe [AnomalousService],
    -- | The impact statistics of the client side service. This includes the
    -- number of requests to the client service and whether the requests were
    -- faults or okay.
    InsightEvent -> Maybe RequestImpactStatistics
clientRequestImpactStatistics :: Prelude.Maybe RequestImpactStatistics
  }
  deriving (InsightEvent -> InsightEvent -> Bool
(InsightEvent -> InsightEvent -> Bool)
-> (InsightEvent -> InsightEvent -> Bool) -> Eq InsightEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InsightEvent -> InsightEvent -> Bool
$c/= :: InsightEvent -> InsightEvent -> Bool
== :: InsightEvent -> InsightEvent -> Bool
$c== :: InsightEvent -> InsightEvent -> Bool
Prelude.Eq, ReadPrec [InsightEvent]
ReadPrec InsightEvent
Int -> ReadS InsightEvent
ReadS [InsightEvent]
(Int -> ReadS InsightEvent)
-> ReadS [InsightEvent]
-> ReadPrec InsightEvent
-> ReadPrec [InsightEvent]
-> Read InsightEvent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InsightEvent]
$creadListPrec :: ReadPrec [InsightEvent]
readPrec :: ReadPrec InsightEvent
$creadPrec :: ReadPrec InsightEvent
readList :: ReadS [InsightEvent]
$creadList :: ReadS [InsightEvent]
readsPrec :: Int -> ReadS InsightEvent
$creadsPrec :: Int -> ReadS InsightEvent
Prelude.Read, Int -> InsightEvent -> ShowS
[InsightEvent] -> ShowS
InsightEvent -> String
(Int -> InsightEvent -> ShowS)
-> (InsightEvent -> String)
-> ([InsightEvent] -> ShowS)
-> Show InsightEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InsightEvent] -> ShowS
$cshowList :: [InsightEvent] -> ShowS
show :: InsightEvent -> String
$cshow :: InsightEvent -> String
showsPrec :: Int -> InsightEvent -> ShowS
$cshowsPrec :: Int -> InsightEvent -> ShowS
Prelude.Show, (forall x. InsightEvent -> Rep InsightEvent x)
-> (forall x. Rep InsightEvent x -> InsightEvent)
-> Generic InsightEvent
forall x. Rep InsightEvent x -> InsightEvent
forall x. InsightEvent -> Rep InsightEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InsightEvent x -> InsightEvent
$cfrom :: forall x. InsightEvent -> Rep InsightEvent x
Prelude.Generic)

-- |
-- Create a value of 'InsightEvent' 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:
--
-- 'summary', 'insightEvent_summary' - A brief description of the event.
--
-- 'eventTime', 'insightEvent_eventTime' - The time, in Unix seconds, at which the event was recorded.
--
-- 'rootCauseServiceRequestImpactStatistics', 'insightEvent_rootCauseServiceRequestImpactStatistics' - The impact statistics of the root cause service. This includes the
-- number of requests to the client service and whether the requests were
-- faults or okay.
--
-- 'topAnomalousServices', 'insightEvent_topAnomalousServices' - The service during the event that is most impacted by the incident.
--
-- 'clientRequestImpactStatistics', 'insightEvent_clientRequestImpactStatistics' - The impact statistics of the client side service. This includes the
-- number of requests to the client service and whether the requests were
-- faults or okay.
newInsightEvent ::
  InsightEvent
newInsightEvent :: InsightEvent
newInsightEvent =
  InsightEvent' :: Maybe Text
-> Maybe POSIX
-> Maybe RequestImpactStatistics
-> Maybe [AnomalousService]
-> Maybe RequestImpactStatistics
-> InsightEvent
InsightEvent'
    { $sel:summary:InsightEvent' :: Maybe Text
summary = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventTime:InsightEvent' :: Maybe POSIX
eventTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:rootCauseServiceRequestImpactStatistics:InsightEvent' :: Maybe RequestImpactStatistics
rootCauseServiceRequestImpactStatistics =
        Maybe RequestImpactStatistics
forall a. Maybe a
Prelude.Nothing,
      $sel:topAnomalousServices:InsightEvent' :: Maybe [AnomalousService]
topAnomalousServices = Maybe [AnomalousService]
forall a. Maybe a
Prelude.Nothing,
      $sel:clientRequestImpactStatistics:InsightEvent' :: Maybe RequestImpactStatistics
clientRequestImpactStatistics = Maybe RequestImpactStatistics
forall a. Maybe a
Prelude.Nothing
    }

-- | A brief description of the event.
insightEvent_summary :: Lens.Lens' InsightEvent (Prelude.Maybe Prelude.Text)
insightEvent_summary :: (Maybe Text -> f (Maybe Text)) -> InsightEvent -> f InsightEvent
insightEvent_summary = (InsightEvent -> Maybe Text)
-> (InsightEvent -> Maybe Text -> InsightEvent)
-> Lens InsightEvent InsightEvent (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightEvent' {Maybe Text
summary :: Maybe Text
$sel:summary:InsightEvent' :: InsightEvent -> Maybe Text
summary} -> Maybe Text
summary) (\s :: InsightEvent
s@InsightEvent' {} Maybe Text
a -> InsightEvent
s {$sel:summary:InsightEvent' :: Maybe Text
summary = Maybe Text
a} :: InsightEvent)

-- | The time, in Unix seconds, at which the event was recorded.
insightEvent_eventTime :: Lens.Lens' InsightEvent (Prelude.Maybe Prelude.UTCTime)
insightEvent_eventTime :: (Maybe UTCTime -> f (Maybe UTCTime))
-> InsightEvent -> f InsightEvent
insightEvent_eventTime = (InsightEvent -> Maybe POSIX)
-> (InsightEvent -> Maybe POSIX -> InsightEvent)
-> Lens InsightEvent InsightEvent (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightEvent' {Maybe POSIX
eventTime :: Maybe POSIX
$sel:eventTime:InsightEvent' :: InsightEvent -> Maybe POSIX
eventTime} -> Maybe POSIX
eventTime) (\s :: InsightEvent
s@InsightEvent' {} Maybe POSIX
a -> InsightEvent
s {$sel:eventTime:InsightEvent' :: Maybe POSIX
eventTime = Maybe POSIX
a} :: InsightEvent) ((Maybe POSIX -> f (Maybe POSIX))
 -> InsightEvent -> f InsightEvent)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> InsightEvent
-> f InsightEvent
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

-- | The impact statistics of the root cause service. This includes the
-- number of requests to the client service and whether the requests were
-- faults or okay.
insightEvent_rootCauseServiceRequestImpactStatistics :: Lens.Lens' InsightEvent (Prelude.Maybe RequestImpactStatistics)
insightEvent_rootCauseServiceRequestImpactStatistics :: (Maybe RequestImpactStatistics
 -> f (Maybe RequestImpactStatistics))
-> InsightEvent -> f InsightEvent
insightEvent_rootCauseServiceRequestImpactStatistics = (InsightEvent -> Maybe RequestImpactStatistics)
-> (InsightEvent -> Maybe RequestImpactStatistics -> InsightEvent)
-> Lens
     InsightEvent
     InsightEvent
     (Maybe RequestImpactStatistics)
     (Maybe RequestImpactStatistics)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightEvent' {Maybe RequestImpactStatistics
rootCauseServiceRequestImpactStatistics :: Maybe RequestImpactStatistics
$sel:rootCauseServiceRequestImpactStatistics:InsightEvent' :: InsightEvent -> Maybe RequestImpactStatistics
rootCauseServiceRequestImpactStatistics} -> Maybe RequestImpactStatistics
rootCauseServiceRequestImpactStatistics) (\s :: InsightEvent
s@InsightEvent' {} Maybe RequestImpactStatistics
a -> InsightEvent
s {$sel:rootCauseServiceRequestImpactStatistics:InsightEvent' :: Maybe RequestImpactStatistics
rootCauseServiceRequestImpactStatistics = Maybe RequestImpactStatistics
a} :: InsightEvent)

-- | The service during the event that is most impacted by the incident.
insightEvent_topAnomalousServices :: Lens.Lens' InsightEvent (Prelude.Maybe [AnomalousService])
insightEvent_topAnomalousServices :: (Maybe [AnomalousService] -> f (Maybe [AnomalousService]))
-> InsightEvent -> f InsightEvent
insightEvent_topAnomalousServices = (InsightEvent -> Maybe [AnomalousService])
-> (InsightEvent -> Maybe [AnomalousService] -> InsightEvent)
-> Lens
     InsightEvent
     InsightEvent
     (Maybe [AnomalousService])
     (Maybe [AnomalousService])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightEvent' {Maybe [AnomalousService]
topAnomalousServices :: Maybe [AnomalousService]
$sel:topAnomalousServices:InsightEvent' :: InsightEvent -> Maybe [AnomalousService]
topAnomalousServices} -> Maybe [AnomalousService]
topAnomalousServices) (\s :: InsightEvent
s@InsightEvent' {} Maybe [AnomalousService]
a -> InsightEvent
s {$sel:topAnomalousServices:InsightEvent' :: Maybe [AnomalousService]
topAnomalousServices = Maybe [AnomalousService]
a} :: InsightEvent) ((Maybe [AnomalousService] -> f (Maybe [AnomalousService]))
 -> InsightEvent -> f InsightEvent)
-> ((Maybe [AnomalousService] -> f (Maybe [AnomalousService]))
    -> Maybe [AnomalousService] -> f (Maybe [AnomalousService]))
-> (Maybe [AnomalousService] -> f (Maybe [AnomalousService]))
-> InsightEvent
-> f InsightEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [AnomalousService]
  [AnomalousService]
  [AnomalousService]
  [AnomalousService]
-> Iso
     (Maybe [AnomalousService])
     (Maybe [AnomalousService])
     (Maybe [AnomalousService])
     (Maybe [AnomalousService])
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
  [AnomalousService]
  [AnomalousService]
  [AnomalousService]
  [AnomalousService]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The impact statistics of the client side service. This includes the
-- number of requests to the client service and whether the requests were
-- faults or okay.
insightEvent_clientRequestImpactStatistics :: Lens.Lens' InsightEvent (Prelude.Maybe RequestImpactStatistics)
insightEvent_clientRequestImpactStatistics :: (Maybe RequestImpactStatistics
 -> f (Maybe RequestImpactStatistics))
-> InsightEvent -> f InsightEvent
insightEvent_clientRequestImpactStatistics = (InsightEvent -> Maybe RequestImpactStatistics)
-> (InsightEvent -> Maybe RequestImpactStatistics -> InsightEvent)
-> Lens
     InsightEvent
     InsightEvent
     (Maybe RequestImpactStatistics)
     (Maybe RequestImpactStatistics)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightEvent' {Maybe RequestImpactStatistics
clientRequestImpactStatistics :: Maybe RequestImpactStatistics
$sel:clientRequestImpactStatistics:InsightEvent' :: InsightEvent -> Maybe RequestImpactStatistics
clientRequestImpactStatistics} -> Maybe RequestImpactStatistics
clientRequestImpactStatistics) (\s :: InsightEvent
s@InsightEvent' {} Maybe RequestImpactStatistics
a -> InsightEvent
s {$sel:clientRequestImpactStatistics:InsightEvent' :: Maybe RequestImpactStatistics
clientRequestImpactStatistics = Maybe RequestImpactStatistics
a} :: InsightEvent)

instance Core.FromJSON InsightEvent where
  parseJSON :: Value -> Parser InsightEvent
parseJSON =
    String
-> (Object -> Parser InsightEvent) -> Value -> Parser InsightEvent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InsightEvent"
      ( \Object
x ->
          Maybe Text
-> Maybe POSIX
-> Maybe RequestImpactStatistics
-> Maybe [AnomalousService]
-> Maybe RequestImpactStatistics
-> InsightEvent
InsightEvent'
            (Maybe Text
 -> Maybe POSIX
 -> Maybe RequestImpactStatistics
 -> Maybe [AnomalousService]
 -> Maybe RequestImpactStatistics
 -> InsightEvent)
-> Parser (Maybe Text)
-> Parser
     (Maybe POSIX
      -> Maybe RequestImpactStatistics
      -> Maybe [AnomalousService]
      -> Maybe RequestImpactStatistics
      -> InsightEvent)
forall (f :: * -> *) a b. Functor 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
"Summary")
            Parser
  (Maybe POSIX
   -> Maybe RequestImpactStatistics
   -> Maybe [AnomalousService]
   -> Maybe RequestImpactStatistics
   -> InsightEvent)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe RequestImpactStatistics
      -> Maybe [AnomalousService]
      -> Maybe RequestImpactStatistics
      -> InsightEvent)
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
"EventTime")
            Parser
  (Maybe RequestImpactStatistics
   -> Maybe [AnomalousService]
   -> Maybe RequestImpactStatistics
   -> InsightEvent)
-> Parser (Maybe RequestImpactStatistics)
-> Parser
     (Maybe [AnomalousService]
      -> Maybe RequestImpactStatistics -> InsightEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            Object -> Text -> Parser (Maybe RequestImpactStatistics)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RootCauseServiceRequestImpactStatistics"
                        )
            Parser
  (Maybe [AnomalousService]
   -> Maybe RequestImpactStatistics -> InsightEvent)
-> Parser (Maybe [AnomalousService])
-> Parser (Maybe RequestImpactStatistics -> InsightEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [AnomalousService]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TopAnomalousServices"
                            Parser (Maybe (Maybe [AnomalousService]))
-> Maybe [AnomalousService] -> Parser (Maybe [AnomalousService])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [AnomalousService]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe RequestImpactStatistics -> InsightEvent)
-> Parser (Maybe RequestImpactStatistics) -> Parser InsightEvent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe RequestImpactStatistics)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ClientRequestImpactStatistics")
      )

instance Prelude.Hashable InsightEvent

instance Prelude.NFData InsightEvent