Skip to content

Commit

Permalink
cardano-node: added metric served.block.latest
Browse files Browse the repository at this point in the history
  • Loading branch information
jutaro committed Sep 18, 2024
1 parent 8673a6d commit 3e0ce34
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import Cardano.Node.Tracing.Tracers.KESInfo
import Cardano.Node.Tracing.Tracers.NodeToClient ()
import Cardano.Node.Tracing.Tracers.NodeToNode ()
import Cardano.Node.Tracing.Tracers.NodeVersion (getNodeVersion)

import Cardano.Node.Tracing.Tracers.NonP2P ()
import Cardano.Node.Tracing.Tracers.P2P ()
import Cardano.Node.Tracing.Tracers.Peer ()
Expand Down Expand Up @@ -267,6 +266,8 @@ mkConsensusTracers configReflection trBase trForward mbTrEKG _trDataPoint trConf
["BlockFetch", "Server"]
configureTracers configReflection trConfig [blockFetchServerTr]

!servedBlockLatestTr <- servedBlockLatest mbTrEKG

!forgeKESInfoTr <- mkCardanoTracer
trBase trForward mbTrEKG
["Forge", "StateInfo"]
Expand Down Expand Up @@ -339,6 +340,7 @@ mkConsensusTracers configReflection trBase trForward mbTrEKG _trDataPoint trConf
<> traceWith blockFetchClientMetricsTr
, Consensus.blockFetchServerTracer = Tracer $
traceWith blockFetchServerTr
<> traceWith servedBlockLatestTr
, Consensus.forgeStateInfoTracer = Tracer $
traceWith (traceAsKESInfo (Proxy @blk) forgeKESInfoTr)
, Consensus.txInboundTracer = Tracer $
Expand Down
59 changes: 59 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Cardano.Node.Tracing.Tracers.Consensus
, forgeTracerTransform
, initialClientMetrics
, calculateBlockFetchClientMetrics
, servedBlockLatest
, ClientMetrics
) where

Expand Down Expand Up @@ -869,6 +870,64 @@ instance MetaTrace (TraceBlockFetchServerEvent blk) where

allNamespaces = [Namespace [] ["SendBlock"]]

--------------------------------------------------------------------------------
-- Metric for server block latest
--------------------------------------------------------------------------------

data ServedBlock = ServedBlock {
maxSlotNo :: SlotNo
, localUp :: Word64
, servedBlocksLatest :: Word64
}

instance MetaTrace ServedBlock where
namespaceFor ServedBlock {} =
Namespace [] ["ServedBlockLatest"]

severityFor (Namespace [] ["ServedBlockLatest"]) _ = Just
Debug
severityFor _ _ = Nothing

documentFor _ = Nothing

metricsDocFor (Namespace [] ["ServedBlockLatest"]) =
[("served.block.latest", "")]
metricsDocFor _ = []

allNamespaces = [Namespace [] ["ServedBlockLatest"]]


instance LogFormatting ServedBlock where
forMachine _mDtal ServedBlock {} = mempty

asMetrics ServedBlock {..} =
[IntM "served.block.latest" (fromIntegral servedBlocksLatest)]


emptyServedBlocks :: ServedBlock
emptyServedBlocks = ServedBlock 0 0 0

servedBlockLatest ::
Maybe (Trace IO FormattedMessage)
-> IO (Trace IO (TraceLabelPeer peer (TraceBlockFetchServerEvent blk)))
servedBlockLatest mbTrEKG =
foldTraceM calculateServedBlockLatest emptyServedBlocks
(metricsFormatter
(mkMetricsTracer mbTrEKG))

calculateServedBlockLatest :: ServedBlock
-> LoggingContext
-> TraceLabelPeer peer (TraceBlockFetchServerEvent blk)
-> IO ServedBlock
calculateServedBlockLatest ServedBlock{..} _lc (TraceLabelPeer _ (TraceBlockFetchServerSendBlock p)) =
case pointSlot p of
Origin -> return $ ServedBlock maxSlotNo localUp servedBlocksLatest
At slotNo ->
case compare maxSlotNo slotNo of
LT -> return $ ServedBlock slotNo (localUp + 1) (localUp + 1)
GT -> return $ ServedBlock maxSlotNo localUp servedBlocksLatest
EQ -> return $ ServedBlock maxSlotNo (localUp + 1) (localUp + 1)

--------------------------------------------------------------------------------
-- TxInbound Tracer
--------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ instance ( Show (BlockNodeToNodeVersion blk)
NotEffective -> 0
)]
asMetrics (BICommon BasicInfoCommon {..}) =
[ PrometheusM "basicInfo" [("nodeStartTime", (pack . show) biNodeStartTime)]]
[ PrometheusM "basicInfo" [("nodeStartTime", (pack . show) biNodeStartTime)]
, IntM "node.start.time" ((ceiling . utcTimeToPOSIXSeconds) biNodeStartTime)
]
asMetrics _ = []

instance MetaTrace (StartupTrace blk) where
Expand Down

0 comments on commit 3e0ce34

Please sign in to comment.