module Cardano.Logging.TraceDispatcherMessage
(
UnknownNamespaceKind (..)
, TraceDispatcherMessage (..)
) where
import Cardano.Logging.ConfigurationParser ()
import Cardano.Logging.Types
import Data.Aeson hiding (Error)
import Data.ByteString.Lazy (toStrict)
import qualified Data.Map as Map
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
data UnknownNamespaceKind =
UKFSeverity
| UKFPrivacy
| UKFDetails
instance Show UnknownNamespaceKind where
show :: UnknownNamespaceKind -> String
show UnknownNamespaceKind
UKFSeverity = String
"severity"
show UnknownNamespaceKind
UKFPrivacy = String
"privacy"
show UnknownNamespaceKind
UKFDetails = String
"details"
data TraceDispatcherMessage =
StartLimiting Text
| StopLimiting Text Int
| RememberLimiting Text Int
| UnknownNamespace [Text] [Text] UnknownNamespaceKind
| TracerInfo [Text] [Text] [Text]
| MetricsInfo (Map.Map Text Int)
| TracerConsistencyWarnings [Text]
| TracerInfoConfig TraceConfig
deriving Int -> TraceDispatcherMessage -> ShowS
[TraceDispatcherMessage] -> ShowS
TraceDispatcherMessage -> String
(Int -> TraceDispatcherMessage -> ShowS)
-> (TraceDispatcherMessage -> String)
-> ([TraceDispatcherMessage] -> ShowS)
-> Show TraceDispatcherMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TraceDispatcherMessage -> ShowS
showsPrec :: Int -> TraceDispatcherMessage -> ShowS
$cshow :: TraceDispatcherMessage -> String
show :: TraceDispatcherMessage -> String
$cshowList :: [TraceDispatcherMessage] -> ShowS
showList :: [TraceDispatcherMessage] -> ShowS
Show
instance LogFormatting TraceDispatcherMessage where
forHuman :: TraceDispatcherMessage -> Text
forHuman (StartLimiting Text
txt) = Text
"Start of frequency limiting for " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
txt
forHuman (StopLimiting Text
txt Int
num) = Text
"Stop of frequency limiting for " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
". Suppressed " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
textShow Int
num Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" messages."
forHuman (RememberLimiting Text
txt Int
num) = Text
"Frequency limiting still active for " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
". Suppressed so far " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
textShow Int
num Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" messages."
forHuman (UnknownNamespace [Text]
nsPrefixNS [Text]
nsInnerNS UnknownNamespaceKind
qk) = Text
"Unknown namespace detected "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
Text.intercalate (Char -> Text
Text.singleton Char
'.') ([Text]
nsPrefixNS [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text]
nsInnerNS)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
". Used for querying " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> UnknownNamespaceKind -> Text
forall a. Show a => a -> Text
textShow UnknownNamespaceKind
qk Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"."
forHuman (TracerInfo [Text]
silent [Text]
noMetrics [Text]
allTracers) = Text
"The tracing system has silent the following tracer,"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" as they will never have any output according to the current config: "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
Text.intercalate (Char -> Text
Text.singleton Char
' ') [Text]
silent Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
". The following tracers will not emit metrics "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
Text.intercalate (Char -> Text
Text.singleton Char
' ') [Text]
noMetrics Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
". Here is a complete list of all tracers: "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
Text.intercalate (Char -> Text
Text.singleton Char
' ') [Text]
allTracers Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"."
forHuman (MetricsInfo Map Text Int
mmap) = Text
"Number of metrics delivered, " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Map Text Int -> Text
forall a. Show a => a -> Text
textShow Map Text Int
mmap
forHuman (TracerConsistencyWarnings [Text]
errs) = Text
"Consistency check found warnings: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
forall a. Show a => a -> Text
textShow [Text]
errs
forHuman (TracerInfoConfig TraceConfig
tc) = Text
"Effective Tracer config is: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ByteString -> Text
Text.decodeUtf8 (ByteString -> ByteString
toStrict (TraceConfig -> ByteString
forall a. ToJSON a => a -> ByteString
encode TraceConfig
tc))
forMachine :: DetailLevel -> TraceDispatcherMessage -> Object
forMachine DetailLevel
_dtl StartLimiting {} = [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat
[ Key
"kind" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"StartLimiting"
]
forMachine DetailLevel
_dtl (StopLimiting Text
_txt Int
num) = [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat
[ Key
"kind" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"StopLimiting"
, Key
"numSuppressed" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Scientific -> Value
Number (Int -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
num)
]
forMachine DetailLevel
_dtl (RememberLimiting Text
_txt Int
num) = [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat
[ Key
"kind" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"RememberLimiting"
, Key
"numSuppressed" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Scientific -> Value
Number (Int -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
num)
]
forMachine DetailLevel
_dtl (UnknownNamespace [Text]
nsun [Text]
nsleg UnknownNamespaceKind
query) = [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat
[ Key
"kind" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"UnknownNamespace"
, Key
"unknownNamespace" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (Text -> [Text] -> Text
Text.intercalate (Char -> Text
Text.singleton Char
'.') [Text]
nsun)
, Key
"legalNamespace" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (Text -> [Text] -> Text
Text.intercalate (Char -> Text
Text.singleton Char
'.') [Text]
nsleg)
, Key
"querying" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (UnknownNamespaceKind -> Text
forall a. Show a => a -> Text
textShow UnknownNamespaceKind
query)
]
forMachine DetailLevel
_dtl (TracerInfo [Text]
silent [Text]
noMetrics [Text]
allTracers) = [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat
[ Key
"kind" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"TracerMeta"
, Key
"silentTracers" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (Text -> [Text] -> Text
Text.intercalate (Char -> Text
Text.singleton Char
' ') [Text]
silent)
, Key
"noMetrics" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (Text -> [Text] -> Text
Text.intercalate (Char -> Text
Text.singleton Char
' ') [Text]
noMetrics)
, Key
"allTracers" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (Text -> [Text] -> Text
Text.intercalate (Char -> Text
Text.singleton Char
' ') [Text]
allTracers)
]
forMachine DetailLevel
_dtl (MetricsInfo Map Text Int
mmap) = [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat
[ Key
"kind" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"MetricsInfo"
, Key
"metrics count" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (Map Text Int -> Text
forall a. Show a => a -> Text
textShow Map Text Int
mmap)
]
forMachine DetailLevel
_dtl (TracerConsistencyWarnings [Text]
errs) = [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat
[ Key
"kind" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"TracerConsistencyWarnings"
, Key
"errors" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String ([Text] -> Text
forall a. Show a => a -> Text
textShow [Text]
errs)
]
forMachine DetailLevel
_dtl (TracerInfoConfig TraceConfig
tc) = [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat
[ Key
"conf" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TraceConfig -> Value
forall a. ToJSON a => a -> Value
toJSON TraceConfig
tc
]
asMetrics :: TraceDispatcherMessage -> [Metric]
asMetrics StartLimiting {} = []
asMetrics (StopLimiting Text
txt Int
num) = [Text -> Integer -> Metric
IntM
(Text
"SuppressedMessages " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
txt)
(Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
num)]
asMetrics RememberLimiting {} = []
asMetrics UnknownNamespace {} = []
asMetrics TracerInfo {} = []
asMetrics MetricsInfo {} = []
asMetrics TracerConsistencyWarnings {} = []
asMetrics TracerInfoConfig {} = []
internalRestriction :: Text
internalRestriction :: Text
internalRestriction = Text
"\nThis internal message can't be filtered by the current configuration"
instance MetaTrace TraceDispatcherMessage where
namespaceFor :: TraceDispatcherMessage -> Namespace TraceDispatcherMessage
namespaceFor StartLimiting {} = [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"StartLimiting"]
namespaceFor StopLimiting {} = [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"StopLimiting"]
namespaceFor RememberLimiting {} = [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"RememberLimiting"]
namespaceFor UnknownNamespace {} = [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"UnknownNamespace"]
namespaceFor TracerInfo {} = [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"TracerInfo"]
namespaceFor MetricsInfo {} = [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"MetricsInfo"]
namespaceFor TracerConsistencyWarnings {} = [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"TracerConsistencyWarnings"]
namespaceFor TracerInfoConfig {} = [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"TracerConfigInfo"]
severityFor :: Namespace TraceDispatcherMessage
-> Maybe TraceDispatcherMessage -> Maybe SeverityS
severityFor (Namespace [Text]
_ [Text
"StartLimiting"]) Maybe TraceDispatcherMessage
_ = SeverityS -> Maybe SeverityS
forall a. a -> Maybe a
Just SeverityS
Notice
severityFor (Namespace [Text]
_ [Text
"StopLimiting"]) Maybe TraceDispatcherMessage
_ = SeverityS -> Maybe SeverityS
forall a. a -> Maybe a
Just SeverityS
Notice
severityFor (Namespace [Text]
_ [Text
"RememberLimiting"]) Maybe TraceDispatcherMessage
_ = SeverityS -> Maybe SeverityS
forall a. a -> Maybe a
Just SeverityS
Notice
severityFor (Namespace [Text]
_ [Text
"UnknownNamespace"]) Maybe TraceDispatcherMessage
_ = SeverityS -> Maybe SeverityS
forall a. a -> Maybe a
Just SeverityS
Error
severityFor (Namespace [Text]
_ [Text
"TracerInfo"]) Maybe TraceDispatcherMessage
_ = SeverityS -> Maybe SeverityS
forall a. a -> Maybe a
Just SeverityS
Notice
severityFor (Namespace [Text]
_ [Text
"MetricsInfo"]) Maybe TraceDispatcherMessage
_ = SeverityS -> Maybe SeverityS
forall a. a -> Maybe a
Just SeverityS
Debug
severityFor (Namespace [Text]
_ [Text
"TracerConsistencyWarnings"]) Maybe TraceDispatcherMessage
_ = SeverityS -> Maybe SeverityS
forall a. a -> Maybe a
Just SeverityS
Warning
severityFor (Namespace [Text]
_ [Text
"TracerConfigInfo"]) Maybe TraceDispatcherMessage
_ = SeverityS -> Maybe SeverityS
forall a. a -> Maybe a
Just SeverityS
Notice
severityFor Namespace TraceDispatcherMessage
_ Maybe TraceDispatcherMessage
_ = Maybe SeverityS
forall a. Maybe a
Nothing
documentFor :: Namespace TraceDispatcherMessage -> Maybe Text
documentFor (Namespace [Text]
_ [Text
"StartLimiting"]) = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$
Text
"This message indicates the start of frequency limiting" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
internalRestriction
documentFor (Namespace [Text]
_ [Text
"StopLimiting"]) = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ Text
"This message indicates the stop of frequency limiting,"
, Text
" and gives the number of messages that has been suppressed"
] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
internalRestriction
documentFor (Namespace [Text]
_ [Text
"RememberLimiting"]) = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ Text
"^ This message remembers of ongoing frequency limiting,"
, Text
" and gives the number of messages that has been suppressed"
] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
internalRestriction
documentFor (Namespace [Text]
_ [Text
"UnknownNamespace"]) = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ Text
"A value was queried for a namespaces from a tracer,"
, Text
"which is unknown. This indicates a bug in the tracer implementation."
] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
internalRestriction
documentFor (Namespace [Text]
_ [Text
"TracerInfo"]) = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ Text
"Writes out tracers with metrics and silent tracers."
] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
internalRestriction
documentFor (Namespace [Text]
_ [Text
"MetricsInfo"]) = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ Text
"Writes out numbers for metrics delivered."
] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
internalRestriction
documentFor (Namespace [Text]
_ [Text
"TracerConsistencyWarnings"]) = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ Text
"Tracer consistency check found errors."
] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
internalRestriction
documentFor (Namespace [Text]
_ [Text
"TracerConfigInfo"]) = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ Text
"Trace the tracer configuration which is effectively used."
] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
internalRestriction
documentFor Namespace TraceDispatcherMessage
_ = Maybe Text
forall a. Maybe a
Nothing
metricsDocFor :: Namespace TraceDispatcherMessage -> [(Text, Text)]
metricsDocFor (Namespace [Text]
_ [Text
"StartLimiting"]) =
[(Text
"SuppressedMessages...", Text
"Number of suppressed messages of a certain kind")]
metricsDocFor Namespace TraceDispatcherMessage
_ = []
allNamespaces :: [Namespace TraceDispatcherMessage]
allNamespaces = [
[Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"StartLimiting"]
, [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"StopLimiting"]
, [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"RememberLimiting"]
, [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"UnknownNamespace"]
, [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"TracerInfo"]
, [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"MetricsInfo"]
, [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"TracerConsistencyWarnings"]
, [Text] -> [Text] -> Namespace TraceDispatcherMessage
forall a. [Text] -> [Text] -> Namespace a
Namespace [] [Text
"TracerConfigInfo"]
]
textShow :: Show a => a -> Text
textShow :: forall a. Show a => a -> Text
textShow = String -> Text
Text.pack (String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show