Skip to content
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

EKG counter for tips served #3300

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions cardano-node/src/Cardano/Tracing/Tracers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,6 @@ isRollForward :: TraceChainSyncServerEvent blk -> Bool
isRollForward (TraceChainSyncRollForward _) = True
isRollForward _ = False

isTraceBlockFetchServerBlockCount :: TraceBlockFetchServerEvent blk -> Bool
isTraceBlockFetchServerBlockCount (TraceBlockFetchServerSendBlock _) = True

mkConsensusTracers
:: forall blk peer localPeer.
( Show peer
Expand Down Expand Up @@ -533,7 +530,9 @@ mkConsensusTracers mbEKGDirect trSel verb tr nodeKern fStats = do
forgeTracers <- mkForgeTracers
meta <- mkLOMeta Critical Public

tBlocksServed <- STM.newTVarIO @Int 0
tBlocksServed <- STM.newTVarIO 0
tLocalUp <- STM.newTVarIO 0
tMaxSlotNo <- STM.newTVarIO $ SlotNo 0
tSubmissionsCollected <- STM.newTVarIO 0
tSubmissionsAccepted <- STM.newTVarIO 0
tSubmissionsRejected <- STM.newTVarIO 0
Expand All @@ -555,12 +554,8 @@ mkConsensusTracers mbEKGDirect trSel verb tr nodeKern fStats = do
, Consensus.blockFetchClientTracer = traceBlockFetchClientMetrics mbEKGDirect tBlockDelayM
tBlockDelayCDF1s tBlockDelayCDF3s tBlockDelayCDF5s $
tracerOnOff (traceBlockFetchClient trSel) verb "BlockFetchClient" tr
, Consensus.blockFetchServerTracer = tracerOnOff' (traceBlockFetchServer trSel) $
Tracer $ \ev -> do
traceWith (annotateSeverity . toLogObject' verb $ appendName "BlockFetchServer" tr) ev
when (isTraceBlockFetchServerBlockCount ev) $
traceI trmet meta "served.block.count" =<<
STM.modifyReadTVarIO tBlocksServed (+1)
, Consensus.blockFetchServerTracer = traceBlockFetchServerMetrics trmet meta tBlocksServed
tLocalUp tMaxSlotNo $ tracerOnOff (traceBlockFetchServer trSel) verb "BlockFetchServer" tr
, Consensus.forgeStateInfoTracer = tracerOnOff' (traceForgeStateInfo trSel) $
forgeStateInfoTracer (Proxy @ blk) trSel tr
, Consensus.txInboundTracer = tracerOnOff' (traceTxInbound trSel) $
Expand Down Expand Up @@ -621,6 +616,46 @@ mkConsensusTracers mbEKGDirect trSel verb tr nodeKern fStats = do
when (isRollForward ev) $
sendEKGDirectCounter ekgDirect "cardano.node.metrics.served.header.counter.int"

traceBlockFetchServerMetrics
:: forall blk. ()
=> Tracer IO (LoggerName, LogObject Text)
-> LOMeta
-> STM.TVar Int64
-> STM.TVar Int64
-> STM.TVar SlotNo
-> Tracer IO (TraceBlockFetchServerEvent blk)
-> Tracer IO (TraceBlockFetchServerEvent blk)
traceBlockFetchServerMetrics trMeta meta tBlocksServed tLocalUp tMaxSlotNo tracer = Tracer bsTracer

where
bsTracer :: TraceBlockFetchServerEvent blk -> IO ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the local upstreaminess metric which tries to answer the question: how many times we serve a block which slot is either equal or ahead of last served block.

I would like to see a description how this related to the upstreaminess metric that is used to choose peers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should mention that at all. This is a useful metric on its own, regardless of if that is how down stream peers may judge the node in the future.

bsTracer e@(TraceBlockFetchServerSendBlock p) = do
traceWith tracer e

(served, mbLocalUpstreamyness) <- atomically $ do
served <- STM.modifyReadTVar' tBlocksServed (+1)
maxSlotNo <- STM.readTVar tMaxSlotNo
case pointSlot p of
Origin -> return (served, Nothing)
At slotNo ->
case compare maxSlotNo slotNo of
LT -> do
STM.writeTVar tMaxSlotNo slotNo
lu <- STM.modifyReadTVar' tLocalUp (+1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is modifyReadTVar'?

Is it equialvent to:

STM.modifyTVar' tLocalUP (+1) >> STM.readTVar tLocalUP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return (served, Just lu)
GT -> do
return (served, Nothing)
EQ -> do
lu <- STM.modifyReadTVar' tLocalUp (+1)
return (served, Just lu)

traceI trMeta meta "served.block.count" served
case mbLocalUpstreamyness of
Just localUpstreamyness ->
traceI trMeta meta "served.block.latest.count" localUpstreamyness
Nothing -> return ()


-- | CdfCounter tracks the number of time a value below 'limit' has been seen.
newtype CdfCounter (limit :: Nat) = CdfCounter Int64

Expand Down