Skip to content

Eliminate cardano-node dependency, add symbolic logging to cardano-tracer #6125

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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 bench/tx-generator/src/Cardano/Benchmarking/Tracer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Cardano.Benchmarking.Types
import Cardano.Benchmarking.Version as Version
import Cardano.Logging
import Cardano.Node.Startup
import Cardano.Node.Tracing.NodeInfo () -- MetaTrace NodeInfo
import Ouroboros.Network.IOManager (IOManager)

import Control.Monad (forM, guard)
Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ package plutus-scripts-bench
allow-newer:
, katip:Win32
, ekg-wai:time
, data-default

-- IMPORTANT
-- Do NOT add more source-repository-package stanzas here unless they are strictly
Expand Down
4 changes: 4 additions & 0 deletions cardano-node/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Next version

- Removed `cardano-node' as a dependency from `cardano-tracer'. This necessitated moving `NodeInfo` from
`cardano-tracer:Cardano.Node.Startup`to `trace-dispatcher:Cardano.Logging.Types.NodeInfo`, and `NodePeers` from
`cardano-node:Cardano.Node.Tracing.Peers` to `trace-dispatcher:Cardano.Logging.Types.NodePeers`.

- Add a new configuration field for fork-policy.

- Optionally support lightweight checkpointing.
Expand Down
4 changes: 3 additions & 1 deletion cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ library
Cardano.Node.TraceConstraints
Cardano.Node.Tracing
Cardano.Node.Tracing.API
Cardano.Node.Tracing.Consistency
Cardano.Node.Tracing.Compat
Cardano.Node.Tracing.Consistency
Cardano.Node.Tracing.DefaultTraceConfig
Cardano.Node.Tracing.Documentation
Cardano.Node.Tracing.Era.Byron
Cardano.Node.Tracing.Era.HardFork
Cardano.Node.Tracing.Era.Shelley
Cardano.Node.Tracing.Formatting
Cardano.Node.Tracing.NodeInfo
Cardano.Node.Tracing.NodeStartupInfo
Cardano.Node.Tracing.Peers
Cardano.Node.Tracing.Render
Cardano.Node.Tracing.StateRep
Expand Down
88 changes: 17 additions & 71 deletions cardano-node/src/Cardano/Node/Startup.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
Expand All @@ -8,13 +9,19 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}

module Cardano.Node.Startup where
module Cardano.Node.Startup
( module Cardano.Node.Startup
, module Cardano.Logging.Types.NodeInfo
, module Cardano.Logging.Types.NodeStartupInfo
) where

import qualified Cardano.Api as Api

import Cardano.Git.Rev (gitRev)
import Cardano.Ledger.Shelley.Genesis (sgSystemStart)
import Cardano.Logging
import Cardano.Logging.Types.NodeInfo (NodeInfo (..))
import Cardano.Logging.Types.NodeStartupInfo (NodeStartupInfo (..))
import Cardano.Network.PeerSelection.PeerTrustable (PeerTrustable (..))
import Cardano.Node.Configuration.POM (NodeConfiguration (..), ncProtocol)
import Cardano.Node.Configuration.Socket
Expand Down Expand Up @@ -43,15 +50,12 @@ import Ouroboros.Network.Subscription.Ip (IPSubscriptionTarget (..))

import Prelude

import Control.DeepSeq (NFData)
import Data.Aeson (FromJSON, ToJSON)
import Data.Map.Strict (Map)
import Data.Monoid (Last (..))
import Data.Text (Text, pack)
import Data.Time.Clock (NominalDiffTime, UTCTime)
import Data.Version (showVersion)
import Data.Word (Word64)
import GHC.Generics (Generic)
import Network.HostName (getHostName)
import qualified Network.Socket as Socket

Expand Down Expand Up @@ -132,13 +136,15 @@ data StartupTrace blk =
| LedgerPeerSnapshotLoaded (WithOrigin SlotNo)
| MovedTopLevelOption String

data EnabledBlockForging = EnabledBlockForging
| DisabledBlockForging
| NotEffective
-- ^ one needs to send `SIGHUP` after consensus
-- initialised itself (especially after replying all
-- blocks).
deriving (Eq, Show)
data EnabledBlockForging
= EnabledBlockForging
| DisabledBlockForging
| NotEffective
-- ^ one needs to send `SIGHUP` after consensus
-- initialised itself (especially after replying all
-- blocks).
deriving stock
(Eq, Show)

data BasicInfoCommon = BasicInfoCommon {
biConfigPath :: FilePath
Expand Down Expand Up @@ -170,37 +176,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
Expand Down Expand Up @@ -261,32 +236,3 @@ prepareNodeInfo nc (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime = do

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 {
suiEra :: Text
, suiSlotLength :: NominalDiffTime
, suiEpochLength :: Word64
, suiSlotsPerKESPeriod :: Word64
} deriving (Eq, Generic, ToJSON, FromJSON, Show)

deriving instance (NFData NodeStartupInfo)

instance MetaTrace NodeStartupInfo where
namespaceFor NodeStartupInfo {} =
Namespace [] ["NodeStartupInfo"]
severityFor (Namespace _ ["NodeStartupInfo"]) _ =
Just Info
severityFor _ns _ =
Nothing
documentFor (Namespace _ ["NodeStartupInfo"]) = Just
"Startup information about this node, required for RTView\
\\n\
\\n _suiEra_: Name of the current era. \
\\n _suiSlotLength_: Slot length, in seconds. \
\\n _suiEpochLength_: Epoch length, in slots. \
\\n _suiSlotsPerKESPeriod_: KES period length, in slots."
documentFor _ns =
Nothing
allNamespaces = [ Namespace [] ["NodeStartupInfo"]]
3 changes: 2 additions & 1 deletion cardano-node/src/Cardano/Node/Tracing/Documentation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Cardano.Node.Tracing.Documentation
, docTracersFirstPhase
) where


import Cardano.Node.Tracing.NodeStartupInfo () -- MetaTrace NodeVersionTrace
import Cardano.Logging as Logging
import Cardano.Logging.Resources
import Cardano.Logging.Resources.Types ()
Expand All @@ -28,6 +28,7 @@ import Cardano.Node.Startup
import Cardano.Node.TraceConstraints
import Cardano.Node.Tracing.DefaultTraceConfig (defaultCardanoConfig)
import Cardano.Node.Tracing.Formatting ()
import Cardano.Node.Tracing.NodeInfo ()
import qualified Cardano.Node.Tracing.StateRep as SR
import Cardano.Node.Tracing.Tracers.BlockReplayProgress
import Cardano.Node.Tracing.Tracers.ChainDB
Expand Down
27 changes: 27 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/NodeInfo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Cardano.Node.Tracing.NodeInfo
( NodeInfo (..)
) where

import Cardano.Logging.Types.NodeInfo (NodeInfo (..))
import Cardano.Logging.Types (MetaTrace(..), Namespace (..), SeverityS (..))

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"]]
26 changes: 26 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/NodeStartupInfo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Cardano.Node.Tracing.NodeStartupInfo
( NodeStartupInfo (..)
) where

import Cardano.Logging.Types.NodeStartupInfo (NodeStartupInfo (..))
import Cardano.Logging.Types (MetaTrace(..), Namespace (..), SeverityS (..))

instance MetaTrace NodeStartupInfo where
namespaceFor NodeStartupInfo {} =
Namespace [] ["NodeStartupInfo"]
severityFor (Namespace _ ["NodeStartupInfo"]) _ =
Just Info
severityFor _ns _ =
Nothing
documentFor (Namespace _ ["NodeStartupInfo"]) = Just
"Startup information about this node, required for RTView\
\\n\
\\n _suiEra_: Name of the current era. \
\\n _suiSlotLength_: Slot length, in seconds. \
\\n _suiEpochLength_: Epoch length, in slots. \
\\n _suiSlotsPerKESPeriod_: KES period length, in slots."
documentFor _ns =
Nothing
allNamespaces = [ Namespace [] ["NodeStartupInfo"]]
23 changes: 2 additions & 21 deletions cardano-node/src/Cardano/Node/Tracing/Peers.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Cardano.Node.Tracing.Peers
( NodePeers (..)
Expand All @@ -9,24 +7,7 @@ module Cardano.Node.Tracing.Peers

import Cardano.Logging
import Cardano.Node.Tracing.Tracers.Peer (PeerT, ppPeer)

import Control.DeepSeq (NFData)
import Data.Aeson (FromJSON, ToJSON)
import Data.Text (Text)
import GHC.Generics (Generic)

type PeerInfoPP = Text -- The result of 'ppPeer' function.

-- | This type contains an information about current peers of the node.
-- It will be asked by external applications as a DataPoint.
newtype NodePeers = NodePeers [PeerInfoPP]

deriving instance Generic NodePeers
deriving instance NFData NodePeers

instance ToJSON NodePeers
instance FromJSON NodePeers

import Cardano.Logging.Types.NodePeers (NodePeers(..))

instance MetaTrace NodePeers where
namespaceFor NodePeers {} =
Expand Down
3 changes: 1 addition & 2 deletions cardano-node/src/Cardano/Node/Tracing/Tracers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Cardano.Node.TraceConstraints
import Cardano.Node.Tracing
import Cardano.Node.Tracing.Consistency (checkNodeTraceConfiguration')
import Cardano.Node.Tracing.Formatting ()
import Cardano.Node.Tracing.Peers
import Cardano.Node.Tracing.Peers (traceNodePeers)
import qualified Cardano.Node.Tracing.StateRep as SR
import Cardano.Node.Tracing.Tracers.BlockReplayProgress
import Cardano.Node.Tracing.Tracers.ChainDB
Expand All @@ -37,7 +37,6 @@ 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 ()
import Cardano.Node.Tracing.Tracers.Shutdown ()
import Cardano.Node.Tracing.Tracers.Startup ()
import qualified Ouroboros.Cardano.Network.PeerSelection.Governor.PeerSelectionState as Cardano
Expand Down
29 changes: 14 additions & 15 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/Peer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,27 @@ startPeerTracer tracer nodeKernel delayMilliseconds = do
traceWith tracer peers
threadDelay (delayMilliseconds * 1000)


data PeerT blk = PeerT
RemoteConnectionId
(Net.AnchoredFragment (Header blk))
(PeerFetchStatus (Header blk))
(PeerFetchInFlight (Header blk))


ppPeer :: PeerT blk -> Text
ppPeer (PeerT cid _af status inflight) =
Text.pack $ printf "%-15s %-8s %s" (ppCid cid) (ppStatus status) (ppInFlight inflight)

ppCid :: RemoteConnectionId -> String
ppCid = takeWhile (/= ':') . show . remoteAddress
where
ppCid :: RemoteConnectionId -> String
ppCid = takeWhile (/= ':') . show . remoteAddress

ppInFlight :: PeerFetchInFlight header -> String
ppInFlight f = printf
"%5s %3d %5d %6d"
(ppMaxSlotNo $ peerFetchMaxSlotNo f)
(peerFetchReqsInFlight f)
(Set.size $ peerFetchBlocksInFlight f)
(peerFetchBytesInFlight f)

ppMaxSlotNo :: Net.MaxSlotNo -> String
ppMaxSlotNo Net.NoMaxSlotNo = "???"
ppMaxSlotNo (Net.MaxSlotNo x) = show (unSlotNo x)
ppInFlight :: PeerFetchInFlight header -> String
ppInFlight f = printf
"%5s %3d %5d %6d"
(ppMaxSlotNo $ peerFetchMaxSlotNo f)
(peerFetchReqsInFlight f)
(Set.size $ peerFetchBlocksInFlight f)
(peerFetchBytesInFlight f)

ppStatus :: PeerFetchStatus header -> String
ppStatus = \case
Expand All @@ -103,6 +98,10 @@ ppStatus = \case
PeerFetchStatusBusy -> "fetching"
PeerFetchStatusReady {} -> "ready"

ppMaxSlotNo :: Net.MaxSlotNo -> String
ppMaxSlotNo Net.NoMaxSlotNo = "???"
ppMaxSlotNo (Net.MaxSlotNo x) = show (unSlotNo x)

getCurrentPeers
:: NodeKernelData blk
-> IO [PeerT blk]
Expand Down
5 changes: 5 additions & 0 deletions cardano-tracer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog

## 0.3.3 (April, 2025)
* Removed `cardano-node' as a dependency from `cardano-tracer'. This necessitated moving `NodeInfo` from
`cardano-tracer:Cardano.Node.Startup`to `trace-dispatcher:Cardano.Logging.Types.NodeInfo`, and `NodePeers` from
`cardano-node:Cardano.Node.Tracing.Peers` to `trace-dispatcher:Cardano.Logging.Types.NodePeers`.

## 0.3.2 (March 2025)

* When requesting forwarded metrics, ask for delta to previous request only. New config option `ekgRequestFull` defaults to `false`; set to `true` to revert this behavior.
Expand Down
Loading
Loading