-
Notifications
You must be signed in to change notification settings - Fork 754
cardano-recon-framework: Add cardano-recon-grep and ContinuousFormula (v1.2.0) #6560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Russoul
wants to merge
8
commits into
master
Choose a base branch
from
russoul/recon-grep
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d9369e4
Get rid of TextFree IR
Russoul d63c090
Implement a `ContinuousFormula` for filtering events by formula confo…
Russoul e788ae6
cardano-recon-framework: Add cardano-recon-grep and ContinuousFormula…
Russoul c24c71c
cardano-recon-grep: support reading traces from stdin when --traces i…
Russoul 15957fb
cardano-recon: add --grep flag for machine-readable negative outcome …
Russoul 6e3a289
cardano-recon: --grep bypasses trace-dispatcher; add ContextDump trac…
Russoul 55f0716
cardano-recon: update README and CHANGELOG for --grep and ContextDump
Russoul 3d02613
Apply review suggestion regarding the cabal file
Russoul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,17 +5,15 @@ module Cardano.ReCon.TraceMessage where | |
| import Cardano.Logging | ||
| import Cardano.Logging.Prometheus.TCPServer (TracePrometheusSimple (..)) | ||
| import qualified Cardano.Logging.Types.TraceMessage as Envelop | ||
| import Cardano.ReCon.Common (extractJsonProps) | ||
| import Cardano.ReCon.LTL.Formula (Formula, Relevance) | ||
| import qualified Cardano.ReCon.LTL.Formula.Prec as Prec | ||
| import Cardano.ReCon.LTL.Formula.Pretty (prettyFormula) | ||
| import Cardano.ReCon.LTL.Satisfy (SatisfactionResult (..)) | ||
| import Cardano.ReCon.Trace.Feed (TemporalEvent (..)) | ||
|
|
||
| import Data.Aeson (Value (..), (.=)) | ||
| import Data.Aeson ((.=)) | ||
| import Data.Aeson.Encode.Pretty | ||
| import Data.List (find) | ||
| import qualified Data.Map as Map | ||
| import qualified Data.Set as Set | ||
| import Data.Text (Text) | ||
| import qualified Data.Text as Text | ||
|
|
@@ -44,13 +42,14 @@ data TraceMessage = FormulaStartCheck { | |
| | FormulaNegativeOutcome { | ||
| formula :: Formula TemporalEvent Text, | ||
| relevance :: Relevance TemporalEvent Text, | ||
| index :: Word | ||
| index :: Word | ||
| } | ||
| | ContextDump { context :: [(Text, Text)] } | ||
|
|
||
| -- | Smart constructor. | ||
| formulaOutcome :: Formula TemporalEvent Text -> SatisfactionResult TemporalEvent Text -> Word -> TraceMessage | ||
| formulaOutcome formula Satisfied idx = FormulaPositiveOutcome formula idx | ||
| formulaOutcome formula (Unsatisfied rel) idx = FormulaNegativeOutcome formula rel idx | ||
| formulaOutcome formula Satisfied idx = FormulaPositiveOutcome { formula, index = idx } | ||
| formulaOutcome formula (Unsatisfied rel) idx = FormulaNegativeOutcome { formula, relevance = rel, index = idx } | ||
|
|
||
| green :: Text -> Text | ||
| green text = "\x001b[32m" <> text <> "\x001b[0m" | ||
|
|
@@ -59,51 +58,51 @@ red :: Text -> Text | |
| red text = "\x001b[31m" <> text <> "\x001b[0m" | ||
|
|
||
| prettyTraceMessage :: Envelop.TraceMessage -> Text | ||
| prettyTraceMessage Envelop.TraceMessage{..} = | ||
| toStrict $ toLazyText $ encodePrettyToTextBuilder $ | ||
| Map.insert "at" (String (showT tmsgAt)) $ | ||
| Map.insert "namespace" (String tmsgNS) $ | ||
| Map.insert "host" (String tmsgHost) $ | ||
| Map.insert "thread" (String tmsgThread) $ | ||
| extractJsonProps tmsgData | ||
| prettyTraceMessage = toStrict . toLazyText . encodePrettyToTextBuilder | ||
|
|
||
| prettyTemporalEvent :: TemporalEvent -> Text -> Text | ||
| prettyTemporalEvent (TemporalEvent _ msgs) ns = | ||
| maybe ("<<Unexpected namespace " <> ns <> ">>") prettyTraceMessage (find (\ x -> x.tmsgNS == ns) msgs) | ||
|
|
||
| prettyRelevanceArray :: Relevance TemporalEvent Text -> Text | ||
| prettyRelevanceArray rel = | ||
| "[\n" | ||
| <> Text.intercalate "\n,\n" (fmap (uncurry prettyTemporalEvent) (Set.toList rel)) | ||
| <> "\n]" | ||
|
|
||
| prettySatisfactionResult :: Formula TemporalEvent Text -> SatisfactionResult TemporalEvent Text -> Text | ||
| prettySatisfactionResult initial Satisfied = prettyFormula initial Prec.Universe <> " " <> green "(✔)" | ||
| prettySatisfactionResult initial (Unsatisfied rel) = | ||
| prettyFormula initial Prec.Universe <> red " (✗)" <> "\n" | ||
| <> Text.intercalate | ||
| "\n----------------------------------------------\n" | ||
| (fmap (uncurry prettyTemporalEvent) (Set.toList rel)) | ||
| <> prettyRelevanceArray rel | ||
|
|
||
| instance LogFormatting TraceMessage where | ||
| forMachine _ FormulaStartCheck{..} = mconcat | ||
| [ | ||
| "formula" .= String (prettyFormula formula Prec.Universe), | ||
| "formula" .= prettyFormula formula Prec.Universe, | ||
| "index" .= index | ||
| ] | ||
| forMachine _ FormulaProgressDump{..} = mconcat | ||
| [ | ||
| "events_per_second" .= Number (fromIntegral eventsPerSecond), | ||
| "catch_up_ratio" .= Number (realToFrac catchupRatio), | ||
| "events_per_second" .= (fromIntegral eventsPerSecond :: Int), | ||
| "catch_up_ratio" .= (realToFrac catchupRatio :: Double), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For JSON property names, please always use camelCasing. |
||
| "index" .= index | ||
| ] | ||
| forMachine _ FormulaPositiveOutcome{..} = mconcat | ||
| [ | ||
| "formula" .= String (prettyFormula formula Prec.Universe), | ||
| "formula" .= prettyFormula formula Prec.Universe, | ||
| "index" .= index | ||
| ] | ||
| forMachine _ FormulaNegativeOutcome{..} = mconcat | ||
| [ | ||
| "formula" .= String (prettyFormula formula Prec.Universe) | ||
| "formula" .= prettyFormula formula Prec.Universe | ||
| , | ||
| "relevance" .= String (showT relevance) | ||
| "relevance" .= showT relevance | ||
| , | ||
| "index" .= index | ||
| ] | ||
| forMachine _ ContextDump{..} = mconcat | ||
| [ "context" .= context ] | ||
|
|
||
| forHuman FormulaStartCheck{..} = | ||
| "Starting satisfiability check on formula #" <> showT index <> ": " <> prettyFormula formula Prec.Universe | ||
|
|
@@ -119,28 +118,35 @@ instance LogFormatting TraceMessage where | |
| prettySatisfactionResult formula Satisfied | ||
| forHuman FormulaNegativeOutcome{..} = | ||
| prettySatisfactionResult formula (Unsatisfied relevance) | ||
| forHuman ContextDump{..} = | ||
| "Context:\n" <> Text.unlines (fmap (\(k, v) -> " " <> k <> " = " <> v) context) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| asMetrics FormulaStartCheck{} = [] | ||
| asMetrics (FormulaProgressDump {catchupRatio, index}) = [DoubleM ("catchup_ratio_" <> showT index) catchupRatio] | ||
| asMetrics FormulaPositiveOutcome{} = [] | ||
| asMetrics FormulaNegativeOutcome{} = [] | ||
| asMetrics ContextDump{} = [] | ||
|
|
||
|
|
||
| instance MetaTrace TraceMessage where | ||
| allNamespaces = | ||
| [ | ||
| Namespace [] ["ContextDump"] | ||
| , | ||
| Namespace [] ["FormulaStartCheck"] | ||
| , | ||
| Namespace [] ["FormulaProgressDump"] | ||
| , | ||
| Namespace [] ["FormulaOutcome"] | ||
| ] | ||
|
|
||
| namespaceFor ContextDump{} = Namespace [] ["ContextDump"] | ||
| namespaceFor FormulaStartCheck{} = Namespace [] ["FormulaStartCheck"] | ||
| namespaceFor FormulaProgressDump{} = Namespace [] ["FormulaProgressDump"] | ||
| namespaceFor FormulaPositiveOutcome{} = Namespace [] ["FormulaPositiveOutcome"] | ||
| namespaceFor FormulaNegativeOutcome{} = Namespace [] ["FormulaNegativeOutcome"] | ||
|
|
||
| severityFor (Namespace [] ["ContextDump"]) _ = Just Debug | ||
| severityFor (Namespace [] ["FormulaStartCheck"]) _ = Just Info | ||
| severityFor (Namespace [] ["FormulaProgressDump"]) _ = Just Debug | ||
| severityFor (Namespace [] ["FormulaPositiveOutcome"]) _ = Just Info | ||
|
|
@@ -149,6 +155,8 @@ instance MetaTrace TraceMessage where | |
|
|
||
| detailsFor _ _ = Just DNormal | ||
|
|
||
| documentFor (Namespace [] ["ContextDump"]) = | ||
| Just "Dump of the context variables supplied to the formula parser." | ||
| documentFor (Namespace [] ["FormulaStartCheck"]) = | ||
| Just "Formula satisfiability check has started." | ||
| documentFor (Namespace [] ["FormulaProgressDump"]) = | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
Text.unlines