Skip to content

Commit

Permalink
Added PeerSelectionCounters tracer
Browse files Browse the repository at this point in the history
Added Counters to ConnectionManager and PeerSelection Trace Counters

Fixed compilation errors and added necessary instances to the counters
  • Loading branch information
bolt12 authored and coot committed May 13, 2021
1 parent 1b499a3 commit 7f4a3d2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 10 deletions.
6 changes: 6 additions & 0 deletions cardano-node/src/Cardano/Tracing/Config.hs
Expand Up @@ -43,6 +43,7 @@ type TraceChainSyncProtocol = ("TraceChainSyncProtocol" :: Symbol)
type TraceConnectionManager = ("TraceConnectionManager" :: Symbol)
type DebugPeerSelectionInitiator = ("DebugPeerSelectionInitiator" :: Symbol)
type DebugPeerSelectionInitiatorResponder = ("DebugPeerSelectionInitiatorResponder" :: Symbol)
type TracePeerSelectionCounters = ("TracePeerSelectionCounters" :: Symbol)
type TraceDiffusionInitialization = ("TraceDiffusionInitialization" :: Symbol)
type TraceDnsResolver = ("TraceDnsResolver" :: Symbol)
type TraceForge = ("TraceForge" :: Symbol)
Expand Down Expand Up @@ -101,6 +102,7 @@ data TraceSelection
, traceConnectionManager :: OnOff TraceConnectionManager
, traceDebugPeerSelectionInitiatorTracer :: OnOff DebugPeerSelectionInitiator
, traceDebugPeerSelectionInitiatorResponderTracer :: OnOff DebugPeerSelectionInitiatorResponder
, tracePeerSelectionCounters :: OnOff TracePeerSelectionCounters
, traceDiffusionInitialization :: OnOff TraceDiffusionInitialization
, traceDnsResolver :: OnOff TraceDnsResolver
, traceForge :: OnOff TraceForge
Expand Down Expand Up @@ -165,6 +167,8 @@ traceConfigParser v =
debugPeerSelectionInitiator = OnOff False
debugPeerSelectionInitiatorResponder :: OnOff DebugPeerSelectionInitiatorResponder
debugPeerSelectionInitiatorResponder = OnOff False
trPeerSelectionCounters :: OnOff TracePeerSelectionCounters
trPeerSelectionCounters = OnOff False
diffusionInitialization :: OnOff TraceDiffusionInitialization
diffusionInitialization = OnOff False
dnsResolver :: OnOff TraceDnsResolver
Expand Down Expand Up @@ -241,6 +245,8 @@ traceConfigParser v =
.!= debugPeerSelectionInitiator
<*> v .:? getName debugPeerSelectionInitiatorResponder
.!= debugPeerSelectionInitiatorResponder
<*> v .:? getName trPeerSelectionCounters
.!= trPeerSelectionCounters
<*> v .:? getName diffusionInitialization .!= diffusionInitialization
<*> v .:? getName dnsResolver .!= dnsResolver
<*> v .:? getName forge .!= forge
Expand Down
27 changes: 21 additions & 6 deletions cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs
Expand Up @@ -73,7 +73,8 @@ import Ouroboros.Network.TxSubmission.Inbound (TraceTxSubmissionInboun
import Ouroboros.Network.TxSubmission.Outbound (TraceTxSubmissionOutbound (..))
import Ouroboros.Network.Diffusion (TraceLocalRootPeers, TracePublicRootPeers,
TracePeerSelection (..), PeerSelectionActionsTrace (..),
ConnectionManagerTrace (..), ConnectionHandlerTrace (..))
ConnectionManagerTrace (..), ConnectionHandlerTrace (..),
PeerSelectionCounters (..))
import Ouroboros.Network.Server2 (ServerTrace)
import qualified Ouroboros.Network.Server2 as Server
import Ouroboros.Network.InboundGovernor (InboundGovernorTrace)
Expand Down Expand Up @@ -390,6 +391,10 @@ instance HasSeverityAnnotation (PeerSelectionActionsTrace Socket.SockAddr) where
PeerMonitoringError {} -> Error
PeerMonitoringResult {} -> Debug

instance HasPrivacyAnnotation PeerSelectionCounters
instance HasSeverityAnnotation PeerSelectionCounters where
getSeverityAnnotation _ = Info

instance HasPrivacyAnnotation (ConnectionManagerTrace addr connTrace)
instance HasSeverityAnnotation (ConnectionManagerTrace addr (ConnectionHandlerTrace versionNumber agreedOptions)) where
getSeverityAnnotation ev =
Expand Down Expand Up @@ -420,7 +425,7 @@ instance HasSeverityAnnotation (ConnectionManagerTrace addr (ConnectionHandlerTr
TrConnectionCleanup {} -> Debug
TrConnectionTimeWait {} -> Debug
TrConnectionTimeWaitDone {} -> Debug
TrDebugState {} -> Debug
TrConnectionManagerCounters {} -> Info

instance HasPrivacyAnnotation (ServerTrace addr)
instance HasSeverityAnnotation (ServerTrace addr) where
Expand Down Expand Up @@ -582,6 +587,11 @@ instance Transformable Text IO (PeerSelectionActionsTrace Socket.SockAddr) where
instance HasTextFormatter (PeerSelectionActionsTrace Socket.SockAddr) where
formatText a _ = pack (show a)

instance Transformable Text IO PeerSelectionCounters where
trTransformer = trStructuredText
instance HasTextFormatter PeerSelectionCounters where
formatText a _ = pack (show a)

instance (Show addr, Show versionNumber, Show agreedOptions, ToObject addr)
=> Transformable Text IO (ConnectionManagerTrace
addr
Expand Down Expand Up @@ -1194,6 +1204,11 @@ instance ToObject (PeerSelectionActionsTrace Socket.SockAddr) where
mkObject [ "kind" .= String "PeerSelectionAction"
, "event" .= show ev ]

instance ToObject PeerSelectionCounters where
toObject _verb ev =
mkObject [ "kind" .= String "PeerSelectionCounters"
, "event" .= show ev ]

instance (Show addr, Show versionNumber, Show agreedOptions, ToObject addr)
=> ToObject (ConnectionManagerTrace addr (ConnectionHandlerTrace versionNumber agreedOptions)) where
toObject verb ev =
Expand Down Expand Up @@ -1293,7 +1308,7 @@ instance (Show addr, Show versionNumber, Show agreedOptions, ToObject addr)
mkObject
[ "kind" .= String "PruneConnections"
, "peers" .= toJSON (toObject verb `map` peers)
]
]
TrConnectionCleanup connId ->
mkObject
[ "kind" .= String "ConnectionCleanup"
Expand All @@ -1309,10 +1324,10 @@ instance (Show addr, Show versionNumber, Show agreedOptions, ToObject addr)
[ "kind" .= String "ConnectionTimeWaitDone"
, "connectionId" .= toObject verb connId
]
TrDebugState cmState ->
TrConnectionManagerCounters cmCounters ->
mkObject
[ "kind" .= String "DebugState"
, "state" .= String (pack . show $ cmState)
[ "kind" .= String "ConnectionManagerCounters"
, "state" .= String (pack . show $ cmCounters)
]


Expand Down
58 changes: 54 additions & 4 deletions cardano-node/src/Cardano/Tracing/Tracers.hs
Expand Up @@ -77,7 +77,11 @@ import Ouroboros.Network.BlockFetch.ClientState (TraceLabelPeer (..))
import Ouroboros.Network.BlockFetch.Decision (FetchDecision, FetchDecline (..))
import Ouroboros.Network.Point (fromWithOrigin, withOrigin)
import Ouroboros.Network.Protocol.LocalStateQuery.Type (ShowQuery)
import Ouroboros.Network.Diffusion (DiffusionTracers (..))
import Ouroboros.Network.Diffusion ( DiffusionTracers (..)
, ConnectionManagerTrace (..)
, PeerSelectionCounters (..)
, ConnectionManagerCounters (..)
)
import qualified Ouroboros.Network.Diffusion as Diffusion

import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
Expand Down Expand Up @@ -294,10 +298,15 @@ mkTracers blockConfig tOpts@(TracingOn trSel) tr nodeKern ekgDirect = do
dtDebugPeerSelectionInitiatorResponderTracer =
tracerOnOff (traceDebugPeerSelectionInitiatorResponderTracer trSel)
verb "DebugPeerSelection" tr,
dtTracePeerSelectionCounters =
tracePeerSelectionCountersMetrics ekgDirect $
tracerOnOff (tracePeerSelectionCounters trSel)
verb "PeerSelectionCounters" tr,
dtPeerSelectionActionsTracer =
tracerOnOff (tracePeerSelectionActions trSel) verb "PeerSelectionActions" tr,
dtConnectionManagerTracer =
tracerOnOff (traceConnectionManager trSel) verb "ConnectionManager" tr,
traceConnectionManagerTraceMetrics ekgDirect $
tracerOnOff (traceConnectionManager trSel) verb "ConnectionManager" tr,
dtServerTracer =
tracerOnOff (traceServer trSel) verb "Server" tr,
dtInboundGovernorTracer =
Expand Down Expand Up @@ -454,8 +463,8 @@ sendEKGDirectCounter ekgDirect name = do
Counter.inc counter
pure $ SMap.insert name counter registeredMap

_sendEKGDirectInt :: Integral a => EKGDirect -> Text -> a -> IO ()
_sendEKGDirectInt ekgDirect name val = do
sendEKGDirectInt :: Integral a => EKGDirect -> Text -> a -> IO ()
sendEKGDirectInt ekgDirect name val = do
modifyMVar_ (ekgGauges ekgDirect) $ \registeredMap -> do
case SMap.lookup name registeredMap of
Just gauge -> do
Expand Down Expand Up @@ -599,6 +608,7 @@ mkConsensusTracers mbEKGDirect trSel verb tr nodeKern fStats = do
when (isRollForward ev) $
sendEKGDirectCounter ekgDirect "cardano.node.metrics.served.header.counter.int"


traceLeadershipChecks ::
forall blk
. ( Consensus.RunNode blk
Expand Down Expand Up @@ -1034,6 +1044,46 @@ teeTraceBlockFetchDecisionElide
-> Tracer IO (WithSeverity [TraceLabelPeer peer (FetchDecision [Point (Header blk)])])
teeTraceBlockFetchDecisionElide = elideToLogObject

--------------------------------------------------------------------------------
-- PeerSelection Tracers
--------------------------------------------------------------------------------

traceConnectionManagerTraceMetrics
:: Maybe EKGDirect
-> Tracer IO (ConnectionManagerTrace peerAddr handlerTrace)
-> Tracer IO (ConnectionManagerTrace peerAddr handlerTrace)
traceConnectionManagerTraceMetrics Nothing tracer = tracer
traceConnectionManagerTraceMetrics (Just ekgDirect) _ = Tracer cmtTracer
where
cmtTracer :: (ConnectionManagerTrace peerAddr handlerTrace) -> IO ()
cmtTracer (TrConnectionManagerCounters
(ConnectionManagerCounters
numberConns
duplexConns
uniConns
incomingConns
outgoingConns
)
) = do
sendEKGDirectInt ekgDirect "cardano.node.metrics.connectionManager.numberConns" numberConns
sendEKGDirectInt ekgDirect "cardano.node.metrics.connectionManager.duplexConns" duplexConns
sendEKGDirectInt ekgDirect "cardano.node.metrics.connectionManager.uniConns" uniConns
sendEKGDirectInt ekgDirect "cardano.node.metrics.connectionManager.incomingConns" incomingConns
sendEKGDirectInt ekgDirect "cardano.node.metrics.connectionManager.outgoingConns" outgoingConns
cmtTracer _ = return ()



tracePeerSelectionCountersMetrics :: Maybe EKGDirect -> Tracer IO PeerSelectionCounters -> Tracer IO PeerSelectionCounters
tracePeerSelectionCountersMetrics Nothing tracer = tracer
tracePeerSelectionCountersMetrics (Just ekgDirect) _ = Tracer pscTracer
where
pscTracer :: PeerSelectionCounters -> IO ()
pscTracer (PeerSelectionCounters cold warm hot) = do
sendEKGDirectInt ekgDirect "cardano.node.metrics.peerSelection.cold" cold
sendEKGDirectInt ekgDirect "cardano.node.metrics.peerSelection.warm" warm
sendEKGDirectInt ekgDirect "cardano.node.metrics.peerSelection.hot" hot


-- | get information about a chain fragment

Expand Down

0 comments on commit 7f4a3d2

Please sign in to comment.