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

import Amazonka.CodeGuruProfiler.Types.AnomalyInstance
import Amazonka.CodeGuruProfiler.Types.Metric
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(Anomaly -> Anomaly -> Bool)
-> (Anomaly -> Anomaly -> Bool) -> Eq Anomaly
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]
(Int -> ReadS Anomaly)
-> ReadS [Anomaly]
-> ReadPrec Anomaly
-> ReadPrec [Anomaly]
-> Read 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
(Int -> Anomaly -> ShowS)
-> (Anomaly -> String) -> ([Anomaly] -> ShowS) -> Show Anomaly
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. Anomaly -> Rep Anomaly x)
-> (forall x. Rep Anomaly x -> Anomaly) -> Generic Anomaly
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' :: [AnomalyInstance] -> Metric -> Text -> Anomaly
Anomaly'
    { $sel:instances:Anomaly' :: [AnomalyInstance]
instances = [AnomalyInstance]
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 :: ([AnomalyInstance] -> f [AnomalyInstance]) -> Anomaly -> f Anomaly
anomaly_instances = (Anomaly -> [AnomalyInstance])
-> (Anomaly -> [AnomalyInstance] -> Anomaly)
-> Lens Anomaly Anomaly [AnomalyInstance] [AnomalyInstance]
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) (([AnomalyInstance] -> f [AnomalyInstance])
 -> Anomaly -> f Anomaly)
-> (([AnomalyInstance] -> f [AnomalyInstance])
    -> [AnomalyInstance] -> f [AnomalyInstance])
-> ([AnomalyInstance] -> f [AnomalyInstance])
-> Anomaly
-> f Anomaly
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([AnomalyInstance] -> f [AnomalyInstance])
-> [AnomalyInstance] -> f [AnomalyInstance]
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 :: (Metric -> f Metric) -> Anomaly -> f Anomaly
anomaly_metric = (Anomaly -> Metric)
-> (Anomaly -> Metric -> Anomaly)
-> Lens Anomaly Anomaly Metric 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 :: (Text -> f Text) -> Anomaly -> f Anomaly
anomaly_reason = (Anomaly -> Text)
-> (Anomaly -> Text -> Anomaly) -> Lens Anomaly Anomaly Text Text
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 Core.FromJSON Anomaly where
  parseJSON :: Value -> Parser Anomaly
parseJSON =
    String -> (Object -> Parser Anomaly) -> Value -> Parser Anomaly
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Anomaly"
      ( \Object
x ->
          [AnomalyInstance] -> Metric -> Text -> Anomaly
Anomaly'
            ([AnomalyInstance] -> Metric -> Text -> Anomaly)
-> Parser [AnomalyInstance] -> Parser (Metric -> Text -> Anomaly)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe [AnomalyInstance])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"instances" Parser (Maybe [AnomalyInstance])
-> [AnomalyInstance] -> Parser [AnomalyInstance]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [AnomalyInstance]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Metric -> Text -> Anomaly)
-> Parser Metric -> Parser (Text -> Anomaly)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Metric
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"metric")
            Parser (Text -> Anomaly) -> Parser Text -> Parser Anomaly
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"reason")
      )

instance Prelude.Hashable Anomaly

instance Prelude.NFData Anomaly