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

NodeVersion tracer for providing metrics #5764

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
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
30 changes: 19 additions & 11 deletions cardano-node/src/Cardano/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TupleSections #-}

{-# LANGUAGE TypeApplications #-}


{-# OPTIONS_GHC -Wno-unused-imports #-}

#if !defined(mingw32_HOST_OS)
Expand Down Expand Up @@ -74,6 +76,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 @@ -102,12 +106,12 @@ import qualified Ouroboros.Network.Diffusion.P2P as P2P
import Ouroboros.Network.NodeToClient (LocalAddress (..), LocalSocket (..))
import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..), ConnectionId,
PeerSelectionTargets (..), RemoteAddress)
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..))

import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..))
import Ouroboros.Network.Protocol.ChainSync.Codec
import Ouroboros.Network.Subscription (DnsSubscriptionTarget (..),
IPSubscriptionTarget (..))
import Ouroboros.Network.PeerSelection.Bootstrap
(UseBootstrapPeers (..))

import Cardano.Node.Configuration.Socket (SocketOrSocketInfo (..),
gatherConfiguredSockets, getSocketOrSocketInfoAddr)
Expand All @@ -124,11 +128,14 @@ import Cardano.Node.Protocol.Types
import Cardano.Node.Queries
import Cardano.Node.TraceConstraints (TraceConstraints)
import Cardano.Tracing.Tracers
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))
import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency, WarmValency)
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers)
import Ouroboros.Network.PeerSelection.LedgerPeers.Type (UseLedgerPeers)

import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))
import Ouroboros.Network.PeerSelection.PeerTrustable (PeerTrustable)
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers)

import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency, WarmValency)


{- HLINT ignore "Fuse concatMap/map" -}
{- HLINT ignore "Redundant <$>" -}
Expand Down Expand Up @@ -240,8 +247,8 @@ handleNodeWithTracers cmdPc nc0 p networkMagic blockType runP = do
blockForging <- snd (Api.protocolInfo runP)
traceWith (startupTracer tracers)
(BlockForgingUpdate (if null blockForging
then EnabledBlockForging
else DisabledBlockForging))
then DisabledBlockForging
else EnabledBlockForging))

handleSimpleNode blockType runP p2pMode tracers nc
(\nk -> do
Expand Down Expand Up @@ -280,12 +287,13 @@ 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
then EnabledBlockForging
else DisabledBlockForging))

then DisabledBlockForging
else EnabledBlockForging))

-- We ignore peer logging thread if it dies, but it will be killed
-- when 'handleSimpleNode' terminates.
Expand Down
3 changes: 3 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing.hs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
153 changes: 153 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/NodeVersion.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}

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

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

import Data.Aeson (toJSON, (.=))
import Data.Text (Text, pack)
import Data.Version (Version (..), showVersion)
#if MIN_VERSION_base(4,15,0)
import System.Info (arch, compilerName, fullCompilerVersion, os)
#else
import System.Info (arch, compilerName, compilerVersion, os)
#endif

import Cardano.Git.Rev (gitRev)
import Cardano.Logging

import Paths_cardano_node (version)



-- | Node version information

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

-- | Get the node version information

getComplierVersion :: Version
#if MIN_VERSION_base(4,15,0)
getComplierVersion = System.Info.fullCompilerVersion
#else
getComplierVersion = System.Info.compilerVersion
#endif

getNodeVersion :: NodeVersionTrace
getNodeVersion =
let applicationName = "cardano-node"
applicationVersion = version
osName = pack os
architecture = pack arch
compilerName = pack System.Info.compilerName
compilerVersion = getComplierVersion
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")
,("haskell_compiler_major", "Cardano compiler version information")
,("haskell_compiler_minor", "Cardano compiler version information")

#if MIN_VERSION_base(4,15,0)
,("haskell_compiler_patch", "Cardano compiler version information")
#endif
,("cardano_build_info", "Cardano node build info")
jutaro marked this conversation as resolved.
Show resolved Hide resolved
]
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 "haskell_compiler_major" (fromIntegral (getMajor compilerVersion))
, IntM "haskell_compiler_minor" (fromIntegral (getMinor compilerVersion))
#if MIN_VERSION_base(4,15,0)
, IntM "haskell_compiler_patch" (fromIntegral (getPatch compilerVersion))
#endif
, PrometheusM "cardano_build_info" (getCardanoBuildInfo nvt)
]

getCardanoBuildInfo :: NodeVersionTrace -> [(Text,Text)]
getCardanoBuildInfo NodeVersionTrace {..} =
[ ("version_major", pack (show (getMajor applicationVersion)))
, ("version_minor", pack (show (getMinor applicationVersion)))
, ("version_patch", pack (show (getPatch applicationVersion)))
, ("version", pack (showVersion applicationVersion))
, ("revision", gitRevision)
, ("compiler_name", compilerName)
, ("compiler_version", pack (showVersion compilerVersion))
, ("compiler_version_major", pack (show (getMajor compilerVersion)))
, ("compiler_version_minor", pack (show (getMinor compilerVersion)))
#if MIN_VERSION_base(4,15,0)
, ("compiler_version_patch", pack (show (getPatch compilerVersion)))
#endif
, ("architecture", architecture)
, ("os_name", osName)
]

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
Original file line number Diff line number Diff line change
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
Loading
Loading