From 3e0ce348b721501c391acfc92f281e2bb8fb10a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Nicklisch-Franken?= Date: Wed, 18 Sep 2024 15:44:44 +0200 Subject: [PATCH] cardano-node: added metric served.block.latest --- .../src/Cardano/Node/Tracing/Tracers.hs | 4 +- .../Cardano/Node/Tracing/Tracers/Consensus.hs | 59 +++++++++++++++++++ .../Cardano/Node/Tracing/Tracers/Startup.hs | 4 +- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers.hs index dc12e1b5947..5ca7aa97042 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers.hs @@ -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 () @@ -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"] @@ -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 $ diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs index 27ca806f916..537a9d1dcd0 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs @@ -18,6 +18,7 @@ module Cardano.Node.Tracing.Tracers.Consensus , forgeTracerTransform , initialClientMetrics , calculateBlockFetchClientMetrics + , servedBlockLatest , ClientMetrics ) where @@ -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 -------------------------------------------------------------------------------- diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs index d1c7854b508..28450f9142d 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs @@ -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