diff --git a/cardano-node/cardano-node.cabal b/cardano-node/cardano-node.cabal index 71d36936283..f67d12dc443 100644 --- a/cardano-node/cardano-node.cabal +++ b/cardano-node/cardano-node.cabal @@ -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 diff --git a/cardano-node/src/Cardano/Node/Tracing.hs b/cardano-node/src/Cardano/Node/Tracing.hs index 148322d5282..027d988d086 100644 --- a/cardano-node/src/Cardano/Node/Tracing.hs +++ b/cardano-node/src/Cardano/Node/Tracing.hs @@ -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 @@ -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) diff --git a/cardano-node/src/Cardano/Node/Tracing/Consistency.hs b/cardano-node/src/Cardano/Node/Tracing/Consistency.hs index d80519bebd6..24a87e6a34a 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Consistency.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Consistency.hs @@ -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 @@ -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"]) @@ -366,6 +371,7 @@ getAllNamespaces = <> resourcesNS <> startupNS <> shutdownNS + <> nodeVersionNS <> chainDBNS <> replayBlockNS -- Consensus diff --git a/cardano-node/src/Cardano/Node/Tracing/Documentation.hs b/cardano-node/src/Cardano/Node/Tracing/Documentation.hs index bef9d5cb87b..211b84bcd56 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Documentation.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Documentation.hs @@ -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 @@ -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 @@ -677,6 +685,7 @@ docTracersFirstPhase condConfigFileName = do <> resourcesTrDoc <> startupTrDoc <> shutdownTrDoc + <> nodeVersionDoc <> peersTrDoc <> chainDBTrDoc <> replayBlockTrDoc diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers.hs index b62ed90e8ac..9cdc8b161da 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers.hs @@ -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 () @@ -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 @@ -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') @@ -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) diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/NodeVersion.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/NodeVersion.hs new file mode 100644 index 00000000000..f2d0d1de930 --- /dev/null +++ b/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 + + + diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs index edbc2c2ffd3..d275072e392 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs @@ -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, @@ -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) diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index 497e4879d0e..99eabc81f62 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -161,6 +161,7 @@ nullTracersP2P = Tracers , nodeInfoTracer = nullTracer , nodeStartupInfoTracer = nullTracer , nodeStateTracer = nullTracer + , nodeVersionTracer = nullTracer , resourcesTracer = nullTracer , peersTracer = nullTracer } @@ -178,6 +179,7 @@ nullTracersNonP2P = Tracers , nodeInfoTracer = nullTracer , nodeStartupInfoTracer = nullTracer , nodeStateTracer = nullTracer + , nodeVersionTracer = nullTracer , resourcesTracer = nullTracer , peersTracer = nullTracer } @@ -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 } @@ -486,6 +489,7 @@ mkTracers _ _ _ _ _ enableP2P = , nodeInfoTracer = nullTracer , nodeStartupInfoTracer = nullTracer , nodeStateTracer = nullTracer + , nodeVersionTracer = nullTracer , resourcesTracer = nullTracer , peersTracer = nullTracer } diff --git a/nix/workbench/service/tracing.nix b/nix/workbench/service/tracing.nix index 1f661802d75..e2ff2b14b0d 100644 --- a/nix/workbench/service/tracing.nix +++ b/nix/workbench/service/tracing.nix @@ -86,6 +86,7 @@ let "TxSubmission.Remote".severity = "Notice"; "TxSubmission.TxInbound".severity = "Debug"; "TxSubmission.TxOutbound".severity = "Notice"; + "Version.NodeVersion".severity = "Info"; }; };