Skip to content

Commit 77b69d8

Browse files
authored
Merge pull request #6125 from IntersectMBO/baldurb/symlink
Eliminate `cardano-node` dependency from `cardano-tracer`
2 parents edf2baa + 13c5018 commit 77b69d8

File tree

27 files changed

+405
-240
lines changed

27 files changed

+405
-240
lines changed

bench/tx-generator/src/Cardano/Benchmarking/Tracer.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import Cardano.Benchmarking.Types
3333
import Cardano.Benchmarking.Version as Version
3434
import Cardano.Logging
3535
import Cardano.Node.Startup
36+
import Cardano.Node.Tracing.NodeInfo () -- MetaTrace NodeInfo
3637
import Ouroboros.Network.IOManager (IOManager)
3738

3839
import Control.Monad (forM, guard)

cardano-node/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Next version
44

5+
* Removed `cardano-node' as a dependency from `cardano-tracer'. This necessitated moving `NodeInfo`
6+
(from `cardano-tracer:Cardano.Node.Startup` to `trace-dispatcher:Cardano.Logging.Types.NodeInfo`), `NodePeers`
7+
(from `cardano-node:Cardano.Node.Tracing.Peers` to `trace-dispatcher:Cardano.Logging.Types.NodePeers`), and
8+
`NodeStartupInfo` (from `cardano-tracer:Cardano.Node.Startup` to `cardano-node:Cardano.Node.Tracing.NodeStartupInfo.hs`).
9+
510
- Add a new configuration field for fork-policy.
611

712
- Optionally support lightweight checkpointing.

cardano-node/cardano-node.cabal

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,16 @@ library
9494
Cardano.Node.TraceConstraints
9595
Cardano.Node.Tracing
9696
Cardano.Node.Tracing.API
97-
Cardano.Node.Tracing.Consistency
9897
Cardano.Node.Tracing.Compat
98+
Cardano.Node.Tracing.Consistency
9999
Cardano.Node.Tracing.DefaultTraceConfig
100100
Cardano.Node.Tracing.Documentation
101101
Cardano.Node.Tracing.Era.Byron
102102
Cardano.Node.Tracing.Era.HardFork
103103
Cardano.Node.Tracing.Era.Shelley
104104
Cardano.Node.Tracing.Formatting
105+
Cardano.Node.Tracing.NodeInfo
106+
Cardano.Node.Tracing.NodeStartupInfo
105107
Cardano.Node.Tracing.Peers
106108
Cardano.Node.Tracing.Render
107109
Cardano.Node.Tracing.StateRep
@@ -215,7 +217,7 @@ library
215217
, sop-extras
216218
, text >= 2.0
217219
, time
218-
, trace-dispatcher ^>= 2.9
220+
, trace-dispatcher ^>= 2.9.1
219221
, trace-forward ^>= 2.2.11
220222
, trace-resources ^>= 0.2.3
221223
, tracer-transformers

cardano-node/src/Cardano/Node/Startup.hs

Lines changed: 17 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE DeriveAnyClass #-}
22
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE DerivingStrategies #-}
34
{-# LANGUAGE FlexibleContexts #-}
45
{-# LANGUAGE GADTs #-}
56
{-# LANGUAGE MultiParamTypeClasses #-}
@@ -8,13 +9,19 @@
89
{-# LANGUAGE TypeApplications #-}
910
{-# LANGUAGE UndecidableInstances #-}
1011

11-
module Cardano.Node.Startup where
12+
module Cardano.Node.Startup
13+
( module Cardano.Node.Startup
14+
, module Cardano.Logging.Types.NodeInfo
15+
, module Cardano.Logging.Types.NodeStartupInfo
16+
) where
1217

1318
import qualified Cardano.Api as Api
1419

1520
import Cardano.Git.Rev (gitRev)
1621
import Cardano.Ledger.Shelley.Genesis (sgSystemStart)
1722
import Cardano.Logging
23+
import Cardano.Logging.Types.NodeInfo (NodeInfo (..))
24+
import Cardano.Logging.Types.NodeStartupInfo (NodeStartupInfo (..))
1825
import Cardano.Network.PeerSelection.PeerTrustable (PeerTrustable (..))
1926
import Cardano.Node.Configuration.POM (NodeConfiguration (..), ncProtocol)
2027
import Cardano.Node.Configuration.Socket
@@ -43,15 +50,12 @@ import Ouroboros.Network.Subscription.Ip (IPSubscriptionTarget (..))
4350

4451
import Prelude
4552

46-
import Control.DeepSeq (NFData)
47-
import Data.Aeson (FromJSON, ToJSON)
4853
import Data.Map.Strict (Map)
4954
import Data.Monoid (Last (..))
5055
import Data.Text (Text, pack)
5156
import Data.Time.Clock (NominalDiffTime, UTCTime)
5257
import Data.Version (showVersion)
5358
import Data.Word (Word64)
54-
import GHC.Generics (Generic)
5559
import Network.HostName (getHostName)
5660
import qualified Network.Socket as Socket
5761

@@ -132,13 +136,15 @@ data StartupTrace blk =
132136
| LedgerPeerSnapshotLoaded (WithOrigin SlotNo)
133137
| MovedTopLevelOption String
134138

135-
data EnabledBlockForging = EnabledBlockForging
136-
| DisabledBlockForging
137-
| NotEffective
138-
-- ^ one needs to send `SIGHUP` after consensus
139-
-- initialised itself (especially after replying all
140-
-- blocks).
141-
deriving (Eq, Show)
139+
data EnabledBlockForging
140+
= EnabledBlockForging
141+
| DisabledBlockForging
142+
| NotEffective
143+
-- ^ one needs to send `SIGHUP` after consensus
144+
-- initialised itself (especially after replying all
145+
-- blocks).
146+
deriving stock
147+
(Eq, Show)
142148

143149
data BasicInfoCommon = BasicInfoCommon {
144150
biConfigPath :: FilePath
@@ -170,37 +176,6 @@ data BasicInfoNetwork = BasicInfoNetwork {
170176
, niIpProducers :: IPSubscriptionTarget
171177
}
172178

173-
data NodeInfo = NodeInfo
174-
{ niName :: Text
175-
, niProtocol :: Text
176-
, niVersion :: Text
177-
, niCommit :: Text
178-
, niStartTime :: UTCTime
179-
, niSystemStartTime :: UTCTime
180-
} deriving (Eq, Generic, ToJSON, FromJSON, Show)
181-
182-
deriving instance (NFData NodeInfo)
183-
184-
instance MetaTrace NodeInfo where
185-
namespaceFor NodeInfo {} =
186-
Namespace [] ["NodeInfo"]
187-
severityFor (Namespace _ ["NodeInfo"]) _ =
188-
Just Info
189-
severityFor _ns _ =
190-
Nothing
191-
documentFor (Namespace _ ["NodeInfo"]) = Just
192-
"Basic information about this node collected at startup\
193-
\\n\
194-
\\n _niName_: Name of the node. \
195-
\\n _niProtocol_: Protocol which this nodes uses. \
196-
\\n _niVersion_: Software version which this node is using. \
197-
\\n _niStartTime_: Start time of this node. \
198-
\\n _niSystemStartTime_: How long did the start of the node took."
199-
documentFor _ns =
200-
Nothing
201-
allNamespaces = [ Namespace [] ["NodeInfo"]]
202-
203-
204179
-- | Prepare basic info about the node. This info will be sent to 'cardano-tracer'.
205180
prepareNodeInfo
206181
:: NodeConfiguration
@@ -261,32 +236,3 @@ prepareNodeInfo nc (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime = do
261236

262237
hostName <- getHostName
263238
return (pack (hostName <> suffix))
264-
265-
-- | This information is taken from 'BasicInfoShelleyBased'. It is required for
266-
-- 'cardano-tracer' service (particularly, for RTView).
267-
data NodeStartupInfo = NodeStartupInfo {
268-
suiEra :: Text
269-
, suiSlotLength :: NominalDiffTime
270-
, suiEpochLength :: Word64
271-
, suiSlotsPerKESPeriod :: Word64
272-
} deriving (Eq, Generic, ToJSON, FromJSON, Show)
273-
274-
deriving instance (NFData NodeStartupInfo)
275-
276-
instance MetaTrace NodeStartupInfo where
277-
namespaceFor NodeStartupInfo {} =
278-
Namespace [] ["NodeStartupInfo"]
279-
severityFor (Namespace _ ["NodeStartupInfo"]) _ =
280-
Just Info
281-
severityFor _ns _ =
282-
Nothing
283-
documentFor (Namespace _ ["NodeStartupInfo"]) = Just
284-
"Startup information about this node, required for RTView\
285-
\\n\
286-
\\n _suiEra_: Name of the current era. \
287-
\\n _suiSlotLength_: Slot length, in seconds. \
288-
\\n _suiEpochLength_: Epoch length, in slots. \
289-
\\n _suiSlotsPerKESPeriod_: KES period length, in slots."
290-
documentFor _ns =
291-
Nothing
292-
allNamespaces = [ Namespace [] ["NodeStartupInfo"]]

cardano-node/src/Cardano/Node/Tracing/Documentation.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Cardano.Node.Tracing.Documentation
1818
, docTracersFirstPhase
1919
) where
2020

21-
21+
import Cardano.Node.Tracing.NodeStartupInfo () -- MetaTrace NodeVersionTrace
2222
import Cardano.Logging as Logging
2323
import Cardano.Logging.Resources
2424
import Cardano.Logging.Resources.Types ()
@@ -28,6 +28,7 @@ import Cardano.Node.Startup
2828
import Cardano.Node.TraceConstraints
2929
import Cardano.Node.Tracing.DefaultTraceConfig (defaultCardanoConfig)
3030
import Cardano.Node.Tracing.Formatting ()
31+
import Cardano.Node.Tracing.NodeInfo ()
3132
import qualified Cardano.Node.Tracing.StateRep as SR
3233
import Cardano.Node.Tracing.Tracers.BlockReplayProgress
3334
import Cardano.Node.Tracing.Tracers.ChainDB
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{-# OPTIONS_GHC -fno-warn-orphans #-}
2+
3+
module Cardano.Node.Tracing.NodeInfo
4+
( NodeInfo (..)
5+
) where
6+
7+
import Cardano.Logging.Types.NodeInfo (NodeInfo (..))
8+
import Cardano.Logging.Types (MetaTrace(..), Namespace (..), SeverityS (..))
9+
10+
instance MetaTrace NodeInfo where
11+
namespaceFor NodeInfo {} =
12+
Namespace [] ["NodeInfo"]
13+
severityFor (Namespace _ ["NodeInfo"]) _ =
14+
Just Info
15+
severityFor _ns _ =
16+
Nothing
17+
documentFor (Namespace _ ["NodeInfo"]) = Just
18+
"Basic information about this node collected at startup\
19+
\\n\
20+
\\n _niName_: Name of the node. \
21+
\\n _niProtocol_: Protocol which this nodes uses. \
22+
\\n _niVersion_: Software version which this node is using. \
23+
\\n _niStartTime_: Start time of this node. \
24+
\\n _niSystemStartTime_: How long did the start of the node took."
25+
documentFor _ns =
26+
Nothing
27+
allNamespaces = [ Namespace [] ["NodeInfo"]]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{-# OPTIONS_GHC -fno-warn-orphans #-}
2+
3+
module Cardano.Node.Tracing.NodeStartupInfo
4+
( NodeStartupInfo (..)
5+
) where
6+
7+
import Cardano.Logging.Types.NodeStartupInfo (NodeStartupInfo (..))
8+
import Cardano.Logging.Types (MetaTrace(..), Namespace (..), SeverityS (..))
9+
10+
instance MetaTrace NodeStartupInfo where
11+
namespaceFor NodeStartupInfo {} =
12+
Namespace [] ["NodeStartupInfo"]
13+
severityFor (Namespace _ ["NodeStartupInfo"]) _ =
14+
Just Info
15+
severityFor _ns _ =
16+
Nothing
17+
documentFor (Namespace _ ["NodeStartupInfo"]) = Just
18+
"Startup information about this node, required for RTView\
19+
\\n\
20+
\\n _suiEra_: Name of the current era. \
21+
\\n _suiSlotLength_: Slot length, in seconds. \
22+
\\n _suiEpochLength_: Epoch length, in slots. \
23+
\\n _suiSlotsPerKESPeriod_: KES period length, in slots."
24+
documentFor _ns =
25+
Nothing
26+
allNamespaces = [ Namespace [] ["NodeStartupInfo"]]

cardano-node/src/Cardano/Node/Tracing/Peers.hs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
{-# LANGUAGE DeriveAnyClass #-}
2-
{-# LANGUAGE DeriveGeneric #-}
3-
{-# LANGUAGE StandaloneDeriving #-}
1+
{-# OPTIONS_GHC -fno-warn-orphans #-}
42

53
module Cardano.Node.Tracing.Peers
64
( NodePeers (..)
@@ -9,24 +7,7 @@ module Cardano.Node.Tracing.Peers
97

108
import Cardano.Logging
119
import Cardano.Node.Tracing.Tracers.Peer (PeerT, ppPeer)
12-
13-
import Control.DeepSeq (NFData)
14-
import Data.Aeson (FromJSON, ToJSON)
15-
import Data.Text (Text)
16-
import GHC.Generics (Generic)
17-
18-
type PeerInfoPP = Text -- The result of 'ppPeer' function.
19-
20-
-- | This type contains an information about current peers of the node.
21-
-- It will be asked by external applications as a DataPoint.
22-
newtype NodePeers = NodePeers [PeerInfoPP]
23-
24-
deriving instance Generic NodePeers
25-
deriving instance NFData NodePeers
26-
27-
instance ToJSON NodePeers
28-
instance FromJSON NodePeers
29-
10+
import Cardano.Logging.Types.NodePeers (NodePeers(..))
3011

3112
instance MetaTrace NodePeers where
3213
namespaceFor NodePeers {} =

cardano-node/src/Cardano/Node/Tracing/Tracers.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Cardano.Node.TraceConstraints
2424
import Cardano.Node.Tracing
2525
import Cardano.Node.Tracing.Consistency (checkNodeTraceConfiguration')
2626
import Cardano.Node.Tracing.Formatting ()
27-
import Cardano.Node.Tracing.Peers
27+
import Cardano.Node.Tracing.Peers (traceNodePeers)
2828
import qualified Cardano.Node.Tracing.StateRep as SR
2929
import Cardano.Node.Tracing.Tracers.BlockReplayProgress
3030
import Cardano.Node.Tracing.Tracers.ChainDB
@@ -37,7 +37,6 @@ import Cardano.Node.Tracing.Tracers.NodeToNode ()
3737
import Cardano.Node.Tracing.Tracers.NodeVersion (getNodeVersion)
3838
import Cardano.Node.Tracing.Tracers.NonP2P ()
3939
import Cardano.Node.Tracing.Tracers.P2P ()
40-
import Cardano.Node.Tracing.Tracers.Peer ()
4140
import Cardano.Node.Tracing.Tracers.Shutdown ()
4241
import Cardano.Node.Tracing.Tracers.Startup ()
4342
import qualified Ouroboros.Cardano.Network.PeerSelection.Governor.PeerSelectionState as Cardano

cardano-node/src/Cardano/Node/Tracing/Tracers/Peer.hs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,27 @@ startPeerTracer tracer nodeKernel delayMilliseconds = do
6868
traceWith tracer peers
6969
threadDelay (delayMilliseconds * 1000)
7070

71-
7271
data PeerT blk = PeerT
7372
RemoteConnectionId
7473
(Net.AnchoredFragment (Header blk))
7574
(PeerFetchStatus (Header blk))
7675
(PeerFetchInFlight (Header blk))
7776

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

83-
ppCid :: RemoteConnectionId -> String
84-
ppCid = takeWhile (/= ':') . show . remoteAddress
81+
where
82+
ppCid :: RemoteConnectionId -> String
83+
ppCid = takeWhile (/= ':') . show . remoteAddress
8584

86-
ppInFlight :: PeerFetchInFlight header -> String
87-
ppInFlight f = printf
88-
"%5s %3d %5d %6d"
89-
(ppMaxSlotNo $ peerFetchMaxSlotNo f)
90-
(peerFetchReqsInFlight f)
91-
(Set.size $ peerFetchBlocksInFlight f)
92-
(peerFetchBytesInFlight f)
93-
94-
ppMaxSlotNo :: Net.MaxSlotNo -> String
95-
ppMaxSlotNo Net.NoMaxSlotNo = "???"
96-
ppMaxSlotNo (Net.MaxSlotNo x) = show (unSlotNo x)
85+
ppInFlight :: PeerFetchInFlight header -> String
86+
ppInFlight f = printf
87+
"%5s %3d %5d %6d"
88+
(ppMaxSlotNo $ peerFetchMaxSlotNo f)
89+
(peerFetchReqsInFlight f)
90+
(Set.size $ peerFetchBlocksInFlight f)
91+
(peerFetchBytesInFlight f)
9792

9893
ppStatus :: PeerFetchStatus header -> String
9994
ppStatus = \case
@@ -103,6 +98,10 @@ ppStatus = \case
10398
PeerFetchStatusBusy -> "fetching"
10499
PeerFetchStatusReady {} -> "ready"
105100

101+
ppMaxSlotNo :: Net.MaxSlotNo -> String
102+
ppMaxSlotNo Net.NoMaxSlotNo = "???"
103+
ppMaxSlotNo (Net.MaxSlotNo x) = show (unSlotNo x)
104+
106105
getCurrentPeers
107106
:: NodeKernelData blk
108107
-> IO [PeerT blk]

0 commit comments

Comments
 (0)