Skip to content

Commit

Permalink
Optimization with metrics always available
Browse files Browse the repository at this point in the history
  • Loading branch information
jutaro committed Nov 29, 2022
1 parent 960099c commit d053bbf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 40 deletions.
Expand Up @@ -12,7 +12,7 @@ defaultCardanoConfig :: TraceConfig
defaultCardanoConfig = emptyTraceConfig {
tcOptions = Map.fromList
[([],
[ ConfSeverity (SeverityF (Just Notice))
[ ConfSeverity (SeverityF (Just Silence))
, ConfDetail DNormal
, ConfBackend [Stdout MachineFormat
, EKGBackend
Expand Down
2 changes: 1 addition & 1 deletion doc/New Tracing Quickstart.md
Expand Up @@ -20,7 +20,7 @@ on the namespace, and require a one-to-one correspondence between namespaces and

As we have two mechanisms for the same purpose for historic reasons, we will soon
__deprecate the Kind field__, and it will disappear in the near future. So we strongly
advise to use namespaces for any analysis tools of traces!
advice to use namespaces for any analysis tools of traces!

### Configuration of new tracing

Expand Down
13 changes: 1 addition & 12 deletions nix/workbench/profiles/tracing.nix
Expand Up @@ -10,7 +10,7 @@
##
TraceOptions = {
"" =
{ severity = "Notice";
{ severity = "Silence";
backends = [
"Stdout MachineFormat"
"EKGBackend"
Expand All @@ -19,16 +19,5 @@
"Forwarder"
]);
};

## These are benchmarking-specific config deviations from the default.
##
"BlockFetch".severity = "Info";
"BlockFetch.Client.CompletedBlockFetch".maxFrequency = 0;
"ChainSync".severity = "Info";
"ChainSync.Client.DownloadedHeader".maxFrequency = 0;
"Forge.Loop.BlockContext".severity = "Info";
"Forge.Loop.LedgerState".severity = "Info";
"Forge.Loop.LedgerView".severity = "Info";
"Startup".severity = "Info";
};
}
3 changes: 1 addition & 2 deletions trace-dispatcher/src/Cardano/Logging/Configuration.hs
Expand Up @@ -81,8 +81,8 @@ maybeSilent ns tr = do
mkTrace _ref (lc, Left other) =
T.traceWith (unpackTrace tr) (lc, Left other)

-- If the top tracer is silent and any subtracer is not silent, it is not
isSilentTracer :: TraceConfig -> Namespace -> Bool
-- If the top tracer is silent and no subtracer is not silent, then switch it off
isSilentTracer tc ns =
if getSeverity tc ns == SeverityF Nothing
then
Expand All @@ -91,7 +91,6 @@ isSilentTracer tc ns =
in null blockers
else False
where
filterOpts (ConfSeverity (SeverityF Nothing)) = False
filterOpts (ConfSeverity (SeverityF (Just _))) = True
filterOpts _ = False

Expand Down
49 changes: 32 additions & 17 deletions trace-dispatcher/src/Cardano/Logging/Trace.hs
Expand Up @@ -57,28 +57,43 @@ filterTrace :: (Monad m)
=> ((LoggingContext, a) -> Bool)
-> Trace m a
-> Trace m a
filterTrace ff (Trace tr) = Trace $ T.squelchUnless
(\case
(_lc, Left _) -> True
(lc, Right a) -> ff (lc, a))
tr
filterTrace ff (Trace tr) = Trace $ T.arrow $ T.emit $ mkTrace
where
mkTrace (lc, Right a) =
if ff (lc, a)
then T.traceWith tr (lc, Right a)
else pure ()
mkTrace (lc, Left l) =
T.traceWith tr (lc, Left l)

-- Trace $ T.squelchUnless
-- (\case
-- (_lc, Left _) -> True
-- (lc, Right a) -> ff (lc, a))
-- tr


--- | Keep the Just values and forget about the Nothings
filterTraceMaybe :: Monad m
=> Trace m a
-> Trace m (Maybe a)
filterTraceMaybe (Trace tr) = Trace $
T.squelchUnless
(\case
(_lc, Left _ctrl) -> True
(_lc, Right (Just _)) -> True
(_lc, Right Nothing) -> False)
(T.contramap
(\case
( lc, Right (Just a)) -> (lc, Right a)
(_lc, Right Nothing) -> error "filterTraceMaybe: impossible"
( lc, Left ctrl) -> (lc, Left ctrl))
tr)
filterTraceMaybe (Trace tr) = Trace $ T.arrow $ T.emit $ mkTrace
where
mkTrace (lc, Right (Just m)) = T.traceWith tr (lc, Right m)
mkTrace (_lc, Right Nothing) = pure ()
mkTrace (lc, Left l) = T.traceWith tr (lc, Left l)

-- T.squelchUnless
-- (\case
-- (_lc, Left _ctrl) -> True
-- (_lc, Right (Just _)) -> True
-- (_lc, Right Nothing) -> False)
-- (T.contramap
-- (\case
-- ( lc, Right (Just a)) -> (lc, Right a)
-- (_lc, Right Nothing) -> error "filterTraceMaybe: impossible"
-- ( lc, Left ctrl) -> (lc, Left ctrl))
-- tr)

--- | Only processes messages further with a severity equal or greater as the
--- given one
Expand Down
17 changes: 10 additions & 7 deletions trace-dispatcher/src/Cardano/Logging/Tracer/Composed.hs
Expand Up @@ -67,7 +67,8 @@ mkCardanoTracer trStdout trForward mbTrEkg tracerName namesFor severityFor priva

-- | Adds the possibility to add special tracers via the hook function
mkCardanoTracer' :: forall evt evt1.
LogFormatting evt1
(LogFormatting evt
,LogFormatting evt1)
=> Trace IO FormattedMessage
-> Trace IO FormattedMessage
-> Maybe (Trace IO FormattedMessage)
Expand All @@ -79,17 +80,19 @@ mkCardanoTracer' :: forall evt evt1.
-> IO (Trace IO evt)
mkCardanoTracer' trStdout trForward mbTrEkg tracerName namesFor severityFor privacyFor
hook = do
messageTrace <- withBackendsFromConfig backendsAndFormat
messageTrace' <- withLimitersFromConfig
messageTrace <- withBackendsFromConfig backendsAndFormat
messageTrace' <- withLimitersFromConfig
(NT.contramap Message messageTrace)
(NT.contramap Limit messageTrace)
messageTrace'' <- addContextAndFilter messageTrace'
messageTrace'' <- hook messageTrace'
messageTrace''' <- addContextAndFilter messageTrace''
messageTrace'''' <- maybeSilent tracerName messageTrace'''
let metricsTrace = case mbTrEkg of
Nothing -> Trace NT.nullTracer
Just ekgTrace -> metricsFormatter "Cardano" ekgTrace
let metricsTrace' = filterTrace (\(_,v) -> asMetrics v /= []) metricsTrace
metricsTrace'' <- hook metricsTrace'
maybeSilent tracerName (messageTrace''' <> metricsTrace'')
metricsTrace' <- hook metricsTrace
let metricsTrace'' = filterTrace (\(_,v) -> Prelude.null (asMetrics v)) metricsTrace'
pure (messageTrace'''' <> metricsTrace'')


where
Expand Down

0 comments on commit d053bbf

Please sign in to comment.