Skip to content

Commit 1404782

Browse files
committed
Sync to match master
1 parent 511dcca commit 1404782

File tree

37 files changed

+375
-280
lines changed

37 files changed

+375
-280
lines changed

cardano-node/cardano-node.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ library
214214
, time
215215
, trace-dispatcher ^>= 2.10.0
216216
, trace-forward ^>= 2.3.0
217-
, trace-resources ^>= 0.2.4
217+
, trace-resources ^>= 0.2.3
218218
, tracer-transformers
219219
, transformers
220220
, transformers-except

cardano-tracer/CHANGELOG.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# ChangeLog
22

3-
## NEXT
4-
5-
* Cardano-tracer library functionality, allows shutting down and sending signals to running
6-
instances through channels.
7-
83
## 0.3.4 (July, 2025)
94
* Forwarding protocol supports connections over TCP socket, in addition to Unix domain sockets.
105

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
{-# LANGUAGE OverloadedRecordDot #-}
2-
3-
import Cardano.Tracer.CLI (TracerParams(..), parseTracerParams)
4-
import Cardano.Tracer.MetaTrace
1+
import Cardano.Tracer.CLI (TracerParams, parseTracerParams)
52
import Cardano.Tracer.Run (runCardanoTracer)
63

7-
import Data.Functor (void)
84
import Data.Version (showVersion)
95
import Options.Applicative
106

117
import Paths_cardano_tracer (version)
128

139
main :: IO ()
14-
main = void do
15-
tracerParams :: TracerParams
16-
<- customExecParser (prefs showHelpOnEmpty) tracerInfo
17-
trace :: Trace IO TracerTrace <-
18-
-- Default `Nothing' severity filter to Info.
19-
mkTracerTracer $ SeverityF (tracerParams.logSeverity <|> Just Info)
20-
runCardanoTracer trace tracerParams
10+
main =
11+
runCardanoTracer =<< customExecParser (prefs showHelpOnEmpty) tracerInfo
2112

2213
tracerInfo :: ParserInfo TracerParams
2314
tracerInfo = info
@@ -30,9 +21,7 @@ tracerInfo = info
3021

3122
versionOption :: Parser (a -> a)
3223
versionOption = infoOption
33-
do showVersion version
34-
do mconcat
35-
[ long "version"
36-
, short 'v'
37-
, help "Show version"
38-
]
24+
(showVersion version)
25+
(long "version" <>
26+
short 'v' <>
27+
help "Show version")

cardano-tracer/bench/cardano-tracer-bench.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import Control.Concurrent.Extra (newLock)
1919
#if RTVIEW
2020
import Control.Concurrent.STM.TVar (newTVarIO)
2121
#endif
22-
import Control.Concurrent.Chan.Unagi (newChan)
2322
import Control.DeepSeq
2423
import qualified Data.List.NonEmpty as NE
2524
import Data.Time.Clock (UTCTime, getCurrentTime)
@@ -64,8 +63,6 @@ main = do
6463

6564
tracer <- mkTracerTracer $ SeverityF $ Just Warning
6665

67-
(inChan, _outChan) <- newChan
68-
6966
let tracerEnv :: TracerConfig -> HandleRegistry -> TracerEnv
7067
tracerEnv config handleRegistry = TracerEnv
7168
{ teConfig = config
@@ -77,7 +74,6 @@ main = do
7774
, teDPRequestors = dpRequestors
7875
, teProtocolsBrake = protocolsBrake
7976
, teTracer = tracer
80-
, teInChan = inChan
8177
, teReforwardTraceObjects = \_-> pure ()
8278
, teRegistry = handleRegistry
8379
, teStateDir = Nothing

cardano-tracer/cardano-tracer.cabal

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ library
199199
, time
200200
, trace-dispatcher ^>= 2.10.0
201201
, trace-forward ^>= 2.3.0
202-
, trace-resources ^>= 0.2.4
203-
, unagi-chan
202+
, trace-resources ^>= 0.2.3
204203
, wai ^>= 3.2
205204
, warp ^>= 3.4
206205
, yaml
@@ -295,7 +294,6 @@ library demo-acceptor-lib
295294
exposed-modules: Cardano.Tracer.Test.Acceptor
296295

297296
build-depends: bytestring
298-
, QuickCheck
299297
, cardano-tracer
300298
, containers
301299
, extra
@@ -308,9 +306,9 @@ library demo-acceptor-lib
308306
, text
309307
, trace-dispatcher
310308
, trace-forward
311-
, unagi-chan
312309
, vector
313310
, vector-algorithms
311+
, QuickCheck
314312

315313
executable demo-acceptor
316314
import: project-config
@@ -454,13 +452,12 @@ benchmark cardano-tracer-bench
454452
build-depends: stm <2.5.2 || >=2.5.3
455453
build-depends: cardano-tracer
456454
, criterion
457-
, deepseq
458455
, directory
456+
, deepseq
459457
, extra
460458
, filepath
461459
, time
462460
, trace-dispatcher
463-
, unagi-chan
464461

465462
ghc-options: -threaded
466463
-rtsopts

cardano-tracer/src/Cardano/Tracer/Acceptors/Run.hs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import Cardano.Tracer.Utils
1414
import Cardano.Logging.Types (TraceObject)
1515
import qualified Cardano.Logging.Types as Net
1616

17-
import Control.Concurrent.Chan.Unagi (dupChan)
1817
import Control.Concurrent.Async (forConcurrently_)
1918
import "contra-tracer" Control.Tracer (Tracer, contramap, nullTracer, stdoutTracer)
2019
import qualified Data.List.NonEmpty as NE
@@ -34,28 +33,20 @@ import qualified Trace.Forward.Protocol.TraceObject.Type as TOF
3433
-- 1. Server mode, when the tracer accepts connections from any number of nodes.
3534
-- 2. Client mode, when the tracer initiates connections to specified number of nodes.
3635
runAcceptors :: TracerEnv -> TracerEnvRTView -> IO ()
37-
runAcceptors tracerEnv@TracerEnv{teTracer, teInChan = inChan} tracerEnvRTView = do
36+
runAcceptors tracerEnv@TracerEnv{teTracer} tracerEnvRTView = do
3837
traceWith teTracer $ TracerStartedAcceptors network
3938
case network of
40-
AcceptAt howToConnect -> let
39+
AcceptAt howToConnect ->
4140
-- Run one server that accepts connections from the nodes.
42-
43-
action :: IO ()
44-
action = do
45-
dieOnShutdown =<< dupChan inChan
46-
runAcceptorsServer tracerEnv tracerEnvRTView howToConnect $ acceptorsConfigs (Net.howToConnectString howToConnect)
47-
48-
in runInLoop action verbosity howToConnect initialPauseInSec
49-
ConnectTo localSocks -> do
41+
runInLoop
42+
(runAcceptorsServer tracerEnv tracerEnvRTView howToConnect $ acceptorsConfigs (Net.howToConnectString howToConnect))
43+
verbosity howToConnect initialPauseInSec
44+
ConnectTo localSocks ->
5045
-- Run N clients that initiate connections to the nodes.
51-
forConcurrently_ (NE.nub localSocks) \howToConnect -> let
52-
53-
action :: IO ()
54-
action = runAcceptorsClient tracerEnv tracerEnvRTView howToConnect $ acceptorsConfigs (Net.howToConnectString howToConnect)
55-
56-
in do
57-
dieOnShutdown =<< dupChan inChan
58-
runInLoop action verbosity howToConnect initialPauseInSec
46+
forConcurrently_ (NE.nub localSocks) \howToConnect ->
47+
runInLoop
48+
(runAcceptorsClient tracerEnv tracerEnvRTView howToConnect $ acceptorsConfigs (Net.howToConnectString howToConnect))
49+
verbosity howToConnect initialPauseInSec
5950
where
6051
TracerConfig{network, ekgRequestFreq, verbosity, ekgRequestFull} = teConfig tracerEnv
6152
ekgUseFullRequests = fromMaybe False ekgRequestFull
Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE GADTs #-}
3-
{-# LANGUAGE LambdaCase #-}
42

53
module Cardano.Tracer.Environment
64
( TracerEnv (..)
75
, TracerEnvRTView (..)
8-
, RawMessage (..)
9-
, InternalMessage (..)
10-
, Tag (..)
11-
, CardanoTracerMessage
12-
, onRawMessage
13-
, onInternal
14-
, onUser
15-
, blockUntilShutdown
16-
, dieOnShutdown
17-
, forever'tilShutdown
186
) where
197

208
import Cardano.Logging.Types
21-
import Cardano.Logging.Resources.Types (ResourceStats)
229
import Cardano.Tracer.Configuration
2310
#if RTVIEW
2411
import Cardano.Tracer.Handlers.Notifications.Types
@@ -29,13 +16,10 @@ import Cardano.Tracer.Handlers.State.TraceObjects
2916
import Cardano.Tracer.MetaTrace
3017
import Cardano.Tracer.Types
3118

32-
import Control.Concurrent (myThreadId)
33-
import Control.Exception (AsyncException(ThreadKilled), throwTo)
34-
import Control.Concurrent.Chan.Unagi (InChan, OutChan, readChan)
3519
import Control.Concurrent.Extra (Lock)
3620
import Data.Text (Text)
3721
import Data.Text.Lazy.Builder (Builder)
38-
import Data.Kind (Type)
22+
3923

4024
-- | Environment for all functions.
4125
data TracerEnv = TracerEnv
@@ -52,7 +36,6 @@ data TracerEnv = TracerEnv
5236
, teRegistry :: !HandleRegistry
5337
, teStateDir :: !(Maybe FilePath)
5438
, teMetricsHelp :: ![(Text, Builder)]
55-
, teInChan :: !(InChan (CardanoTracerMessage ()))
5639
}
5740

5841
#if RTVIEW
@@ -68,46 +51,3 @@ data TracerEnvRTView = TracerEnvRTView
6851
#else
6952
data TracerEnvRTView = TracerEnvRTView
7053
#endif
71-
72-
type CardanoTracerMessage userMsg = RawMessage InternalMessage userMsg
73-
74-
type RawMessage :: Type -> Type -> Type
75-
data RawMessage internal user
76-
= Shutdown
77-
| InternalMessage internal
78-
| UserMessage user
79-
80-
blockUntilShutdown :: OutChan (RawMessage internal user) -> IO ()
81-
blockUntilShutdown outChan = go where
82-
go :: IO ()
83-
go = readChan outChan >>= \case
84-
Shutdown -> pure ()
85-
_ -> go
86-
87-
onRawMessage :: (internal -> IO ()) -> (user -> IO ()) -> OutChan (RawMessage internal user) -> IO ()
88-
onRawMessage internalAction userAction outChan =
89-
readChan outChan >>= \case
90-
Shutdown -> myThreadId >>= (`throwTo` ThreadKilled)
91-
InternalMessage internal -> internalAction internal
92-
UserMessage user -> userAction user
93-
94-
onInternal :: (internal -> IO ()) -> OutChan (RawMessage internal user) -> IO ()
95-
onInternal = (`onRawMessage` mempty)
96-
97-
onUser :: (user -> IO ()) -> OutChan (RawMessage internal user) -> IO ()
98-
onUser = (mempty `onRawMessage`)
99-
100-
data InternalMessage where
101-
ResourceMessage :: Tag ex -> (ex -> IO ()) -> InternalMessage
102-
103-
data Tag a where
104-
TagResource :: Tag (ResourceStats, Trace IO TracerTrace)
105-
106-
dieOnShutdown :: OutChan (RawMessage internal user) -> IO ()
107-
dieOnShutdown = onRawMessage mempty mempty
108-
109-
forever'tilShutdown :: OutChan (RawMessage internal user) -> IO () -> IO ()
110-
forever'tilShutdown outChan action = do
111-
readChan outChan >>= \case
112-
Shutdown -> pure ()
113-
_ -> action *> forever'tilShutdown outChan action

cardano-tracer/src/Cardano/Tracer/Handlers/Logs/Rotator.hs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ module Cardano.Tracer.Handlers.Logs.Rotator
66
) where
77

88
import Cardano.Tracer.Configuration
9-
import Cardano.Tracer.Environment (TracerEnv (..), forever'tilShutdown)
9+
import Cardano.Tracer.Environment
1010
import Cardano.Tracer.Handlers.Logs.Utils (createOrUpdateEmptyLog, getTimeStampFromLog,
1111
isItLog)
1212
import Cardano.Tracer.MetaTrace
1313
import Cardano.Tracer.Types (HandleRegistry, HandleRegistryKey, NodeName)
1414
import Cardano.Tracer.Utils (showProblemIfAny, readRegistry)
1515

1616
import Control.Concurrent.Async (forConcurrently_)
17-
import Control.Concurrent.Chan.Unagi (dupChan)
1817
import Control.Concurrent.Extra (Lock)
19-
import Control.Monad (forM_, unless, when)
18+
import Control.Monad (forM_, forever, unless, when)
2019
import Control.Monad.Extra (whenJust, whenM)
2120
import Data.Foldable (for_)
2221
import Data.List (nub, sort)
@@ -34,40 +33,38 @@ import System.Time.Extra (sleep)
3433

3534
-- | Runs rotation mechanism for the log files.
3635
runLogsRotator :: TracerEnv -> IO ()
37-
runLogsRotator tracerEnv@TracerEnv { teConfig = TracerConfig{rotation}, teTracer } = do
38-
whenJust rotation \rot -> do
36+
runLogsRotator TracerEnv
37+
{ teConfig = TracerConfig{rotation, verbosity, logging}
38+
, teCurrentLogLock
39+
, teTracer
40+
, teRegistry
41+
} = do
42+
whenJust rotation \rotParams -> do
3943
traceWith teTracer TracerStartedLogRotator
40-
launchRotator tracerEnv rot
41-
42-
launchRotator
43-
:: TracerEnv
44-
-> RotationParams
45-
-> IO ()
46-
launchRotator tracerEnv rot@RotationParams{rpFrequencySecs} = do
47-
whenNonEmpty loggingParamsForFiles do
48-
outChan <- dupChan teInChan
49-
forever'tilShutdown outChan do
50-
showProblemIfAny verbosity do
51-
forM_ loggingParamsForFiles \loggingParam -> do
52-
checkRootDir teCurrentLogLock teRegistry rot loggingParam
53-
sleep (fromIntegral rpFrequencySecs)
54-
where
55-
whenNonEmpty :: Applicative f => [a] -> f () -> f ()
56-
whenNonEmpty = unless . null
57-
58-
TracerEnv
59-
{ teConfig = TracerConfig{verbosity, logging}
60-
, teCurrentLogLock
61-
, teRegistry
62-
, teInChan
63-
} = tracerEnv
64-
44+
launchRotator loggingParamsForFiles rotParams verbosity teRegistry teCurrentLogLock
45+
where
6546
loggingParamsForFiles :: [LoggingParams]
6647
loggingParamsForFiles = nub (NE.filter filesOnly logging)
6748

6849
filesOnly :: LoggingParams -> Bool
6950
filesOnly LoggingParams{logMode} = logMode == FileMode
7051

52+
launchRotator
53+
:: [LoggingParams]
54+
-> RotationParams
55+
-> Maybe Verbosity
56+
-> HandleRegistry
57+
-> Lock
58+
-> IO ()
59+
launchRotator [] _ _ _ _ = return ()
60+
launchRotator loggingParamsForFiles
61+
rotParams@RotationParams{rpFrequencySecs} verb registry currentLogLock =
62+
forever do
63+
showProblemIfAny verb do
64+
forM_ loggingParamsForFiles \loggingParam -> do
65+
checkRootDir currentLogLock registry rotParams loggingParam
66+
sleep $ fromIntegral rpFrequencySecs
67+
7168
-- | All the logs with 'TraceObject's received from particular node
7269
-- will be stored in a separate subdirectory in the root directory.
7370
--

cardano-tracer/src/Cardano/Tracer/Handlers/Metrics/Monitoring.hs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import Cardano.Tracer.Types
1414

1515
import Prelude hiding (head)
1616

17-
import Control.Concurrent.Async (race_)
18-
import Control.Concurrent.Chan.Unagi (OutChan, dupChan)
1917
import Data.ByteString as ByteString (ByteString, isInfixOf)
2018
import Data.ByteString.Builder (stringUtf8)
2119
import qualified Data.Text as T
@@ -41,26 +39,19 @@ runMonitoringServer
4139
-> Endpoint -- ^ (web page with list of connected nodes, EKG web page).
4240
-> IO RouteDictionary
4341
-> IO ()
44-
runMonitoringServer TracerEnv{teTracer, teInChan = inChan} endpoint computeRoutes_autoUpdate = do
42+
runMonitoringServer TracerEnv{teTracer} endpoint computeRoutes_autoUpdate = do
4543
-- Pause to prevent collision between "Listening"-notifications from servers.
4644
sleep 0.2
4745
traceWith teTracer TracerStartedMonitoring
4846
{ ttMonitoringEndpoint = endpoint
4947
, ttMonitoringType = "list"
5048
}
5149
dummyStore <- EKG.newStore
52-
outChan <- dupChan inChan
53-
54-
let run :: IO ()
55-
run = runSettings (setEndpoint endpoint defaultSettings) $
56-
renderEkg dummyStore outChan computeRoutes_autoUpdate
57-
58-
race_ run (blockUntilShutdown outChan)
59-
60-
renderEkg :: EKG.Store -> OutChan (CardanoTracerMessage ()) -> IO RouteDictionary -> Application
61-
renderEkg dummyStore outChan computeRoutes_autoUpdate request send = do
62-
dieOnShutdown outChan
50+
runSettings (setEndpoint endpoint defaultSettings) do
51+
renderEkg dummyStore computeRoutes_autoUpdate
6352

53+
renderEkg :: EKG.Store -> IO RouteDictionary -> Application
54+
renderEkg dummyStore computeRoutes_autoUpdate request send = do
6455
routeDictionary :: RouteDictionary <-
6556
computeRoutes_autoUpdate
6657

0 commit comments

Comments
 (0)