Skip to content

Commit

Permalink
Handshake and LocalHandshake tracers
Browse files Browse the repository at this point in the history
Add handshake and localhandshake tracer with config options.
  • Loading branch information
karknu committed Mar 11, 2020
1 parent b9739a3 commit 93fc7b7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cardano-config/src/Cardano/Config/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ instance FromJSON NodeConfiguration where
<*> v .:? "TraceTxInbound" .!= False
<*> v .:? "TraceTxOutbound" .!= False
<*> v .:? "TraceTxSubmissionProtocol" .!= False
<*> v .:? "TraceHandshake" .!= False
<*> v .:? "TraceLocalHandshake" .!= False

pure $ NodeConfiguration
{ ncProtocol = ptcl
Expand Down Expand Up @@ -328,6 +330,8 @@ data TraceOptions = TraceOptions
, traceTxInbound :: !Bool
, traceTxOutbound :: !Bool
, traceTxSubmissionProtocol :: !Bool
, traceHandshake :: !Bool
, traceLocalHandshake :: !Bool
} deriving (Eq, Show)

--------------------------------------------------------------------------------
Expand Down
30 changes: 30 additions & 0 deletions cardano-config/src/Cardano/Tracing/ToObjectOrphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import Ouroboros.Network.BlockFetch.ClientState
(TraceFetchClientState (..), TraceLabelPeer (..))
import Ouroboros.Network.BlockFetch.Decision (FetchDecision)
import Ouroboros.Network.Codec (AnyMessage (..))
import qualified Ouroboros.Network.NodeToClient as NtC
import qualified Ouroboros.Network.NodeToNode as NtN
import Ouroboros.Network.NodeToNode
(WithAddr(..), ErrorPolicyTrace(..), TraceSendRecv (..))
import Ouroboros.Network.Protocol.TxSubmission.Type
Expand Down Expand Up @@ -227,6 +229,14 @@ instance DefineSeverity (WithMuxBearer peer MuxTrace) where
MuxTraceRecvDeltaQObservation {} -> Debug
MuxTraceRecvDeltaQSample {} -> Info

instance DefinePrivacyAnnotation NtN.HandshakeTr
instance DefineSeverity NtN.HandshakeTr where
defineSeverity _ = Info

instance DefinePrivacyAnnotation NtC.HandshakeTr
instance DefineSeverity NtC.HandshakeTr where
defineSeverity _ = Info

instance DefinePrivacyAnnotation (WithTip blk (ChainDB.TraceEvent blk))
instance DefineSeverity (WithTip blk (ChainDB.TraceEvent blk)) where
defineSeverity (WithTip _tip ev) = defineSeverity ev
Expand Down Expand Up @@ -465,6 +475,14 @@ instance (Show peer)
=> Transformable Text IO (WithMuxBearer peer MuxTrace) where
trTransformer = defaultTextTransformer

-- transform @NtN.HandshakeTrace@
instance Transformable Text IO NtN.HandshakeTr where
trTransformer = defaultTextTransformer

-- transform @NtC.HandshakeTrace@
instance Transformable Text IO NtC.HandshakeTr where
trTransformer = defaultTextTransformer

-- transform @TraceEvent@
instance (Condense (HeaderHash blk), LedgerSupportsProtocol blk)
=> Transformable Text IO (WithTip blk (ChainDB.TraceEvent blk)) where
Expand Down Expand Up @@ -655,6 +673,18 @@ instance (Show peer)
, "bearer" .= show b
, "event" .= show ev ]

instance ToObject NtN.HandshakeTr where
toObject _verb (WithMuxBearer b ev) =
mkObject [ "kind" .= String "HandshakeTrace"
, "bearer" .= show b
, "event" .= show ev ]

instance ToObject NtC.HandshakeTr where
toObject _verb (WithMuxBearer b ev) =
mkObject [ "kind" .= String "LocalHandshakeTrace"
, "bearer" .= show b
, "event" .= show ev ]

instance (Condense (HeaderHash blk), LedgerSupportsProtocol blk)
=> ToObject (WithTip blk (ChainDB.TraceEvent blk)) where
-- example: turn off any tracing of @TraceEvent@s when minimal verbosity level is set
Expand Down
4 changes: 2 additions & 2 deletions cardano-node/src/Cardano/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ handleSimpleNode p trace nodeTracers npm onKernel = do
, dtLocalErrorPolicyTracer = localErrorPolicyTracer nodeTracers'
, dtMuxTracer = muxTracer nodeTracers'
, dtMuxLocalTracer = nullTracer
, dtHandshakeTracer = nullTracer
, dtHandshakeLocalTracer = nullTracer
, dtHandshakeTracer = handshakeTracer nodeTracers'
, dtHandshakeLocalTracer = localHandshakeTracer nodeTracers'
}

createTracers
Expand Down
21 changes: 18 additions & 3 deletions cardano-node/src/Cardano/Tracing/Tracers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ import Ouroboros.Network.Block (Point, BlockNo(..),
blockNo, unBlockNo, unSlotNo)
import Ouroboros.Network.BlockFetch.Decision (FetchDecision)
import Ouroboros.Network.BlockFetch.ClientState (TraceLabelPeer (..))
import Ouroboros.Network.NodeToNode (WithAddr, ErrorPolicyTrace)
import qualified Ouroboros.Network.NodeToClient as NtC
import qualified Ouroboros.Network.NodeToNode as NtN
import Ouroboros.Network.Point (fromWithOrigin)
import Ouroboros.Network.Subscription

Expand Down Expand Up @@ -88,11 +89,13 @@ data Tracers peer localPeer blk = Tracers
-- | Trace the DNS resolver
, dnsResolverTracer :: Tracer IO (WithDomainName DnsTrace)
-- | Trace error policy resolution
, errorPolicyTracer :: Tracer IO (WithAddr Socket.SockAddr ErrorPolicyTrace)
, errorPolicyTracer :: Tracer IO (NtN.WithAddr Socket.SockAddr NtN.ErrorPolicyTrace)
-- | Trace local error policy resolution
, localErrorPolicyTracer :: Tracer IO (WithAddr Socket.SockAddr ErrorPolicyTrace)
, localErrorPolicyTracer :: Tracer IO (NtN.WithAddr Socket.SockAddr NtN.ErrorPolicyTrace)
-- | Trace the Mux
, muxTracer :: Tracer IO (WithMuxBearer peer MuxTrace)
, handshakeTracer :: Tracer IO NtN.HandshakeTr
, localHandshakeTracer :: Tracer IO NtC.HandshakeTr
}

data ForgeTracers = ForgeTracers
Expand All @@ -119,6 +122,8 @@ nullTracers = Tracers
, errorPolicyTracer = nullTracer
, localErrorPolicyTracer = nullTracer
, muxTracer = nullTracer
, handshakeTracer = nullTracer
, localHandshakeTracer = nullTracer
}


Expand Down Expand Up @@ -231,6 +236,16 @@ mkTracers traceOptions tracer = do
$ annotateSeverity
$ toLogObject' StructuredLogging tracingVerbosity
$ appendName "Mux" tracer
, handshakeTracer
= tracerOnOff (traceHandshake traceOptions)
$ annotateSeverity
$ toLogObject' StructuredLogging tracingVerbosity
$ appendName "Handshake" tracer
, localHandshakeTracer
= tracerOnOff (traceLocalHandshake traceOptions)
$ annotateSeverity
$ toLogObject' StructuredLogging tracingVerbosity
$ appendName "LocalHandshake" tracer
}
where
-- Turn on/off a tracer depending on what was parsed from the command line.
Expand Down
6 changes: 6 additions & 0 deletions configuration/configuration-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,9 @@ TraceTxOutbound: False

# Trace TxSubmission protocol messages.
TraceTxSubmissionProtocol: False

# Trace Handshake protocol messages.
TraceHandshake: False

# Trace Local Handshake protocol messages.
TraceLocalHandshake: False

0 comments on commit 93fc7b7

Please sign in to comment.