Skip to content

Commit

Permalink
cardano-tracer: Eliminate cardano-node dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Icelandjack committed Mar 3, 2025
1 parent 6d25d88 commit 294435e
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 93 deletions.
92 changes: 0 additions & 92 deletions cardano-node/src/Cardano/Node/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,98 +169,6 @@ data BasicInfoNetwork = BasicInfoNetwork {
, niIpProducers :: IPSubscriptionTarget
}

data NodeInfo = NodeInfo
{ niName :: Text
, niProtocol :: Text
, niVersion :: Text
, niCommit :: Text
, niStartTime :: UTCTime
, niSystemStartTime :: UTCTime
} deriving (Eq, Generic, ToJSON, FromJSON, Show)

deriving instance (NFData NodeInfo)

instance MetaTrace NodeInfo where
namespaceFor NodeInfo {} =
Namespace [] ["NodeInfo"]
severityFor (Namespace _ ["NodeInfo"]) _ =
Just Info
severityFor _ns _ =
Nothing
documentFor (Namespace _ ["NodeInfo"]) = Just
"Basic information about this node collected at startup\
\\n\
\\n _niName_: Name of the node. \
\\n _niProtocol_: Protocol which this nodes uses. \
\\n _niVersion_: Software version which this node is using. \
\\n _niStartTime_: Start time of this node. \
\\n _niSystemStartTime_: How long did the start of the node took."
documentFor _ns =
Nothing
allNamespaces = [ Namespace [] ["NodeInfo"]]


-- | Prepare basic info about the node. This info will be sent to 'cardano-tracer'.
prepareNodeInfo
:: NodeConfiguration
-> SomeConsensusProtocol
-> TraceConfig
-> UTCTime
-> IO NodeInfo
prepareNodeInfo nc (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime = do
nodeName <- prepareNodeName
return $ NodeInfo
{ niName = nodeName
, niProtocol = pack . show . ncProtocol $ nc
, niVersion = pack . showVersion $ version
, niCommit = $(gitRev)
, niStartTime = nodeStartTime
, niSystemStartTime = systemStartTime
}
where
cfg = pInfoConfig $ fst $ Api.protocolInfo @IO pForInfo

systemStartTime :: UTCTime
systemStartTime =
case whichP of
Api.ByronBlockType ->
getSystemStartByron
Api.ShelleyBlockType ->
let DegenLedgerConfig cfgShelley = configLedger cfg
in getSystemStartShelley cfgShelley
Api.CardanoBlockType ->
let CardanoLedgerConfig _ cfgShelley cfgAllegra cfgMary cfgAlonzo cfgBabbage cfgConway = configLedger cfg
in minimum [ getSystemStartByron
, getSystemStartShelley cfgShelley
, getSystemStartShelley cfgAllegra
, getSystemStartShelley cfgMary
, getSystemStartShelley cfgAlonzo
, getSystemStartShelley cfgBabbage
, getSystemStartShelley cfgConway
]

getSystemStartByron = WCT.getSystemStart . getSystemStart . configBlock $ cfg
getSystemStartShelley = sgSystemStart . shelleyLedgerGenesis . shelleyLedgerConfig

prepareNodeName =
case tcNodeName tc of
Just aName -> return aName
Nothing -> do
-- The user didn't specify node's name in the configuration.
-- In this case we should form node's name as "host_port",
-- where 'host' is the machine's host name and 'port' is taken
-- from the '--port' CLI-parameter.

let suffix :: String
suffix
| SocketConfig{ncNodePortNumber = Last (Just port)} <- ncSocketConfig nc
= "_" <> show port
| otherwise
= ""

hostName <- getHostName
return (pack (hostName <> suffix))

-- | This information is taken from 'BasicInfoShelleyBased'. It is required for
-- 'cardano-tracer' service (particularly, for RTView).
data NodeStartupInfo = NodeStartupInfo {
Expand Down
2 changes: 1 addition & 1 deletion cardano-tracer/cardano-tracer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ library
, bimap
, blaze-html
, bytestring
, cardano-node
-- , cardano-node
, cborg
, containers
, contra-tracer
Expand Down
100 changes: 100 additions & 0 deletions trace-dispatcher/src/Cardano/Logging/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ module Cardano.Logging.Types (
, unfold
, TraceObject(..)
, PreFormatted(..)
, NodeInfo(..)
-- , prepareNodeInfo
) where


import Ouroboros.Network.Util.ShowProxy (ShowProxy (..))

import Codec.Serialise (Serialise (..))
import Control.DeepSeq (NFData)
import qualified Control.Tracer as T
import qualified Data.Aeson as AE
import qualified Data.Aeson.Encoding as AE
Expand Down Expand Up @@ -561,3 +564,100 @@ instance Serialise LoggingContext
instance Serialise TraceObject

instance ShowProxy TraceObject

--

-- TODO: experimental

data NodeInfo = NodeInfo
{ niName :: Text
, niProtocol :: Text
, niVersion :: Text
, niCommit :: Text
, niStartTime :: UTCTime
, niSystemStartTime :: UTCTime
} deriving (Eq, Generic, AE.ToJSON, AE.FromJSON, Show)

deriving instance (NFData NodeInfo)

instance MetaTrace NodeInfo where
namespaceFor NodeInfo {} =
Namespace [] ["NodeInfo"]
severityFor (Namespace _ ["NodeInfo"]) _ =
Just Info
severityFor _ns _ =
Nothing
documentFor (Namespace _ ["NodeInfo"]) = Just
"Basic information about this node collected at startup\
\\n\
\\n _niName_: Name of the node. \
\\n _niProtocol_: Protocol which this nodes uses. \
\\n _niVersion_: Software version which this node is using. \
\\n _niStartTime_: Start time of this node. \
\\n _niSystemStartTime_: How long did the start of the node took."
documentFor _ns =
Nothing
allNamespaces = [ Namespace [] ["NodeInfo"]]

-- -- | Prepare basic info about the node. This info will be sent to 'cardano-tracer'.
-- prepareNodeInfo
-- :: NodeConfiguration
-- -> SomeConsensusProtocol
-- -> TraceConfig
-- -> UTCTime
-- -> IO NodeInfo
-- prepareNodeInfo = undefined
-- prepareNodeInfo nc (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime = do
-- nodeName <- prepareNodeName
-- return $ NodeInfo
-- { niName = nodeName
-- , niProtocol = pack . show . ncProtocol $ nc
-- , niVersion = pack . showVersion $ version
-- , niCommit = $(gitRev)
-- , niStartTime = nodeStartTime
-- , niSystemStartTime = systemStartTime
-- }
-- where
-- cfg = pInfoConfig $ fst $ Api.protocolInfo @IO pForInfo

-- systemStartTime :: UTCTime
-- systemStartTime =
-- case whichP of
-- Api.ByronBlockType ->
-- getSystemStartByron
-- Api.ShelleyBlockType ->
-- let DegenLedgerConfig cfgShelley = configLedger cfg
-- in getSystemStartShelley cfgShelley
-- Api.CardanoBlockType ->
-- let CardanoLedgerConfig _ cfgShelley cfgAllegra cfgMary cfgAlonzo cfgBabbage cfgConway = configLedger cfg
-- in minimum [ getSystemStartByron
-- , getSystemStartShelley cfgShelley
-- , getSystemStartShelley cfgAllegra
-- , getSystemStartShelley cfgMary
-- , getSystemStartShelley cfgAlonzo
-- , getSystemStartShelley cfgBabbage
-- , getSystemStartShelley cfgConway
-- ]

-- getSystemStartByron = WCT.getSystemStart . getSystemStart . configBlock $ cfg
-- getSystemStartShelley = sgSystemStart . shelleyLedgerGenesis . shelleyLedgerConfig

-- prepareNodeName =
-- case tcNodeName tc of
-- Just aName -> return aName
-- Nothing -> do
-- -- The user didn't specify node's name in the configuration.
-- -- In this case we should form node's name as "host_port",
-- -- where 'host' is the machine's host name and 'port' is taken
-- -- from the '--port' CLI-parameter.

-- let suffix :: String
-- suffix
-- | SocketConfig{ncNodePortNumber = Last (Just port)} <- ncSocketConfig nc
-- = "_" <> show port
-- | otherwise
-- = ""

-- hostName <- getHostName
-- return (pack (hostName <> suffix))

0 comments on commit 294435e

Please sign in to comment.