{-# 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.CodeGuruProfiler.Types.Anomaly
-- 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.CodeGuruProfiler.Types.Anomaly where

import Amazonka.CodeGuruProfiler.Types.AnomalyInstance
import Amazonka.CodeGuruProfiler.Types.Metric
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

-- | Details about an anomaly in a specific metric of application profile.
-- The anomaly is detected using analysis of the metric data over a period
-- of time.
--
-- /See:/ 'newAnomaly' smart constructor.
data Anomaly = Anomaly'
  { -- | A list of the instances of the detected anomalies during the requested
    -- period.
    Anomaly -> [AnomalyInstance]
instances :: [AnomalyInstance],
    -- | Details about the metric that the analysis used when it detected the
    -- anomaly. The metric includes the name of the frame that was analyzed
    -- with the type and thread states used to derive the metric value for that
    -- frame.
    Anomaly -> Metric
metric :: Metric,
    -- | The reason for which metric was flagged as anomalous.
    Anomaly -> Text
reason :: Prelude.Text
  }
  deriving (Anomaly -> Anomaly -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Anomaly -> Anomaly -> Bool
$c/= :: Anomaly -> Anomaly -> Bool
== :: Anomaly -> Anomaly -> Bool
$c== :: Anomaly -> Anomaly -> Bool
Prelude.Eq, ReadPrec [Anomaly]
ReadPrec Anomaly
Int -> ReadS Anomaly
ReadS [Anomaly]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Anomaly]
$creadListPrec :: ReadPrec [Anomaly]
readPrec :: ReadPrec Anomaly
$creadPrec :: ReadPrec Anomaly
readList :: ReadS [Anomaly]
$creadList :: ReadS [Anomaly]
readsPrec :: Int -> ReadS Anomaly
$creadsPrec :: Int -> ReadS Anomaly
Prelude.Read, Int -> Anomaly -> ShowS
[Anomaly] -> ShowS
Anomaly -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Anomaly] -> ShowS
$cshowList :: [Anomaly] -> ShowS
show :: Anomaly -> String
$cshow :: Anomaly -> String
showsPrec :: Int -> Anomaly -> ShowS
$cshowsPrec :: Int -> Anomaly -> ShowS
Prelude.Show, forall x. Rep Anomaly x -> Anomaly
forall x. Anomaly -> Rep Anomaly x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Anomaly x -> Anomaly
$cfrom :: forall x. Anomaly -> Rep Anomaly x
Prelude.Generic)

-- |
-- Create a value of 'Anomaly' 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:
--
-- 'instances', 'anomaly_instances' - A list of the instances of the detected anomalies during the requested
-- period.
--
-- 'metric', 'anomaly_metric' - Details about the metric that the analysis used when it detected the
-- anomaly. The metric includes the name of the frame that was analyzed
-- with the type and thread states used to derive the metric value for that
-- frame.
--
-- 'reason', 'anomaly_reason' - The reason for which metric was flagged as anomalous.
newAnomaly ::
  -- | 'metric'
  Metric ->
  -- | 'reason'
  Prelude.Text ->
  Anomaly
newAnomaly :: Metric -> Text -> Anomaly
newAnomaly Metric
pMetric_ Text
pReason_ =
  Anomaly'
    { $sel:instances:Anomaly' :: [AnomalyInstance]
instances = forall a. Monoid a => a
Prelude.mempty,
      $sel:metric:Anomaly' :: Metric
metric = Metric
pMetric_,
      $sel:reason:Anomaly' :: Text
reason = Text
pReason_
    }

-- | A list of the instances of the detected anomalies during the requested
-- period.
anomaly_instances :: Lens.Lens' Anomaly [AnomalyInstance]
anomaly_instances :: Lens' Anomaly [AnomalyInstance]
anomaly_instances = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {[AnomalyInstance]
instances :: [AnomalyInstance]
$sel:instances:Anomaly' :: Anomaly -> [AnomalyInstance]
instances} -> [AnomalyInstance]
instances) (\s :: Anomaly
s@Anomaly' {} [AnomalyInstance]
a -> Anomaly
s {$sel:instances:Anomaly' :: [AnomalyInstance]
instances = [AnomalyInstance]
a} :: Anomaly) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Details about the metric that the analysis used when it detected the
-- anomaly. The metric includes the name of the frame that was analyzed
-- with the type and thread states used to derive the metric value for that
-- frame.
anomaly_metric :: Lens.Lens' Anomaly Metric
anomaly_metric :: Lens' Anomaly Metric
anomaly_metric = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {Metric
metric :: Metric
$sel:metric:Anomaly' :: Anomaly -> Metric
metric} -> Metric
metric) (\s :: Anomaly
s@Anomaly' {} Metric
a -> Anomaly
s {$sel:metric:Anomaly' :: Metric
metric = Metric
a} :: Anomaly)

-- | The reason for which metric was flagged as anomalous.
anomaly_reason :: Lens.Lens' Anomaly Prelude.Text
anomaly_reason :: Lens' Anomaly Text
anomaly_reason = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {Text
reason :: Text
$sel:reason:Anomaly' :: Anomaly -> Text
reason} -> Text
reason) (\s :: Anomaly
s@Anomaly' {} Text
a -> Anomaly
s {$sel:reason:Anomaly' :: Text
reason = Text
a} :: Anomaly)

instance Data.FromJSON Anomaly where
  parseJSON :: Value -> Parser Anomaly
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Anomaly"
      ( \Object
x ->
          [AnomalyInstance] -> Metric -> Text -> Anomaly
Anomaly'
            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
"instances" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"metric")
            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
"reason")
      )

instance Prelude.Hashable Anomaly where
  hashWithSalt :: Int -> Anomaly -> Int
hashWithSalt Int
_salt Anomaly' {[AnomalyInstance]
Text
Metric
reason :: Text
metric :: Metric
instances :: [AnomalyInstance]
$sel:reason:Anomaly' :: Anomaly -> Text
$sel:metric:Anomaly' :: Anomaly -> Metric
$sel:instances:Anomaly' :: Anomaly -> [AnomalyInstance]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [AnomalyInstance]
instances
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Metric
metric
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
reason

instance Prelude.NFData Anomaly where
  rnf :: Anomaly -> ()
rnf Anomaly' {[AnomalyInstance]
Text
Metric
reason :: Text
metric :: Metric
instances :: [AnomalyInstance]
$sel:reason:Anomaly' :: Anomaly -> Text
$sel:metric:Anomaly' :: Anomaly -> Metric
$sel:instances:Anomaly' :: Anomaly -> [AnomalyInstance]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf [AnomalyInstance]
instances
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Metric
metric
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
reason