{-# 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-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.InsightEvent 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
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'
  { -- | 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,
    -- | The time, in Unix seconds, at which the event was recorded.
    InsightEvent -> Maybe POSIX
eventTime :: Prelude.Maybe Data.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,
    -- | A brief description of the event.
    InsightEvent -> Maybe Text
summary :: Prelude.Maybe Prelude.Text,
    -- | The service during the event that is most impacted by the incident.
    InsightEvent -> Maybe [AnomalousService]
topAnomalousServices :: Prelude.Maybe [AnomalousService]
  }
  deriving (InsightEvent -> InsightEvent -> Bool
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]
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
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. 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:
--
-- '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.
--
-- '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.
--
-- 'summary', 'insightEvent_summary' - A brief description of the event.
--
-- 'topAnomalousServices', 'insightEvent_topAnomalousServices' - The service during the event that is most impacted by the incident.
newInsightEvent ::
  InsightEvent
newInsightEvent :: InsightEvent
newInsightEvent =
  InsightEvent'
    { $sel:clientRequestImpactStatistics:InsightEvent' :: Maybe RequestImpactStatistics
clientRequestImpactStatistics =
        forall a. Maybe a
Prelude.Nothing,
      $sel:eventTime:InsightEvent' :: Maybe POSIX
eventTime = forall a. Maybe a
Prelude.Nothing,
      $sel:rootCauseServiceRequestImpactStatistics:InsightEvent' :: Maybe RequestImpactStatistics
rootCauseServiceRequestImpactStatistics =
        forall a. Maybe a
Prelude.Nothing,
      $sel:summary:InsightEvent' :: Maybe Text
summary = forall a. Maybe a
Prelude.Nothing,
      $sel:topAnomalousServices:InsightEvent' :: Maybe [AnomalousService]
topAnomalousServices = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' InsightEvent (Maybe RequestImpactStatistics)
insightEvent_clientRequestImpactStatistics = 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)

-- | The time, in Unix seconds, at which the event was recorded.
insightEvent_eventTime :: Lens.Lens' InsightEvent (Prelude.Maybe Prelude.UTCTime)
insightEvent_eventTime :: Lens' InsightEvent (Maybe UTCTime)
insightEvent_eventTime = 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) 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 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 :: Lens' InsightEvent (Maybe RequestImpactStatistics)
insightEvent_rootCauseServiceRequestImpactStatistics = 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)

-- | A brief description of the event.
insightEvent_summary :: Lens.Lens' InsightEvent (Prelude.Maybe Prelude.Text)
insightEvent_summary :: Lens' InsightEvent (Maybe Text)
insightEvent_summary = 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 service during the event that is most impacted by the incident.
insightEvent_topAnomalousServices :: Lens.Lens' InsightEvent (Prelude.Maybe [AnomalousService])
insightEvent_topAnomalousServices :: Lens' InsightEvent (Maybe [AnomalousService])
insightEvent_topAnomalousServices = 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) 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 s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable InsightEvent where
  hashWithSalt :: Int -> InsightEvent -> Int
hashWithSalt Int
_salt InsightEvent' {Maybe [AnomalousService]
Maybe Text
Maybe POSIX
Maybe RequestImpactStatistics
topAnomalousServices :: Maybe [AnomalousService]
summary :: Maybe Text
rootCauseServiceRequestImpactStatistics :: Maybe RequestImpactStatistics
eventTime :: Maybe POSIX
clientRequestImpactStatistics :: Maybe RequestImpactStatistics
$sel:topAnomalousServices:InsightEvent' :: InsightEvent -> Maybe [AnomalousService]
$sel:summary:InsightEvent' :: InsightEvent -> Maybe Text
$sel:rootCauseServiceRequestImpactStatistics:InsightEvent' :: InsightEvent -> Maybe RequestImpactStatistics
$sel:eventTime:InsightEvent' :: InsightEvent -> Maybe POSIX
$sel:clientRequestImpactStatistics:InsightEvent' :: InsightEvent -> Maybe RequestImpactStatistics
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RequestImpactStatistics
clientRequestImpactStatistics
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
eventTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RequestImpactStatistics
rootCauseServiceRequestImpactStatistics
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
summary
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [AnomalousService]
topAnomalousServices

instance Prelude.NFData InsightEvent where
  rnf :: InsightEvent -> ()
rnf InsightEvent' {Maybe [AnomalousService]
Maybe Text
Maybe POSIX
Maybe RequestImpactStatistics
topAnomalousServices :: Maybe [AnomalousService]
summary :: Maybe Text
rootCauseServiceRequestImpactStatistics :: Maybe RequestImpactStatistics
eventTime :: Maybe POSIX
clientRequestImpactStatistics :: Maybe RequestImpactStatistics
$sel:topAnomalousServices:InsightEvent' :: InsightEvent -> Maybe [AnomalousService]
$sel:summary:InsightEvent' :: InsightEvent -> Maybe Text
$sel:rootCauseServiceRequestImpactStatistics:InsightEvent' :: InsightEvent -> Maybe RequestImpactStatistics
$sel:eventTime:InsightEvent' :: InsightEvent -> Maybe POSIX
$sel:clientRequestImpactStatistics:InsightEvent' :: InsightEvent -> Maybe RequestImpactStatistics
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe RequestImpactStatistics
clientRequestImpactStatistics
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
eventTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe RequestImpactStatistics
rootCauseServiceRequestImpactStatistics
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
summary
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [AnomalousService]
topAnomalousServices