From 6768aa0596862697a68f68a61aef83a5b4ee392f Mon Sep 17 00:00:00 2001 From: Kosyrev Serge Date: Thu, 20 Feb 2020 21:38:46 +0300 Subject: [PATCH 1/4] CAD-636 | tracing: factor defaultTextTransformer --- .../src/Cardano/Tracing/ToObjectOrphans.hs | 71 ++++++++----------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs index fc68aed5fe2..f285f8893ae 100644 --- a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs +++ b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs @@ -218,6 +218,26 @@ instance DefinePrivacyAnnotation (WithTip blk (ChainDB.TraceEvent blk)) instance DefineSeverity (WithTip blk (ChainDB.TraceEvent blk)) where defineSeverity (WithTip _tip ev) = defineSeverity ev +defaultTextTransformer + :: ( MonadIO m + , DefinePrivacyAnnotation b + , DefineSeverity b + , Show b + , ToObject b) + => TracingFormatting + -> TracingVerbosity + -> Trace m Text + -> Tracer m b +defaultTextTransformer TextualRepresentation _verb tr = + Tracer $ \s -> + traceWith tr =<< + LogObject + <$> pure mempty + <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) + <*> pure (LogMessage $ pack $ show s) +defaultTextTransformer _ verb tr = + trStructured verb tr + instance DefineSeverity (ChainDB.TraceEvent blk) where defineSeverity (ChainDB.TraceAddBlockEvent ev) = case ev of ChainDB.IgnoreBlockOlderThanK {} -> Info @@ -369,31 +389,26 @@ instance Show peer => Transformable Text IO (TraceLabelPeer peer instance (Show peer, Show txid, Show tx) => Transformable Text IO (TraceLabelPeer peer (TraceSendRecv (TxSubmission txid tx))) where - trTransformer _ verb tr = trStructured verb tr + trTransformer = defaultTextTransformer -- transform @BlockFetchServerEvent@ instance Transformable Text IO (TraceBlockFetchServerEvent blk) where - trTransformer _ verb tr = trStructured verb tr + trTransformer = defaultTextTransformer instance Transformable Text IO (TraceTxSubmissionInbound (GenTxId blk) (GenTx blk)) where - trTransformer _ verb tr = trStructured verb tr + trTransformer = defaultTextTransformer instance Transformable Text IO (TraceTxSubmissionOutbound (GenTxId blk) (GenTx blk)) where - trTransformer _ verb tr = trStructured verb tr + trTransformer = defaultTextTransformer instance Transformable Text IO (TraceLocalTxSubmissionServerEvent blk) where trTransformer _ verb tr = trStructured verb tr instance (Condense (HeaderHash blk), Show (TxId tx), HasTxId tx, Show blk, Show tx, ProtocolLedgerView blk) => Transformable Text IO (TraceForgeEvent blk tx) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer instance (Show (GenTx blk), Show (GenTxId blk)) => Transformable Text IO (TraceEventMempool blk) where @@ -401,49 +416,24 @@ instance (Show (GenTx blk), Show (GenTxId blk)) -- transform @SubscriptionTrace@ instance Transformable Text IO (WithIPList (SubscriptionTrace Socket.SockAddr)) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer instance Transformable Text IO (WithDomainName (SubscriptionTrace Socket.SockAddr)) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer -- transform @DnsTrace@ instance Transformable Text IO (WithDomainName DnsTrace) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer -- transform @ErrorPolicyTrace@ instance Transformable Text IO (WithAddr Socket.SockAddr ErrorPolicyTrace) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer -- transform @MuxTrace@ instance (Show peer) => Transformable Text IO (WithMuxBearer peer MuxTrace) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer -- transform @TraceEvent@ instance (Condense (HeaderHash blk), ProtocolLedgerView blk) @@ -457,6 +447,7 @@ instance (Condense (HeaderHash blk), ProtocolLedgerView blk) <*> pure (LogMessage $ pack s) -- user defined formatting of log output trTransformer UserdefinedFormatting verb tr = trStructured verb tr + -- trTransformer _ verb tr = trStructured verb tr -- | tracer transformer to text messages for TraceEvents -- Converts the trace events from the ChainDB that we're interested in into From c1392decf2465b36753f61d049071e10c9aeaab2 Mon Sep 17 00:00:00 2001 From: Kosyrev Serge Date: Thu, 20 Feb 2020 21:38:54 +0300 Subject: [PATCH 2/4] CAD-636 | tracing: Transformable instance for TraceAddBlockEvent --- cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs index f285f8893ae..338743df842 100644 --- a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs +++ b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs @@ -31,7 +31,7 @@ import Cardano.BM.Data.LogItem (LOContent (..), LogObject (..), import Cardano.BM.Tracing import Cardano.BM.Data.Tracer (trStructured, emptyObject, mkObject) -import Ouroboros.Consensus.Block (SupportedBlock, headerPoint) +import Ouroboros.Consensus.Block (Header, SupportedBlock, headerPoint) import Ouroboros.Consensus.BlockFetchServer (TraceBlockFetchServerEvent) import Ouroboros.Consensus.ChainSyncClient @@ -238,6 +238,14 @@ defaultTextTransformer TextualRepresentation _verb tr = defaultTextTransformer _ verb tr = trStructured verb tr +instance ( DefinePrivacyAnnotation (ChainDB.TraceAddBlockEvent blk) + , DefineSeverity (ChainDB.TraceAddBlockEvent blk) + , ProtocolLedgerView blk + , Show (Ouroboros.Consensus.Block.Header blk) + , ToObject (ChainDB.TraceAddBlockEvent blk)) + => Transformable Text IO (ChainDB.TraceAddBlockEvent blk) where + trTransformer = defaultTextTransformer + instance DefineSeverity (ChainDB.TraceEvent blk) where defineSeverity (ChainDB.TraceAddBlockEvent ev) = case ev of ChainDB.IgnoreBlockOlderThanK {} -> Info From 1ff4f84e9bb115ab244c248a93e29ce7fb85a77b Mon Sep 17 00:00:00 2001 From: Kosyrev Serge Date: Fri, 21 Feb 2020 01:09:41 +0300 Subject: [PATCH 3/4] CAD-636: TextualRepr traces for forging, mempool and chain tip events --- cardano-node/src/Cardano/Tracing/Tracers.hs | 31 +++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index 7bb62405415..a1e421dfcec 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -190,8 +190,9 @@ mkTracers traceOptions tracer = do { chainDBTracer = tracerOnOff (traceChainDB traceOptions) $ annotateSeverity - $ teeTraceChainTip StructuredLogging tracingVerbosity elided - $ addName "ChainDB" tracer + $ teeTraceChainTip tracingVerbosity elided + $ addName "ChainDB" + $ tracer , consensusTracers = mkConsensusTracers forgeTracers traceOptions , protocolTracers @@ -230,14 +231,14 @@ mkTracers traceOptions tracer = do tracingVerbosity :: TracingVerbosity tracingVerbosity = traceVerbosity traceOptions - teeTraceChainTip :: TracingFormatting - -> TracingVerbosity + teeTraceChainTip :: TracingVerbosity -> MVar (Maybe (WithSeverity (WithTip blk (ChainDB.TraceEvent blk))), Int) -> Tracer IO (LogObject Text) -> Tracer IO (WithSeverity (WithTip blk (ChainDB.TraceEvent blk))) - teeTraceChainTip tform tverb elided tr = Tracer $ \ev -> do + teeTraceChainTip tverb elided tr = Tracer $ \ev -> do traceWith (teeTraceChainTip' tr) ev - traceWith (teeTraceChainTipElide tform tverb elided tr) ev + traceWith (teeTraceChainTipElide StructuredLogging tverb elided tr) ev + traceWith (teeTraceChainTipElide TextualRepresentation tverb elided (addName "text" tr)) ev teeTraceChainTipElide :: TracingFormatting -> TracingVerbosity -> MVar (Maybe (WithSeverity (WithTip blk (ChainDB.TraceEvent blk))), Int) @@ -314,12 +315,12 @@ mkTracers traceOptions tracer = do mempoolTracer = Tracer $ \ev -> do traceWith (mempoolMetricsTraceTransformer tracer) ev traceWith (measureTxsStart tracer) ev - traceWith mpTracer ev + let tr = addName "Mempool" tracer + traceWith (mpTracer StructuredLogging tr) ev + traceWith (mpTracer TextualRepresentation (addName "text" tr)) ev where - mpTracer :: Tracer IO (TraceEventMempool blk) - mpTracer = annotateSeverity - $ toLogObject' StructuredLogging tracingVerbosity - $ addName "Mempool" tracer + mpTracer :: TracingFormatting -> Tracer IO (LogObject Text) -> Tracer IO (TraceEventMempool blk) + mpTracer fmt tr = annotateSeverity $ toLogObject' fmt tracingVerbosity tr forgeTracer :: ForgeTracers @@ -334,16 +335,15 @@ mkTracers traceOptions tracer = do -- The consensus tracer. consensusForgeTracer = tracerOnOff (traceForge traceOpts) $ annotateSeverity - $ teeForge forgeTracers StructuredLogging tracingVerbosity + $ teeForge forgeTracers tracingVerbosity $ addName "Forge" tracer teeForge :: ForgeTracers - -> TracingFormatting -> TracingVerbosity -> Trace IO Text -> Tracer IO (WithSeverity (Consensus.TraceForgeEvent blk (GenTx blk))) - teeForge ft tform tverb tr = Tracer $ \ev -> do + teeForge ft tverb tr = Tracer $ \ev -> do traceWith (teeForge' tr) ev flip traceWith ev $ fanning $ \(WithSeverity _ e) -> case e of @@ -359,7 +359,8 @@ mkTracers traceOptions tracer = do Consensus.TraceSlotIsImmutable{} -> teeForge' (ftTraceSlotIsImmutable ft) Consensus.TraceNodeIsLeader{} -> teeForge' (ftTraceNodeIsLeader ft) - traceWith (toLogObject' tform tverb tr) ev + traceWith (toLogObject' StructuredLogging tverb tr) ev + traceWith (toLogObject' TextualRepresentation tverb (addName "text" tr)) ev teeForge' :: Trace IO Text From 4cacbe4da2b04533b89a06f75c853b179577dee0 Mon Sep 17 00:00:00 2001 From: Kosyrev Serge Date: Fri, 21 Feb 2020 01:50:11 +0300 Subject: [PATCH 4/4] CAD-636 | tracing: update the JournalSK example --- configuration/log-configuration.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/configuration/log-configuration.yaml b/configuration/log-configuration.yaml index 77df740877d..23ab96940fa 100644 --- a/configuration/log-configuration.yaml +++ b/configuration/log-configuration.yaml @@ -27,17 +27,22 @@ setupScribes: scName: stdout scFormat: ScText scRotation: null + # for output to 'journald' add this scribe: + # - scKind: JournalSK + # scName: "cardano" + # scFormat: ScText # if not indicated otherwise, then log output is directed to this: defaultScribes: - - StdoutSK - stdout -# for output to 'journald' add this scribe: -# - - JournalSK -# - cardano # more options which can be passed as key-value pairs: options: + # for output to 'journald', map these TextualRepresentation traces: + # mapScribes: + # cardano.node.text: + # - JournalSK::cardano mapSubtrace: benchmark: contents: