Skip to content

Commit

Permalink
cardano-node: try node version metric for old-tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
jutaro committed May 5, 2024
1 parent cd203b0 commit 004de7d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cardano-node/src/Cardano/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ import Paths_cardano_node (version)

import qualified Cardano.Crypto.Init as Crypto

import Cardano.Node.Tracing.Tracers.NodeVersion (getNodeVersion)

import Cardano.Node.Configuration.Logging (LoggingLayer (..), createLoggingLayer,
nodeBasicInfo, shutdownLoggingLayer)
import Cardano.Node.Configuration.NodeAddress
Expand Down Expand Up @@ -279,6 +281,9 @@ handleNodeWithTracers cmdPc nc0 p networkMagic blockType runP = do
getStartupInfo nc p fp
>>= mapM_ (traceWith $ startupTracer tracers)

traceWith (nodeVersionTracer tracers) getNodeVersion


blockForging <- snd (Api.protocolInfo runP)
traceWith (startupTracer tracers)
(BlockForgingUpdate (if null blockForging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Cardano.Node.Tracing.Tracers.NodeVersion
(
NodeVersionTrace (..)
, getNodeVersion
, getCardanoBuildInfo
)
where

Expand Down
38 changes: 37 additions & 1 deletion cardano-node/src/Cardano/Tracing/Tracers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import qualified Cardano.Node.STM as STM
import Cardano.Node.Startup

import Cardano.Node.TraceConstraints
import Cardano.Node.Tracing.Tracers.NodeVersion

import Cardano.Node.Tracing
import Cardano.Protocol.TPraos.OCert (KESPeriod (..))
import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..), WithOrigin (..))
Expand Down Expand Up @@ -343,11 +345,11 @@ mkTracers blockConfig tOpts@(TracingOnLegacy trSel) tr nodeKern ekgDirect enable
<> Tracer (\(ev :: StartupTrace blk) -> traceForgeEnabledMetric ekgDirect ev)

, shutdownTracer = toLogObject' verb $ appendName "shutdown" tr
, nodeVersionTracer = Tracer (\(ev :: NodeVersionTrace) -> traceVersionMetric ekgDirect ev)
-- The remaining tracers are completely unused by the legacy tracing:
, nodeInfoTracer = nullTracer
, nodeStartupInfoTracer = nullTracer
, nodeStateTracer = nullTracer
, nodeVersionTracer = nullTracer
, resourcesTracer = nullTracer
, peersTracer = nullTracer
}
Expand All @@ -364,6 +366,18 @@ mkTracers blockConfig tOpts@(TracingOnLegacy trSel) tr nodeKern ekgDirect enable
NotEffective -> 0 :: Int)
_ -> pure ()
Nothing -> pure ()
traceVersionMetric :: Maybe EKGDirect -> NodeVersionTrace -> IO ()
traceVersionMetric mbEKGDirect ev =
case mbEKGDirect of
Just ekgDirect' ->
case ev of
NodeVersionTrace {} ->
sendEKGDirectPrometheusLabel
ekgDirect'
"cardano_build_info"
(getCardanoBuildInfo ev)
Nothing -> pure ()


diffusionTracers = Diffusion.Tracers
{ Diffusion.dtMuxTracer = muxTracer
Expand Down Expand Up @@ -661,6 +675,28 @@ sendEKGDirectDouble ekgDirect name val = do
Label.set label (Text.pack (show val))
pure $ Map.insert name label registeredMap

sendEKGDirectPrometheusLabel :: EKGDirect -> Text -> [(Text,Text)] -> IO ()
sendEKGDirectPrometheusLabel ekgDirect name labels = do
modifyMVar_ (ekgLabels ekgDirect) $ \registeredMap -> do
case Map.lookup name registeredMap of
Just label -> do
Label.set label (presentPrometheusM labels)
pure registeredMap
Nothing -> do
label <- EKG.getLabel name (ekgServer ekgDirect)
Label.set label (presentPrometheusM labels)
pure $ Map.insert name label registeredMap
where
presentPrometheusM :: [(Text, Text)] -> Text
presentPrometheusM =
label . map pair
where
label pairs = "{" <> Text.intercalate "," pairs <> "} 1"
pair (k, v) = k <> "=\"" <> v <> "\""




--------------------------------------------------------------------------------
-- Consensus Tracers
--------------------------------------------------------------------------------
Expand Down

0 comments on commit 004de7d

Please sign in to comment.