Skip to content

Commit

Permalink
Updated with connection manager changes
Browse files Browse the repository at this point in the history
  • Loading branch information
coot committed Dec 19, 2024
1 parent a0b009e commit b22f1a0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
31 changes: 20 additions & 11 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/P2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Ouroboros.Network.ConnectionHandler (ConnectionHandlerTrace (..
import Ouroboros.Network.ConnectionId (ConnectionId (..))
import Ouroboros.Network.ConnectionManager.Core as ConnectionManager (Trace (..))
import Ouroboros.Network.ConnectionManager.Types (ConnectionManagerCounters (..))
import Ouroboros.Network.ConnectionManager.ConnMap (ConnMap (..))
import qualified Ouroboros.Network.ConnectionManager.Types as ConnectionManager
import Ouroboros.Network.InboundGovernor as InboundGovernor (Trace (..))
import qualified Ouroboros.Network.InboundGovernor as InboundGovernor
Expand Down Expand Up @@ -1205,10 +1206,10 @@ instance (Show addr, Show versionNumber, Show agreedOptions, LogFormatting addr,
, "remoteAddress" .= forMachine dtal peerAddr
, "provenance" .= String (pack . show $ prov)
]
forMachine dtal (TrReleaseConnection prov peerAddr) =
forMachine dtal (TrReleaseConnection prov connId) =
mconcat $ reverse
[ "kind" .= String "UnregisterConnection"
, "remoteAddress" .= forMachine dtal peerAddr
, "remoteAddress" .= toJSON connId
, "provenance" .= String (pack . show $ prov)
]
forMachine _dtal (TrConnect (Just localAddress) remoteAddress) =
Expand Down Expand Up @@ -1284,12 +1285,12 @@ instance (Show addr, Show versionNumber, Show agreedOptions, LogFormatting addr,
, "remoteAddress" .= forMachine dtal remoteAddress
, "connectionState" .= toJSON connState
]
forMachine dtal (TrPruneConnections pruningSet numberPruned chosenPeers) =
forMachine _dtal (TrPruneConnections pruningSet numberPruned chosenPeers) =
mconcat
[ "kind" .= String "PruneConnections"
, "prunedPeers" .= toJSON pruningSet
, "numberPrunedPeers" .= toJSON numberPruned
, "choiceSet" .= toJSON (forMachine dtal `Set.map` chosenPeers)
, "choiceSet" .= toJSON (toJSON `Set.map` chosenPeers)
]
forMachine _dtal (TrConnectionCleanup connId) =
mconcat
Expand All @@ -1314,12 +1315,20 @@ instance (Show addr, Show versionNumber, Show agreedOptions, LogFormatting addr,
forMachine _dtal (TrState cmState) =
mconcat
[ "kind" .= String "ConnectionManagerState"
, "state" .= listValue (\(addr, connState) ->
, "state" .= listValue (\(remoteAddr, inner) ->
object
[ "remoteAddress" .= toJSON addr
, "connectionState" .= toJSON connState
])
(Map.toList cmState)
[ "connections" .=
listValue (\(localAddr, connState) ->
object
[ "localAddress" .= localAddr
, "state" .= toJSON connState
]
)
(Map.toList inner)
, "remoteAddress" .= toJSON remoteAddr
]
)
(Map.toList (getConnMap cmState))
]
forMachine _dtal (ConnectionManager.TrUnexpectedlyFalseAssertion info) =
mconcat
Expand Down Expand Up @@ -1526,9 +1535,9 @@ instance MetaTrace (ConnectionManager.AbstractTransitionTrace peerAddr) where

instance (Show addr, LogFormatting addr, ToJSON addr)
=> LogFormatting (Server.Trace addr) where
forMachine dtal (TrAcceptConnection peerAddr) =
forMachine dtal (TrAcceptConnection connId) =
mconcat [ "kind" .= String "AcceptConnection"
, "address" .= forMachine dtal peerAddr
, "address" .= toJSON connId
]
forMachine _dtal (TrAcceptError exception) =
mconcat [ "kind" .= String "AcceptErroor"
Expand Down
33 changes: 23 additions & 10 deletions cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Ouroboros.Network.BlockFetch.Decision (FetchDecision, FetchDecl
import Ouroboros.Network.ConnectionHandler (ConnectionHandlerTrace (..))
import Ouroboros.Network.ConnectionId (ConnectionId (..))
import Ouroboros.Network.ConnectionManager.Core as ConnMgr (Trace (..))
import Ouroboros.Network.ConnectionManager.ConnMap (ConnMap (..), LocalAddr (..))
import Ouroboros.Network.ConnectionManager.Types (AbstractState (..),
ConnectionManagerCounters (..),
OperationResult (..))
Expand Down Expand Up @@ -2329,6 +2330,10 @@ instance (Show versionNumber, ToJSON versionNumber, ToJSON agreedOptions)
, "command" .= show cerr
]

instance ToJSON addr => ToJSON (LocalAddr addr) where
toJSON (LocalAddr addr) = toJSON addr
toJSON UnknownLocalAddr = Null

instance (Show addr, Show versionNumber, Show agreedOptions, ToObject addr,
ToJSON addr, ToJSON versionNumber, ToJSON agreedOptions)
=> ToObject (ConnMgr.Trace addr (ConnectionHandlerTrace versionNumber agreedOptions)) where
Expand All @@ -2340,10 +2345,10 @@ instance (Show addr, Show versionNumber, Show agreedOptions, ToObject addr,
, "remoteAddress" .= toObject verb peerAddr
, "provenance" .= String (pack . show $ prov)
]
TrReleaseConnection prov peerAddr ->
TrReleaseConnection prov connId ->
mconcat $ reverse
[ "kind" .= String "UnregisterConnection"
, "remoteAddress" .= toObject verb peerAddr
, "remoteAddress" .= toJSON connId
, "provenance" .= String (pack . show $ prov)
]
TrConnect (Just localAddress) remoteAddress ->
Expand Down Expand Up @@ -2424,7 +2429,7 @@ instance (Show addr, Show versionNumber, Show agreedOptions, ToObject addr,
[ "kind" .= String "PruneConnections"
, "prunedPeers" .= toJSON pruningSet
, "numberPrunedPeers" .= toJSON numberPruned
, "choiceSet" .= toJSON (toObject verb `Set.map` chosenPeers)
, "choiceSet" .= toJSON (toJSON `Set.map` chosenPeers)
]
TrConnectionCleanup connId ->
mconcat
Expand All @@ -2449,12 +2454,20 @@ instance (Show addr, Show versionNumber, Show agreedOptions, ToObject addr,
TrState cmState ->
mconcat
[ "kind" .= String "ConnectionManagerState"
, "state" .= listValue (\(addr, connState) ->
, "state" .= listValue (\(remoteAddr, inner) ->
Aeson.object
[ "remoteAddress" .= toJSON addr
, "connectionState" .= toJSON connState
])
(Map.toList cmState)
[ "connections" .=
listValue (\(localAddr, connState) ->
Aeson.object
[ "localAddress" .= localAddr
, "state" .= toJSON connState
]
)
(Map.toList inner)
, "remoteAddress" .= toJSON remoteAddr
]
)
(Map.toList (getConnMap cmState))
]
ConnMgr.TrUnexpectedlyFalseAssertion info ->
mconcat
Expand Down Expand Up @@ -2489,9 +2502,9 @@ instance (Show addr, ToObject addr, ToJSON addr)

instance (Show addr, ToObject addr, ToJSON addr)
=> ToObject (Server.Trace addr) where
toObject verb (Server.TrAcceptConnection peerAddr) =
toObject verb (Server.TrAcceptConnection connId) =
mconcat [ "kind" .= String "AcceptConnection"
, "address" .= toObject verb peerAddr
, "connectionId" .= toJSON connId
]
toObject _verb (Server.TrAcceptError exception) =
mconcat [ "kind" .= String "AcceptErroor"
Expand Down

0 comments on commit b22f1a0

Please sign in to comment.