@@ -5,17 +5,15 @@ module Cardano.ReCon.TraceMessage where
55import Cardano.Logging
66import Cardano.Logging.Prometheus.TCPServer (TracePrometheusSimple (.. ))
77import qualified Cardano.Logging.Types.TraceMessage as Envelop
8- import Cardano.ReCon.Common (extractJsonProps )
98import Cardano.ReCon.LTL.Formula (Formula , Relevance )
109import qualified Cardano.ReCon.LTL.Formula.Prec as Prec
1110import Cardano.ReCon.LTL.Formula.Pretty (prettyFormula )
1211import Cardano.ReCon.LTL.Satisfy (SatisfactionResult (.. ))
1312import Cardano.ReCon.Trace.Feed (TemporalEvent (.. ))
1413
15- import Data.Aeson (Value ( .. ), (.=) )
14+ import Data.Aeson ((.=) )
1615import Data.Aeson.Encode.Pretty
1716import Data.List (find )
18- import qualified Data.Map as Map
1917import qualified Data.Set as Set
2018import Data.Text (Text )
2119import qualified Data.Text as Text
@@ -44,13 +42,14 @@ data TraceMessage = FormulaStartCheck {
4442 | FormulaNegativeOutcome {
4543 formula :: Formula TemporalEvent Text ,
4644 relevance :: Relevance TemporalEvent Text ,
47- index :: Word
45+ index :: Word
4846 }
47+ | ContextDump { context :: [(Text , Text )] }
4948
5049-- | Smart constructor.
5150formulaOutcome :: Formula TemporalEvent Text -> SatisfactionResult TemporalEvent Text -> Word -> TraceMessage
52- formulaOutcome formula Satisfied idx = FormulaPositiveOutcome formula idx
53- formulaOutcome formula (Unsatisfied rel) idx = FormulaNegativeOutcome formula rel idx
51+ formulaOutcome formula Satisfied idx = FormulaPositiveOutcome { formula, index = idx }
52+ formulaOutcome formula (Unsatisfied rel) idx = FormulaNegativeOutcome { formula, relevance = rel, index = idx }
5453
5554green :: Text -> Text
5655green text = " \x001b [32m" <> text <> " \x001b [0m"
@@ -59,51 +58,49 @@ red :: Text -> Text
5958red text = " \x001b [31m" <> text <> " \x001b [0m"
6059
6160prettyTraceMessage :: Envelop. TraceMessage -> Text
62- prettyTraceMessage Envelop. TraceMessage {.. } =
63- toStrict $ toLazyText $ encodePrettyToTextBuilder $
64- Map. insert " at" (String (showT tmsgAt)) $
65- Map. insert " namespace" (String tmsgNS) $
66- Map. insert " host" (String tmsgHost) $
67- Map. insert " thread" (String tmsgThread) $
68- extractJsonProps tmsgData
61+ prettyTraceMessage = toStrict . toLazyText . encodePrettyToTextBuilder
6962
7063prettyTemporalEvent :: TemporalEvent -> Text -> Text
7164prettyTemporalEvent (TemporalEvent _ msgs) ns =
7265 maybe (" <<Unexpected namespace " <> ns <> " >>" ) prettyTraceMessage (find (\ x -> x. tmsgNS == ns) msgs)
7366
67+ prettyRelevanceArray :: Relevance TemporalEvent Text -> Text
68+ prettyRelevanceArray rel =
69+ Text. unlines $ " [" : fmap (uncurry prettyTemporalEvent) (Set. toList rel) ++ [" ]" ]
70+
7471prettySatisfactionResult :: Formula TemporalEvent Text -> SatisfactionResult TemporalEvent Text -> Text
7572prettySatisfactionResult initial Satisfied = prettyFormula initial Prec. Universe <> " " <> green " (✔)"
7673prettySatisfactionResult initial (Unsatisfied rel) =
7774 prettyFormula initial Prec. Universe <> red " (✗)" <> " \n "
78- <> Text. intercalate
79- " \n ----------------------------------------------\n "
80- (fmap (uncurry prettyTemporalEvent) (Set. toList rel))
75+ <> prettyRelevanceArray rel
8176
8277instance LogFormatting TraceMessage where
8378 forMachine _ FormulaStartCheck {.. } = mconcat
8479 [
85- " formula" .= String ( prettyFormula formula Prec. Universe) ,
80+ " formula" .= prettyFormula formula Prec. Universe ,
8681 " index" .= index
8782 ]
8883 forMachine _ FormulaProgressDump {.. } = mconcat
8984 [
90- " events_per_second " .= Number (fromIntegral eventsPerSecond),
91- " catch_up_ratio " .= Number (realToFrac catchupRatio),
85+ " eventsPerSecond " .= (fromIntegral eventsPerSecond :: Int ),
86+ " catchUpRatio " .= (realToFrac catchupRatio :: Double ),
9287 " index" .= index
9388 ]
9489 forMachine _ FormulaPositiveOutcome {.. } = mconcat
9590 [
96- " formula" .= String ( prettyFormula formula Prec. Universe) ,
91+ " formula" .= prettyFormula formula Prec. Universe ,
9792 " index" .= index
9893 ]
9994 forMachine _ FormulaNegativeOutcome {.. } = mconcat
10095 [
101- " formula" .= String ( prettyFormula formula Prec. Universe)
96+ " formula" .= prettyFormula formula Prec. Universe
10297 ,
103- " relevance" .= String ( showT relevance)
98+ " relevance" .= showT relevance
10499 ,
105100 " index" .= index
106101 ]
102+ forMachine _ ContextDump {.. } = mconcat
103+ [ " context" .= context ]
107104
108105 forHuman FormulaStartCheck {.. } =
109106 " Starting satisfiability check on formula #" <> showT index <> " : " <> prettyFormula formula Prec. Universe
@@ -119,28 +116,35 @@ instance LogFormatting TraceMessage where
119116 prettySatisfactionResult formula Satisfied
120117 forHuman FormulaNegativeOutcome {.. } =
121118 prettySatisfactionResult formula (Unsatisfied relevance)
119+ forHuman ContextDump {.. } =
120+ Text. unlines $ " Context:" : map (\ (k, v) -> " " <> k <> " = " <> v) context
122121
123122 asMetrics FormulaStartCheck {} = []
124123 asMetrics (FormulaProgressDump {catchupRatio, index}) = [DoubleM (" catchup_ratio_" <> showT index) catchupRatio]
125124 asMetrics FormulaPositiveOutcome {} = []
126125 asMetrics FormulaNegativeOutcome {} = []
126+ asMetrics ContextDump {} = []
127127
128128
129129instance MetaTrace TraceMessage where
130130 allNamespaces =
131131 [
132+ Namespace [] [" ContextDump" ]
133+ ,
132134 Namespace [] [" FormulaStartCheck" ]
133135 ,
134136 Namespace [] [" FormulaProgressDump" ]
135137 ,
136138 Namespace [] [" FormulaOutcome" ]
137139 ]
138140
141+ namespaceFor ContextDump {} = Namespace [] [" ContextDump" ]
139142 namespaceFor FormulaStartCheck {} = Namespace [] [" FormulaStartCheck" ]
140143 namespaceFor FormulaProgressDump {} = Namespace [] [" FormulaProgressDump" ]
141144 namespaceFor FormulaPositiveOutcome {} = Namespace [] [" FormulaPositiveOutcome" ]
142145 namespaceFor FormulaNegativeOutcome {} = Namespace [] [" FormulaNegativeOutcome" ]
143146
147+ severityFor (Namespace [] [" ContextDump" ]) _ = Just Debug
144148 severityFor (Namespace [] [" FormulaStartCheck" ]) _ = Just Info
145149 severityFor (Namespace [] [" FormulaProgressDump" ]) _ = Just Debug
146150 severityFor (Namespace [] [" FormulaPositiveOutcome" ]) _ = Just Info
@@ -149,6 +153,8 @@ instance MetaTrace TraceMessage where
149153
150154 detailsFor _ _ = Just DNormal
151155
156+ documentFor (Namespace [] [" ContextDump" ]) =
157+ Just " Dump of the context variables supplied to the formula parser."
152158 documentFor (Namespace [] [" FormulaStartCheck" ]) =
153159 Just " Formula satisfiability check has started."
154160 documentFor (Namespace [] [" FormulaProgressDump" ]) =
0 commit comments