Skip to content

Commit

Permalink
cardano-node: NodeVersionTracer
Browse files Browse the repository at this point in the history
Added for metrics
  • Loading branch information
jutaro committed Apr 16, 2024
1 parent 3f5181c commit 21d7eed
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 0 deletions.
1 change: 1 addition & 0 deletions cardano-node/cardano-node.cabal
Expand Up @@ -113,6 +113,7 @@ library
Cardano.Node.Tracing.Tracers.KESInfo
Cardano.Node.Tracing.Tracers.NodeToClient
Cardano.Node.Tracing.Tracers.NodeToNode
Cardano.Node.Tracing.Tracers.NodeVersion
Cardano.Node.Tracing.Tracers.NonP2P
Cardano.Node.Tracing.Tracers.P2P
Cardano.Node.Tracing.Tracers.Peer
Expand Down
3 changes: 3 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing.hs
Expand Up @@ -16,6 +16,8 @@ import Cardano.Node.Tracing.StateRep (NodeState)
import Cardano.Node.Tracing.Tracers.ConsensusStartupException
(ConsensusStartupException (..))
import Cardano.Node.Tracing.Tracers.Peer (PeerT)
import Cardano.Node.Tracing.Tracers.NodeVersion (NodeVersionTrace)

import qualified Ouroboros.Consensus.Network.NodeToClient as NodeToClient
import qualified Ouroboros.Consensus.Network.NodeToNode as NodeToNode
import qualified Ouroboros.Consensus.Node.Tracers as Consensus
Expand Down Expand Up @@ -48,6 +50,7 @@ data Tracers peer localPeer blk p2p = Tracers
, startupTracer :: !(Tracer IO (StartupTrace blk))
, shutdownTracer :: !(Tracer IO ShutdownTrace)
, nodeInfoTracer :: !(Tracer IO NodeInfo)
, nodeVersionTracer :: !(Tracer IO NodeVersionTrace)
, nodeStartupInfoTracer :: !(Tracer IO NodeStartupInfo)
, nodeStateTracer :: !(Tracer IO NodeState)
, resourcesTracer :: !(Tracer IO ResourceStats)
Expand Down
6 changes: 6 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/Consistency.hs
Expand Up @@ -27,6 +27,8 @@ import Cardano.Node.Tracing.Tracers.Diffusion ()
import Cardano.Node.Tracing.Tracers.KESInfo ()
import Cardano.Node.Tracing.Tracers.NodeToClient ()
import Cardano.Node.Tracing.Tracers.NodeToNode ()
import Cardano.Node.Tracing.Tracers.NodeVersion (NodeVersionTrace)

import Cardano.Node.Tracing.Tracers.NonP2P ()
import Cardano.Node.Tracing.Tracers.P2P ()
import Cardano.Node.Tracing.Tracers.Peer
Expand Down Expand Up @@ -130,6 +132,9 @@ getAllNamespaces =
(allNamespaces :: [Namespace (StartupTrace blk)])
shutdownNS = map (nsGetTuple . nsReplacePrefix ["Shutdown"])
(allNamespaces :: [Namespace ShutdownTrace])
nodeVersionNS = map (nsGetTuple . nsReplacePrefix ["Version"])
(allNamespaces :: [Namespace NodeVersionTrace])

chainDBNS = map (nsGetTuple . nsReplacePrefix ["ChainDB"])
(allNamespaces :: [Namespace (ChainDB.TraceEvent blk)])
replayBlockNS = map (nsGetTuple . nsReplacePrefix ["ChainDB", "ReplayBlock"])
Expand Down Expand Up @@ -366,6 +371,7 @@ getAllNamespaces =
<> resourcesNS
<> startupNS
<> shutdownNS
<> nodeVersionNS
<> chainDBNS
<> replayBlockNS
-- Consensus
Expand Down
9 changes: 9 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/Documentation.hs
Expand Up @@ -35,6 +35,8 @@ import Cardano.Node.Tracing.Tracers.ForgingThreadStats (ForgeThreadSta
import Cardano.Node.Tracing.Tracers.KESInfo ()
import Cardano.Node.Tracing.Tracers.NodeToClient ()
import Cardano.Node.Tracing.Tracers.NodeToNode ()
import Cardano.Node.Tracing.Tracers.NodeVersion (NodeVersionTrace)

import Cardano.Node.Tracing.Tracers.NonP2P ()
import Cardano.Node.Tracing.Tracers.P2P ()
import Cardano.Node.Tracing.Tracers.Peer
Expand Down Expand Up @@ -192,6 +194,12 @@ docTracersFirstPhase condConfigFileName = do
nodeStartupInfoDpDoc <- documentTracer
(nodeStartupInfoDp :: Trace IO NodeStartupInfo)

nodeVersionTr <- mkCardanoTracer
trBase trForward mbTrEKG
["Version"]
configureTracers configReflection trConfig [nodeVersionTr]
nodeVersionDoc <- documentTracer (nodeVersionTr :: Trace IO NodeVersionTrace)

-- State tracer
stateTr <- mkCardanoTracer
trBase trForward mbTrEKG
Expand Down Expand Up @@ -677,6 +685,7 @@ docTracersFirstPhase condConfigFileName = do
<> resourcesTrDoc
<> startupTrDoc
<> shutdownTrDoc
<> nodeVersionDoc
<> peersTrDoc
<> chainDBTrDoc
<> replayBlockTrDoc
Expand Down
9 changes: 9 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/Tracers.hs
Expand Up @@ -33,6 +33,8 @@ import Cardano.Node.Tracing.Tracers.ForgingThreadStats (forgeThreadSta
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 @@ -125,6 +127,10 @@ mkDispatchTracers nodeKernel trBase trForward mbTrEKG trDataPoint trConfig enabl
!chainDBTr <- mkCardanoTracer' trBase trForward mbTrEKG ["ChainDB"]
withAddedToCurrentChainEmptyLimited
configureTracers configReflection trConfig [chainDBTr]

!nodeVersionTr <- mkCardanoTracer trBase trForward mbTrEKG ["Version"]
configureTracers configReflection trConfig [nodeVersionTr]

-- Filter out replayed blocks for this tracer
let chainDBTr' = filterTrace
(\case (_, ChainDB.TraceLedgerReplayEvent
Expand Down Expand Up @@ -170,6 +176,8 @@ mkDispatchTracers nodeKernel trBase trForward mbTrEKG trDataPoint trConfig enabl

traceEffectiveConfiguration trBase trForward trConfig

traceWith nodeVersionTr getNodeVersion

pure Tracers
{
chainDBTracer = Tracer (traceWith chainDBTr')
Expand All @@ -188,6 +196,7 @@ mkDispatchTracers nodeKernel trBase trForward mbTrEKG trDataPoint trConfig enabl
, nodeStartupInfoTracer = Tracer (traceWith nodeStartupInfoDP)
, nodeStateTracer = Tracer (traceWith stateTr)
<> Tracer (traceWith nodeStateDP)
, nodeVersionTracer = Tracer (traceWith nodeVersionTr)
, resourcesTracer = Tracer (traceWith resourcesTr)
, peersTracer = Tracer (traceWith peersTr)
<> Tracer (traceNodePeers nodePeersDP)
Expand Down
132 changes: 132 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/NodeVersion.hs
@@ -0,0 +1,132 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}

{-# OPTIONS_GHC -Wno-name-shadowing #-}

module Cardano.Node.Tracing.Tracers.NodeVersion
(
NodeVersionTrace (..)
, getNodeVersion
)
where

import Cardano.Logging
import Data.Aeson (toJSON, (.=))
import Data.Text (Text, pack)

import Data.Version (Version (..), showVersion)

import Cardano.Git.Rev (gitRev)

import Paths_cardano_node (version)
import System.Info (arch, compilerName, compilerVersion, os)



data NodeVersionTrace = NodeVersionTrace
{ applicationName :: Text
, applicationVersion :: Version
, osName :: Text
, architecture :: Text
, compilerName :: Text
, compilerVersion :: Version
, gitRevision :: Text
} deriving (Eq, Show)

getNodeVersion :: NodeVersionTrace
getNodeVersion =
let applicationName = "cardano-node"
applicationVersion = version
osName = pack os
architecture = pack arch
compilerName = pack System.Info.compilerName
compilerVersion = System.Info.compilerVersion

gitRevision = $(gitRev)
in NodeVersionTrace {..}

instance MetaTrace NodeVersionTrace where
namespaceFor NodeVersionTrace {} =
Namespace [] ["NodeVersion"]
severityFor (Namespace _ ["NodeVersion"]) _ = Just Info
severityFor _ _ = Nothing

documentFor (Namespace _ ["NodeVersion"]) = Just "Node version information"

documentFor _ = Nothing

metricsDocFor (Namespace _ ["NodeVersion"]) =
[("Cardano.Version.Major", "Cardano node version information")
,("Cardano.Version.Minor", "Cardano node version information")
,("Cardano.Version.Patch", "Cardano node version information")
,("Cardano.Version.GitRevision", "Cardano node version information")
,("Cardano.CompilerName", "Cardano compiler name")
,("Cardano.CompilerMajor", "Cardano compiler version information")
,("Cardano.CompilerMinor", "Cardano compiler version information")
,("Cardano.CompilerPatch", "Cardano compiler version information")
,("Cardano.OSName", "Cardano node operating system information")
,("Cardano.Architecture", "Cardano node architecture information")
,("Cardano_Build_Info", "Cardano node build info")
,("Haskell_Build_Info", "Haskell compiler build information")
]
metricsDocFor _ = []

allNamespaces = [Namespace [] ["NodeVersion"]]

instance LogFormatting NodeVersionTrace where
forHuman NodeVersionTrace {..} = mconcat
[ "cardano-node ", pack (showVersion applicationVersion)
, " git rev ", gitRevision
, " - ", pack os, "-", pack arch
, " - ", compilerName, "-", pack (showVersion compilerVersion)
]

forMachine _dtal NodeVersionTrace {..} = mconcat

[ "applicationName" .= applicationName
, "applicationVersion" .= toJSON applicationVersion
, "gitRevision" .= gitRevision
, "osName" .= osName
, "architecture" .= architecture
, "compilerName" .= compilerName
, "compilerVersion" .= toJSON compilerVersion
]

asMetrics nvt@NodeVersionTrace {..} =
[ IntM "Cardano.Version.Major" (fromIntegral (getMajor applicationVersion))
, IntM "Cardano.Version.Minor" (fromIntegral (getMinor applicationVersion))
, IntM "Cardano.Version.Patch" (fromIntegral (getPatch applicationVersion))
, IntM ("Cardano.Version.GitRevision " <> gitRevision) 1
, IntM ("Cardano.CompilerName " <> compilerName) 1
, IntM "Cardano.CompilerMajor " (fromIntegral (getMajor compilerVersion))
, IntM "Cardano.CompilerMinor " (fromIntegral (getMinor compilerVersion))
, IntM "Cardano.CompilerPatch " (fromIntegral (getPatch compilerVersion))
, IntM ("Cardano.OSName " <> osName) 1
, IntM ("Cardano.Architecture " <> architecture) 1
, IntM ("Cardano_Build_Info " <> getCardanoBuildInfo nvt) 1
, IntM ("Haskell_Build_Info " <> getHaskellBuildInfo nvt) 1
]

getCardanoBuildInfo :: NodeVersionTrace -> Text
getCardanoBuildInfo NodeVersionTrace {..} = pack $ showVersion applicationVersion


getHaskellBuildInfo :: NodeVersionTrace -> Text
getHaskellBuildInfo NodeVersionTrace {..} = pack $ showVersion compilerVersion

getMajor :: Version -> Int
getMajor (Version (x:_) _) = x
getMajor _ = 0

getMinor :: Version -> Int
getMinor (Version (_:x:_) _) = x
getMinor _ = 0


getPatch :: Version -> Int
getPatch (Version (_:_:x:_) _) = x
getPatch _ = 0



3 changes: 3 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs
Expand Up @@ -25,7 +25,9 @@ import Cardano.Logging
import Cardano.Node.Configuration.POM (NodeConfiguration, ncProtocol)
import Cardano.Node.Configuration.Socket
import Cardano.Node.Protocol (SomeConsensusProtocol (..))

import Cardano.Node.Startup

import Cardano.Slotting.Slot (EpochSize (..))
import qualified Ouroboros.Consensus.BlockchainTime.WallClock.Types as WCT
import Ouroboros.Consensus.Byron.Ledger.Conversions (fromByronEpochSlots,
Expand Down Expand Up @@ -54,6 +56,7 @@ import Data.Text (Text, pack)
import Data.Time (getCurrentTime)
import Data.Time.Clock.POSIX (POSIXTime, utcTimeToPOSIXSeconds)
import Data.Version (showVersion)

import Network.Socket (SockAddr)

import Paths_cardano_node (version)
Expand Down
4 changes: 4 additions & 0 deletions cardano-node/src/Cardano/Tracing/Tracers.hs
Expand Up @@ -161,6 +161,7 @@ nullTracersP2P = Tracers
, nodeInfoTracer = nullTracer
, nodeStartupInfoTracer = nullTracer
, nodeStateTracer = nullTracer
, nodeVersionTracer = nullTracer
, resourcesTracer = nullTracer
, peersTracer = nullTracer
}
Expand All @@ -178,6 +179,7 @@ nullTracersNonP2P = Tracers
, nodeInfoTracer = nullTracer
, nodeStartupInfoTracer = nullTracer
, nodeStateTracer = nullTracer
, nodeVersionTracer = nullTracer
, resourcesTracer = nullTracer
, peersTracer = nullTracer
}
Expand Down Expand Up @@ -341,6 +343,7 @@ mkTracers blockConfig tOpts@(TracingOnLegacy trSel) tr nodeKern ekgDirect enable
, nodeInfoTracer = nullTracer
, nodeStartupInfoTracer = nullTracer
, nodeStateTracer = nullTracer
, nodeVersionTracer = nullTracer
, resourcesTracer = nullTracer
, peersTracer = nullTracer
}
Expand Down Expand Up @@ -486,6 +489,7 @@ mkTracers _ _ _ _ _ enableP2P =
, nodeInfoTracer = nullTracer
, nodeStartupInfoTracer = nullTracer
, nodeStateTracer = nullTracer
, nodeVersionTracer = nullTracer
, resourcesTracer = nullTracer
, peersTracer = nullTracer
}
Expand Down
1 change: 1 addition & 0 deletions nix/workbench/service/tracing.nix
Expand Up @@ -86,6 +86,7 @@ let
"TxSubmission.Remote".severity = "Notice";
"TxSubmission.TxInbound".severity = "Debug";
"TxSubmission.TxOutbound".severity = "Notice";
"Version.NodeVersion".severity = "Info";
};
};

Expand Down

0 comments on commit 21d7eed

Please sign in to comment.