Skip to content

Commit 9cf1e65

Browse files
authored
Merge pull request #6409 from IntersectMBO/mkarg/tracing-improvements
new tracing: various improvements
2 parents 710f6aa + e521921 commit 9cf1e65

6 files changed

Lines changed: 39 additions & 20 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ defaultCardanoConfig = emptyTraceConfig {
1717
[([],
1818
[ ConfSeverity (SeverityF (Just Notice))
1919
, ConfDetail DNormal
20-
, ConfBackend [Stdout MachineFormat
20+
, ConfBackend [ Stdout MachineFormat
2121
, EKGBackend
22-
, Forwarder
2322
]])
2423

2524
-- more important tracers going here

cardano-tracer/test/cardano-tracer-test-ext.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ getExternalTracerState TestSetup{..} ref = do
138138
-- For simplicity, we are always 'Initiator',
139139
-- so 'cardano-tracer' is always a 'Responder'.
140140
let forwardingConf = fromMaybe defaultForwarder (tcForwarder simpleTestConfig)
141-
initForwarding iomgr forwardingConf $
141+
-- weaker machines (like CI runners) need to be able to buffer more trace objects for the stress test
142+
initForwarding iomgr forwardingConf{ tofQueueSize = 768 } $
142143
InitForwardingWith
143144
{ initNetworkMagic = unI tsNetworkMagic
144145
, initEKGStore = Nothing

trace-dispatcher/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Revision history for trace-dispatcher
22

3-
## 2.11.1 -- Dez 2025
3+
## 2.11.1 -- Jan 2026
44

5+
* Add strict `contramap'` (infix alias `>!$!<`) to the API, capturing a common pattern to avoid unintentional space leaks when composing tracers
56
* Increase `PrometheusSimple` robustness by restarting the backend upon crash, adding start/stop traces and more eagerly reaping of dangling sockets
7+
* Increased strictness when storing traced `DataPoints`
8+
* Drastically reduced fallback value for forwarding queue capacity to minimize impact of forwarding service interruption on heap size and retention
69
* Removed `TraceConfig.tcPeerFrequency` and hence `TraceOptionPeerFrequency` from config representation
710
* Removed unused module `Cardano.Logging.Types.NodePeers`
811

trace-dispatcher/src/Cardano/Logging/Trace.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ module Cardano.Logging.Trace (
3434
, appendInnerName
3535
, appendInnerNames
3636
, withInnerNames
37+
38+
, contramap'
39+
, (>!$!<)
3740
) where
3841

3942
import Cardano.Logging.Types
4043

4144
import Control.Monad (forM_, join)
4245
import Control.Monad.IO.Unlift
4346
import qualified Control.Tracer as T
47+
import Data.Functor.Contravariant as Contr (Contravariant, (>$<))
4448
import Data.Maybe (isJust)
4549
import Data.Text (Text)
4650

@@ -371,3 +375,15 @@ routingTrace rf rc = contramapM'
371375
(lc, Left control) ->
372376
T.traceWith (unpackTrace rc) (lc, Left control))
373377

378+
-- | A contramap' which is strict in its second argument and its result captures
379+
-- a common pattern to avoid unintentionally leaking space when composing tracers.
380+
-- The infix alias is (>!$!<).
381+
contramap', (>!$!<) :: Contravariant f => (a' -> a) -> (f a -> f a')
382+
383+
contramap' a !b =
384+
let !result = a Contr.>$< b
385+
in result
386+
387+
infixl 4 >!$!<
388+
389+
(>!$!<) = contramap'

trace-dispatcher/src/Cardano/Logging/Tracer/DataPoint.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BangPatterns #-}
12
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE FlexibleInstances #-}
34
{-# LANGUAGE GADTs #-}
@@ -21,7 +22,7 @@ import Cardano.Logging.Types
2122

2223
import Control.Concurrent.STM (atomically)
2324
import Control.Concurrent.STM.TVar
24-
import Control.DeepSeq (NFData, deepseq)
25+
import Control.DeepSeq (NFData, ($!!))
2526
import Control.Monad.IO.Class
2627
import qualified Control.Tracer as NT
2728
import Data.Aeson
@@ -39,11 +40,12 @@ import Data.Text (Text, intercalate)
3940
-- available for the acceptor application, to decode unstructured JSON.
4041
--
4142
data DataPoint where
42-
DataPoint :: (ToJSON v, NFData v) => v -> DataPoint
43+
DataPoint :: (ToJSON v, NFData v) => !v -> DataPoint
4344

44-
type DataPointName = Text
45+
type DataPointName = Text
4546
type DataPointStore = TVar (M.Map DataPointName DataPoint)
4647

48+
4749
initDataPointStore :: IO DataPointStore
4850
initDataPointStore = newTVarIO M.empty
4951

@@ -53,11 +55,11 @@ writeToStore
5355
-> DataPointName
5456
-> DataPoint
5557
-> IO ()
56-
writeToStore dpStore dpName (DataPoint obj) = atomically $
57-
modifyTVar' dpStore $ \store ->
58-
if dpName `M.member` store
59-
then M.adjust (const (DataPoint (deepseq obj obj))) dpName store
60-
else M.insert dpName (DataPoint (deepseq obj obj)) store
58+
writeToStore dpStore dpName (DataPoint obj) =
59+
let !newVal = DataPoint $!! obj
60+
in atomically $
61+
modifyTVar' dpStore $
62+
M.insert dpName newVal
6163

6264
dataPointTracer :: forall m. MonadIO m
6365
=> DataPointStore

trace-dispatcher/src/Cardano/Logging/Types.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ data TraceOptionForwarder = TraceOptionForwarder {
497497
-- requests periodically, the default for that being 100. Here, the queue can
498498
-- hold enough traces for 10 subsequent polls by cardano-tracer.
499499
instance AE.FromJSON TraceOptionForwarder where
500-
parseJSON (AE.Object obj) = do
500+
parseJSON = AE.withObject "TraceOptionForwarder" $ \obj -> do
501501
-- Field "queueSize" is the new field that replaces and unifies
502502
-- both "connQueueSize" and "disconnQueueSize".
503503
maybeQueueSize <- obj AE..:? "queueSize"
@@ -506,14 +506,12 @@ instance AE.FromJSON TraceOptionForwarder where
506506
(Just qs) -> return qs
507507
-- Else we look for the deprectaed fields.
508508
Nothing -> do
509-
-- We keep the same default values.
510-
connQueueSize <- obj AE..:? "connQueueSize" AE..!= 1024
511-
disconnQueueSize <- obj AE..:? "disconnQueueSize" AE..!= 2048
509+
connQueueSize <- obj AE..:? "connQueueSize" AE..!= 128
510+
disconnQueueSize <- obj AE..:? "disconnQueueSize" AE..!= 192
512511
return $ max connQueueSize disconnQueueSize
513512
verbosity <- obj AE..:? "verbosity" AE..!= Minimum
514-
maxReconnectDelay <- obj AE..:? "maxReconnectDelay" AE..!= 60
513+
maxReconnectDelay <- obj AE..:? "maxReconnectDelay" AE..!= 45
515514
return $ TraceOptionForwarder queueSize verbosity maxReconnectDelay
516-
parseJSON _ = mempty
517515

518516
instance AE.ToJSON TraceOptionForwarder where
519517
toJSON TraceOptionForwarder{..} = AE.object
@@ -525,9 +523,9 @@ instance AE.ToJSON TraceOptionForwarder where
525523

526524
defaultForwarder :: TraceOptionForwarder
527525
defaultForwarder = TraceOptionForwarder {
528-
tofQueueSize = 2048
526+
tofQueueSize = 192
529527
, tofVerbosity = Minimum
530-
, tofMaxReconnectDelay = 60
528+
, tofMaxReconnectDelay = 45
531529
}
532530

533531
instance AE.FromJSON ForwarderMode where

0 commit comments

Comments
 (0)