Skip to content

Commit

Permalink
CAD-2572 Tracing: Get EKG Server to traces
Browse files Browse the repository at this point in the history
  • Loading branch information
jutaro committed May 13, 2021
1 parent 3362b49 commit ce361a9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions cardano-node/cardano-node.cabal
Expand Up @@ -76,6 +76,7 @@ library
, byron-spec-ledger
, bytestring
, deepseq
, ekg
, cardano-api
, cardano-config
, cardano-crypto-class
Expand Down
11 changes: 8 additions & 3 deletions cardano-node/src/Cardano/Node/Configuration/Logging.hs
Expand Up @@ -31,6 +31,7 @@ import Data.List (nub)
import Data.Text (pack)
import Data.Time.Clock (UTCTime, getCurrentTime)
import Data.Version (showVersion)
import qualified System.Remote.Monitoring as EKG

import Cardano.BM.Backend.Aggregation (plugin)
import Cardano.BM.Backend.EKGView (plugin)
Expand Down Expand Up @@ -109,6 +110,7 @@ data LoggingLayer = LoggingLayer
, llConfiguration :: Configuration
, llAddBackend :: Backend Text -> BackendKind -> IO ()
, llSwitchboard :: Switchboard Text
, llEKGServer :: Maybe EKG.Server
}

--------------------------------
Expand Down Expand Up @@ -163,7 +165,9 @@ createLoggingLayer ver nodeConfig' p = do
when loggingEnabled $ liftIO $
loggingPreInit nodeConfig' logConfig switchBoard trace

pure $ mkLogLayer logConfig switchBoard trace
mEKGServer <- liftIO $ Switchboard.getSbEKGServer switchBoard

pure $ mkLogLayer logConfig switchBoard mEKGServer trace
where
loggingPreInit
:: NodeConfiguration
Expand Down Expand Up @@ -217,8 +221,8 @@ createLoggingLayer ver nodeConfig' p = do
-- Record node metrics, if configured
startCapturingMetrics trace

mkLogLayer :: Configuration -> Switchboard Text -> Trace IO Text -> LoggingLayer
mkLogLayer logConfig switchBoard trace =
mkLogLayer :: Configuration -> Switchboard Text -> Maybe EKG.Server -> Trace IO Text -> LoggingLayer
mkLogLayer logConfig switchBoard mEKGServer trace =
LoggingLayer
{ llBasicTrace = Trace.natTrace liftIO trace
, llLogDebug = Trace.logDebug
Expand All @@ -235,6 +239,7 @@ createLoggingLayer ver nodeConfig' p = do
, llConfiguration = logConfig
, llAddBackend = Switchboard.addExternalBackend switchBoard
, llSwitchboard = switchBoard
, llEKGServer = mEKGServer
}

startCapturingMetrics :: Trace IO Text -> IO ()
Expand Down
8 changes: 6 additions & 2 deletions cardano-node/src/Cardano/Node/Run.hs
Expand Up @@ -113,7 +113,7 @@ runNode cmdPc = do
p

loggingLayer <- case eLoggingLayer of
Left err -> putTextLn (show err) >> exitFailure
Left err -> putTextLn (show err) >> exitFailure
Right res -> return res

!trace <- setupTrace loggingLayer
Expand All @@ -125,7 +125,11 @@ runNode cmdPc = do
-- Used for ledger queries and peer connection status.
nodeKernelData :: NodeKernelData blk <- mkNodeKernelData

tracers <- mkTracers (ncTraceConfig nc) trace nodeKernelData
tracers <- mkTracers
(ncTraceConfig nc)
trace
nodeKernelData
(llEKGServer loggingLayer)

Async.withAsync (handlePeersListSimple trace nodeKernelData)
$ \_peerLogingThread ->
Expand Down
25 changes: 16 additions & 9 deletions cardano-node/src/Cardano/Tracing/Tracers.hs
Expand Up @@ -33,6 +33,7 @@ import Data.Aeson (ToJSON (..), Value (..))
import qualified Data.HashMap.Strict as Map
import qualified Data.Text as Text
import Data.Time (UTCTime)
import qualified System.Remote.Monitoring as EKG

import Network.Mux (MuxTrace, WithMuxBearer)
import qualified Network.Socket as Socket (SockAddr)
Expand Down Expand Up @@ -274,16 +275,20 @@ mkTracers
=> TraceOptions
-> Trace IO Text
-> NodeKernelData blk
-> Maybe EKG.Server
-> IO (Tracers peer localPeer blk)
mkTracers tOpts@(TracingOn trSel) tr nodeKern = do
mkTracers tOpts@(TracingOn trSel) tr nodeKern mEKGServer = do
fStats <- mkForgingStats
consensusTracers <- mkConsensusTracers trSel verb tr nodeKern fStats
elidedChainDB <- newstate -- for eliding messages in ChainDB tracer

pure Tracers
{ chainDBTracer = tracerOnOff' (traceChainDB trSel) $
annotateSeverity $ teeTraceChainTip tOpts elidedChainDB
(appendName "ChainDB" tr) (appendName "metrics" tr)
annotateSeverity $ teeTraceChainTip
tOpts elidedChainDB
mEKGServer
(appendName "ChainDB" tr)
(appendName "metrics" tr)
, consensusTracers = consensusTracers
, nodeToClientTracers = nodeToClientTracers' trSel verb tr
, nodeToNodeTracers = nodeToNodeTracers' trSel verb tr
Expand All @@ -302,7 +307,7 @@ mkTracers tOpts@(TracingOn trSel) tr nodeKern = do
verb :: TracingVerbosity
verb = traceVerbosity trSel

mkTracers TracingOff _ _ =
mkTracers TracingOff _ _ _ =
pure Tracers
{ chainDBTracer = nullTracer
, consensusTracers = Consensus.Tracers
Expand Down Expand Up @@ -359,14 +364,15 @@ teeTraceChainTip
)
=> TraceOptions
-> MVar (Maybe (WithSeverity (ChainDB.TraceEvent blk)), Integer)
-> Maybe EKG.Server
-> Trace IO Text
-> Trace IO Text
-> Tracer IO (WithSeverity (ChainDB.TraceEvent blk))
teeTraceChainTip TracingOff _ _ _ = nullTracer
teeTraceChainTip (TracingOn trSel) elided trTrc trMet =
teeTraceChainTip TracingOff _ _ _ _ = nullTracer
teeTraceChainTip (TracingOn trSel) elided mEKGServer trTrc trMet =
Tracer $ \ev -> do
traceWith (teeTraceChainTipElide (traceVerbosity trSel) elided trTrc) ev
traceWith (ignoringSeverity (traceChainMetrics trMet)) ev
traceWith (ignoringSeverity (traceChainMetrics mEKGServer trMet)) ev

teeTraceChainTipElide
:: ( ConvertRawHash blk
Expand All @@ -388,8 +394,9 @@ ignoringSeverity tr = Tracer $ \(WithSeverity _ ev) -> traceWith tr ev

traceChainMetrics
:: forall blk. HasHeader (Header blk)
=> Trace IO Text -> Tracer IO (ChainDB.TraceEvent blk)
traceChainMetrics tr = Tracer $ \ev ->
=> Maybe EKG.Server -> Trace IO Text -> Tracer IO (ChainDB.TraceEvent blk)
traceChainMetrics Nothing _ = nullTracer
traceChainMetrics (Just _eKGServer) tr = Tracer $ \ev ->
fromMaybe (pure ()) $
doTrace <$> chainTipInformation ev
where
Expand Down

0 comments on commit ce361a9

Please sign in to comment.