Skip to content
Open
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
4 changes: 4 additions & 0 deletions cardano-tracer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

## NEXT
* Cardano-tracer library functionality, allows shutting down and sending signals to running
instances through channels.

## 0.3.6 (November 2025)
* Implement Prometheus HTTP service discovery (SD) under the URL `/targets`
* Add optional config field `"prometheusLabels": { "<labelname>": "<labelvalue>", ... }` for custom labels to be attached with Prometheus SD
Expand Down
25 changes: 18 additions & 7 deletions cardano-tracer/app/cardano-tracer.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import Cardano.Tracer.CLI (TracerParams, parseTracerParams)
{-# LANGUAGE OverloadedRecordDot #-}

import Cardano.Tracer.CLI (TracerParams(..), parseTracerParams)
import Cardano.Tracer.MetaTrace
import Cardano.Tracer.Run (runCardanoTracer)

import Data.Functor (void)
import Data.Version (showVersion)
import Options.Applicative

import Paths_cardano_tracer (version)

main :: IO ()
main =
runCardanoTracer =<< customExecParser (prefs showHelpOnEmpty) tracerInfo
main = void do
tracerParams :: TracerParams
<- customExecParser (prefs showHelpOnEmpty) tracerInfo
trace :: Trace IO TracerTrace <-
-- Default `Nothing' severity filter to Info.
mkTracerTracer $ SeverityF (tracerParams.logSeverity <|> Just Info)
runCardanoTracer trace tracerParams

tracerInfo :: ParserInfo TracerParams
tracerInfo = info
Expand All @@ -21,7 +30,9 @@ tracerInfo = info

versionOption :: Parser (a -> a)
versionOption = infoOption
(showVersion version)
(long "version" <>
short 'v' <>
help "Show version")
do showVersion version
do mconcat
[ long "version"
, short 'v'
, help "Show version"
]
4 changes: 4 additions & 0 deletions cardano-tracer/bench/cardano-tracer-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Control.Concurrent.Extra (newLock)
#if RTVIEW
import Control.Concurrent.STM.TVar (newTVarIO)
#endif
import Control.Concurrent.Chan.Unagi (newChan)
import Control.DeepSeq
import qualified Data.List.NonEmpty as NE
import Data.Time.Clock (UTCTime, getCurrentTime)
Expand Down Expand Up @@ -63,6 +64,8 @@ main = do

tracer <- mkTracerTracer $ SeverityF $ Just Warning

(inChan, _outChan) <- newChan

let tracerEnv :: TracerConfig -> HandleRegistry -> TracerEnv
tracerEnv config handleRegistry = TracerEnv
{ teConfig = config
Expand All @@ -74,6 +77,7 @@ main = do
, teDPRequestors = dpRequestors
, teProtocolsBrake = protocolsBrake
, teTracer = tracer
, teInChan = inChan
, teReforwardTraceObjects = \_-> pure ()
, teRegistry = handleRegistry
, teStateDir = Nothing
Expand Down
7 changes: 5 additions & 2 deletions cardano-tracer/cardano-tracer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ library
, trace-dispatcher ^>= 2.11.0
, trace-forward ^>= 2.4.0
, trace-resources ^>= 0.2.4
, unagi-chan
, wai ^>= 3.2
, warp ^>= 3.4
, yaml
Expand Down Expand Up @@ -297,6 +298,7 @@ library demo-acceptor-lib
exposed-modules: Cardano.Tracer.Test.Acceptor

build-depends: bytestring
, QuickCheck
, cardano-tracer
, containers
, extra
Expand All @@ -309,9 +311,9 @@ library demo-acceptor-lib
, text
, trace-dispatcher
, trace-forward
, unagi-chan
, vector
, vector-algorithms
, QuickCheck

executable demo-acceptor
import: project-config
Expand Down Expand Up @@ -455,12 +457,13 @@ benchmark cardano-tracer-bench
build-depends: stm <2.5.2 || >=2.5.3
build-depends: cardano-tracer
, criterion
, directory
, deepseq
, directory
, extra
, filepath
, time
, trace-dispatcher
, unagi-chan

ghc-options: -threaded
-rtsopts
Expand Down
25 changes: 15 additions & 10 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ module Cardano.Tracer.Acceptors.Run
) where

import Cardano.Logging.Types (TraceObject)
import Cardano.Logging.Utils (runInLoop)
import Cardano.Logging.Utils (runInLoop, RunInLoopTermination(..))
import Cardano.Tracer.Acceptors.Client
import Cardano.Tracer.Acceptors.Server
import Cardano.Tracer.Configuration
import Cardano.Tracer.Environment
import Cardano.Tracer.MetaTrace

import Control.Concurrent.Chan.Unagi (dupChan)
import Control.Concurrent.Async (forConcurrently_)
import Control.Exception (SomeException (..))
import "contra-tracer" Control.Tracer (Tracer, contramap, nullTracer, stdoutTracer)
Expand All @@ -33,20 +34,24 @@ import qualified Trace.Forward.Protocol.TraceObject.Type as TOF
-- 1. Server mode, when the tracer accepts connections from any number of nodes.
-- 2. Client mode, when the tracer initiates connections to specified number of nodes.
runAcceptors :: TracerEnv -> TracerEnvRTView -> IO ()
runAcceptors tracerEnv@TracerEnv{teTracer} tracerEnvRTView = do
runAcceptors tracerEnv@TracerEnv{teTracer, teInChan = inChan} tracerEnvRTView = do
traceWith teTracer $ TracerStartedAcceptors network
case network of
AcceptAt howToConnect ->
AcceptAt howToConnect -> let
-- Run one server that accepts connections from the nodes.
runInLoop
(runAcceptorsServer tracerEnv tracerEnvRTView howToConnect $ acceptorsConfigs (show howToConnect))
(handleOnInterruption howToConnect) initialPauseInSec 10
action :: IO ()
action = do
dieOnShutdown =<< dupChan inChan
runAcceptorsServer tracerEnv tracerEnvRTView howToConnect $ acceptorsConfigs (show howToConnect)
in runInLoop action TerminateNever (handleOnInterruption howToConnect) initialPauseInSec 10
ConnectTo localSocks ->
-- Run N clients that initiate connections to the nodes.
forConcurrently_ (NE.nub localSocks) \howToConnect ->
runInLoop
(runAcceptorsClient tracerEnv tracerEnvRTView howToConnect $ acceptorsConfigs (show howToConnect))
(handleOnInterruption howToConnect) initialPauseInSec 30
forConcurrently_ (NE.nub localSocks) \howToConnect -> let
action :: IO ()
action = do
dieOnShutdown =<< dupChan inChan
runAcceptorsClient tracerEnv tracerEnvRTView howToConnect $ acceptorsConfigs (show howToConnect)
in runInLoop action TerminateNever (handleOnInterruption howToConnect) initialPauseInSec 30
where
handleOnInterruption howToConnect (SomeException e)
| verbosity == Just Minimum = pure ()
Expand Down
Loading
Loading