Skip to content

Commit

Permalink
cardano-node: initial NodeVersionTracer
Browse files Browse the repository at this point in the history
  • Loading branch information
jutaro committed Apr 7, 2024
1 parent 04e060e commit 2b2eabf
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 3 deletions.
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
2 changes: 2 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ data Tracers peer localPeer blk p2p = Tracers
, diffusionTracersExtra :: !(Diffusion.ExtraTracers p2p)

, startupTracer :: !(Tracer IO (StartupTrace blk))
, nodeVersionTracer :: !(Tracer IO NodeVersion)
, shutdownTracer :: !(Tracer IO ShutdownTrace)
, nodeInfoTracer :: !(Tracer IO NodeInfo)
, nodeVersionTracer :: !(Tracer IO NodeVersion)
, nodeStartupInfoTracer :: !(Tracer IO NodeStartupInfo)
, nodeStateTracer :: !(Tracer IO NodeState)
, resourcesTracer :: !(Tracer IO ResourceStats)
Expand Down
98 changes: 98 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,98 @@
module Cardano.Node.Tracing.Tracers.NodeVersion
(
NodeVersion (..)
)
where

import Cardano.Git.Rev (gitRev)
import Data.Version
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 compilerName
compilerVersion = compilerVersion
gitRevision = gitRev
in NodeVersion {..}

instance MetaTrace NodeVersionTrace where
namespaceFor NodeVersion {} =
Namespace [] ["NodeVersion"]
severityFor (Namespace _ ["NodeVersion"]) _ = Just Info
severityFor _ _ = Nothing
documentFor NodeVersion {} = Just "Node version information"
documentFor _ = Nothing
metricsDocFor NodeVersion {} =
[("Cardano.Version.Major", "Cardano node version information")
,("Cardano.Version.Minor", "Cardano node version information")
,("Cardano.Version.Patch", "Cardano node version information")
,("Cardano.Version.VersionTags", "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.CompilerTags", "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")
]
allNamespaces = [Namespace [] ["NodeVersion"]]


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

forMachine dtal NodeVersionTrace {..} = mconcat
[ "applicationName" .= applicationName
, "applicationVersion" .= toJSON applicationVersion
, "osName" .= osName
, "architecture" .= architecture
, "compilerName" .= compilerName
, "compilerVersion" .= toJSON compilerVersion
, "gitRevision" .= gitRevision]

asMetrics nvt@NodeVersionTrace {..} = mconcat
[ IntM "Cardano.Version.Major" (fromIntegral (getMajor applicationVersion))
, IntM "Cardano.Version.Minor" (fromIntegral (getMinor applicationVersion))
, IntM "Cardano.Version.Patch" (fromIntegral (getPatch applicationVersion))
, IntM ("Cardano.Version.VersionTags " ++ getVersionTags applicationVersion) 1
, IntM ("Cardano.Version.GitRevision " ++ gitRevision) 1
, IntM ("Cardano.CompilerName " ++ compilerName) 1
, IntM ("Cardano.CompilerMajor " (fromIntegral (getMajor applicationVersion)))
, IntM ("Cardano.CompilerMinor " (fromIntegral (getMinor applicationVersion)))
, IntM ("Cardano.CompilerPatch " (fromIntegral (getPatch applicationVersion)))
, IntM ("Cardano.CompilerTags " ++ getVersionTags applicationVersion) 1
, 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 {..} = showVersion applicationVersion

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

15 changes: 12 additions & 3 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,10 @@ import Cardano.Logging
import Cardano.Node.Configuration.POM (NodeConfiguration, ncProtocol)
import Cardano.Node.Configuration.Socket
import Cardano.Node.Protocol (SomeConsensusProtocol (..))
-- import Cardano.Node.Protocol.Types (Protocol (..))

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 @@ -53,7 +56,8 @@ import qualified Data.Map.Strict as Map
import Data.Text (Text, pack)
import Data.Time (getCurrentTime)
import Data.Time.Clock.POSIX (POSIXTime, utcTimeToPOSIXSeconds)
import Data.Version (showVersion)
-- import Data.Version (showVersion, versionBranch)

import Network.Socket (SockAddr)

import Paths_cardano_node (version)
Expand Down Expand Up @@ -118,6 +122,8 @@ getStartupInfo nc (SomeConsensusProtocol whichP pForInfo) fp = do
$ Gen.configEpochSlots genesis
}



-- --------------------------------------------------------------------------------
-- -- StartupInfo Tracer
-- --------------------------------------------------------------------------------
Expand Down Expand Up @@ -269,11 +275,14 @@ instance ( Show (BlockNodeToNodeVersion blk)
mconcat [ "kind" .= String "BasicInfoCommon"
, "configPath" .= String (pack biConfigPath)
, "networkMagic" .= String (showT biNetworkMagic)
, "protocol" .= String biProtocol
, "version" .= String biVersion
, "protocol" .= String (showT biProtocol)
, "version" .= String (showT biVersion)
, "commit" .= String biCommit
, "nodeStartTime" .= biNodeStartTime
]
asMetrics (BICommon BasicInfoCommon {}) = [] --undefined
asMetrics _ = []


instance MetaTrace (StartupTrace blk) where
namespaceFor StartupInfo {} =
Expand Down

0 comments on commit 2b2eabf

Please sign in to comment.