Skip to content

Commit

Permalink
Merge #538
Browse files Browse the repository at this point in the history
538: Mempool event tracing details at default log level r=intricate a=intricate

Related: #527 

Co-authored-by: Luke Nadur <[email protected]>
  • Loading branch information
iohk-bors[bot] and intricate authored Feb 6, 2020
2 parents a1572fe + 2f2df7c commit 931185e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
39 changes: 38 additions & 1 deletion cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
]
17 changes: 11 additions & 6 deletions cardano-node/src/Cardano/Tracing/Tracers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 (mempoolMetricsTraceTransformer 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
Expand Down

0 comments on commit 931185e

Please sign in to comment.