From 8dbfac210b4d6e6f83aadd953bb8f91c568b1a9d Mon Sep 17 00:00:00 2001 From: Luke Nadur <19835357+intricate@users.noreply.github.com> Date: Tue, 4 Feb 2020 13:03:22 -0600 Subject: [PATCH 1/2] Add structured logging for TraceEventMempool objects at Info severity --- .../src/Cardano/Tracing/ToObjectOrphans.hs | 39 ++++++++++++++++++- cardano-node/src/Cardano/Tracing/Tracers.hs | 11 ++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs index cfcfe018b77..c34457e2787 100644 --- a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs +++ b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs @@ -37,7 +37,8 @@ import Ouroboros.Consensus.ChainSyncClient import Ouroboros.Consensus.ChainSyncServer (TraceChainSyncServerEvent(..)) import Ouroboros.Consensus.Ledger.Abstract -import Ouroboros.Consensus.Mempool.API (GenTx, GenTxId, HasTxId, TxId, txId) +import Ouroboros.Consensus.Mempool.API (ApplyTxErr, GenTx, GenTxId, + HasTxId, TraceEventMempool (..), TxId, txId) import Ouroboros.Consensus.Node.Tracers (TraceForgeEvent (..)) import Ouroboros.Consensus.TxSubmission (TraceLocalTxSubmissionServerEvent (..)) @@ -313,6 +314,10 @@ instance DefinePrivacyAnnotation (TraceLocalTxSubmissionServerEvent blk) instance DefineSeverity (TraceLocalTxSubmissionServerEvent blk) where defineSeverity _ = Info +instance DefinePrivacyAnnotation (TraceEventMempool blk) +instance DefineSeverity (TraceEventMempool blk) where + defineSeverity _ = Info + instance DefinePrivacyAnnotation (TraceForgeEvent blk tx) instance DefineSeverity (TraceForgeEvent blk tx) where defineSeverity TraceForgedBlock {} = Info @@ -371,6 +376,10 @@ instance (Condense (HeaderHash blk), Show (TxId tx), HasTxId tx, Show blk, Show <*> pure (LogMessage $ pack $ show s) trTransformer UserdefinedFormatting verb tr = trStructured verb tr +instance (Show (GenTx blk), Show (GenTxId blk), Show (ApplyTxErr blk)) + => Transformable Text IO (TraceEventMempool blk) where + trTransformer _ verb tr = trStructured verb tr + -- transform @SubscriptionTrace@ instance Transformable Text IO (WithIPList (SubscriptionTrace Socket.SockAddr)) where trTransformer StructuredLogging verb tr = trStructured verb tr @@ -904,3 +913,31 @@ instance (HasTxId tx, ProtocolLedgerView blk, Condense (HeaderHash blk), Show (T [ "kind" .= String "TraceStartLeadershipCheck" , "slot" .= toJSON (unSlotNo slotNo) ] + +instance (Show (GenTx blk), Show (GenTxId blk), Show (ApplyTxErr blk)) + => ToObject (TraceEventMempool blk) where + toObject _verb (TraceMempoolAddTxs txs mpSz) = + mkObject + [ "kind" .= String "TraceMempoolAddTxs" + , "txsAdded" .= String (pack $ show $ txs) + , "mempoolSize" .= String (pack $ show $ mpSz) + ] + toObject _verb (TraceMempoolRejectedTxs txAndErrs mpSz) = + mkObject + [ "kind" .= String "TraceMempoolRejectedTxs" + , "txsRejected" .= String (pack $ show $ txAndErrs) + , "mempoolSize" .= String (pack $ show $ mpSz) + ] + toObject _verb (TraceMempoolRemoveTxs txs mpSz) = + mkObject + [ "kind" .= String "TraceMempoolRemoveTxs" + , "txsRemoved" .= String (pack $ show $ txs) + , "mempoolSize" .= String (pack $ show $ mpSz) + ] + toObject _verb (TraceMempoolManuallyRemovedTxs txs0 txs1 mpSz) = + mkObject + [ "kind" .= String "TraceMempoolManuallyRemovedTxs" + , "txsManuallyRemoved" .= String (pack $ show $ txs0) + , "txsNoLongerValidRemoved" .= String (pack $ show $ txs1) + , "mempoolSize" .= String (pack $ show $ mpSz) + ] diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index a906315a30a..4481c3fbf18 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -297,9 +297,14 @@ mkTracers traceOptions tracer = do mempoolTracer :: Tracer IO (TraceEventMempool blk) mempoolTracer = Tracer $ \ev -> do - traceWith (mempoolTraceTransformer tracer) ev - traceWith (measureTxsStart tracer) ev - traceWith (showTracing $ withName "Mempool" tracer) ev + traceWith (mempoolTraceTransformer tracer) ev + traceWith (measureTxsStart tracer) ev + traceWith mpTracer ev + where + mpTracer :: Tracer IO (TraceEventMempool blk) + mpTracer = annotateSeverity + $ toLogObject' StructuredLogging tracingVerbosity + $ addName "Mempool" tracer forgeTracer :: ForgeTracers From 2f2df7cdb0f7ccad7311d7d104d395bb169d7182 Mon Sep 17 00:00:00 2001 From: Luke Nadur <19835357+intricate@users.noreply.github.com> Date: Tue, 4 Feb 2020 13:04:14 -0600 Subject: [PATCH 2/2] Rename mempoolTraceTransformer to mempoolMetricsTraceTransformer --- cardano-node/src/Cardano/Tracing/Tracers.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index 4481c3fbf18..a9e57d2d405 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -263,9 +263,9 @@ mkTracers traceOptions tracer = do let tr' = appendName "peers" tr traceNamedObject tr' (meta, LogValue "connectedPeers" . PureI $ fromIntegral $ length peers) - mempoolTraceTransformer :: Tracer IO (LogObject a) - -> Tracer IO (TraceEventMempool blk) - mempoolTraceTransformer tr = Tracer $ \mempoolEvent -> do + mempoolMetricsTraceTransformer :: Tracer IO (LogObject a) + -> Tracer IO (TraceEventMempool blk) + mempoolMetricsTraceTransformer tr = Tracer $ \mempoolEvent -> do let tr' = appendName "metrics" tr (n, tot) = case mempoolEvent of TraceMempoolAddTxs txs0 tot0 -> (length txs0, tot0) @@ -297,7 +297,7 @@ mkTracers traceOptions tracer = do mempoolTracer :: Tracer IO (TraceEventMempool blk) mempoolTracer = Tracer $ \ev -> do - traceWith (mempoolTraceTransformer tracer) ev + traceWith (mempoolMetricsTraceTransformer tracer) ev traceWith (measureTxsStart tracer) ev traceWith mpTracer ev where