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 5, 2024
1 parent 36871ba commit 29f997c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
9 changes: 9 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ allow-newer:
-- IMPORTANT
-- Do NOT add more source-repository-package stanzas here unless they are strictly
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.

source-repository-package
type: git
location: https://github.com/IntersectMBO/ouroboros-network
tag: e8896feaf2ffb9758d27c00d842237e2dbd56592
--sha256: sha256-78ulTpgwJuccs3ntjHebkIyrdT7Id572fk0xwianOe0=
subdir: network-mux
ouroboros-network-framework
ouroboros-network
36 changes: 25 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.Types (ConnectionManagerCounters (..),
ConnectionManagerTrace (..))
import Ouroboros.Network.ConnectionManager.ConnMap (ConnMap (..))
import qualified Ouroboros.Network.ConnectionManager.Types as ConnectionManager
import Ouroboros.Network.InboundGovernor (InboundGovernorTrace (..))
import qualified Ouroboros.Network.InboundGovernor as InboundGovernor
Expand Down Expand Up @@ -1132,13 +1133,18 @@ instance Show lAddr => LogFormatting (PeerSelectionActionsTrace SockAddr lAddr)
, "connectionId" .= toJSON connId
, "withProtocolTemp" .= show wf
]
forMachine _dtal (AcquireConnectionError err) =
mconcat [ "kind" .= String "AcquireConnectionError"
, "error" .= show err
]
forHuman = pack . show

instance MetaTrace (PeerSelectionActionsTrace SockAddr lAddr) where
namespaceFor PeerStatusChanged {} = Namespace [] ["StatusChanged"]
namespaceFor PeerStatusChangeFailure {} = Namespace [] ["StatusChangeFailure"]
namespaceFor PeerMonitoringError {} = Namespace [] ["MonitoringError"]
namespaceFor PeerMonitoringResult {} = Namespace [] ["MonitoringResult"]
namespaceFor AcquireConnectionError {} = Namespace [] ["AcquireConnectionError"]

severityFor (Namespace _ ["StatusChanged"]) _ = Just Info
severityFor (Namespace _ ["StatusChangeFailure"]) _ = Just Error
Expand Down Expand Up @@ -1176,10 +1182,10 @@ instance (Show addr, Show versionNumber, Show agreedOptions, LogFormatting addr,
, "remoteAddress" .= forMachine dtal peerAddr
, "provenance" .= String (pack . show $ prov)
]
forMachine dtal (TrUnregisterConnection prov peerAddr) =
forMachine _dtal (TrUnregisterConnection 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 @@ -1255,12 +1261,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 @@ -1285,12 +1291,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 @@ -1497,9 +1511,9 @@ instance MetaTrace (ConnectionManager.AbstractTransitionTrace peerAddr) where

instance (Show addr, LogFormatting addr, ToJSON addr)
=> LogFormatting (ServerTrace 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
38 changes: 28 additions & 10 deletions cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import qualified Ouroboros.Network.BlockFetch.ClientState as BlockFetch
import Ouroboros.Network.BlockFetch.Decision (FetchDecision, FetchDecline (..))
import Ouroboros.Network.ConnectionHandler (ConnectionHandlerTrace (..))
import Ouroboros.Network.ConnectionId (ConnectionId (..))
import Ouroboros.Network.ConnectionManager.ConnMap (ConnMap (..), LocalAddr (..))
import Ouroboros.Network.ConnectionManager.Types (AbstractState (..),
ConnectionManagerCounters (..), ConnectionManagerTrace (..),
OperationResult (..))
Expand Down Expand Up @@ -496,6 +497,7 @@ instance HasSeverityAnnotation (PeerSelectionActionsTrace SockAddr lAddr) where
PeerStatusChangeFailure {} -> Error
PeerMonitoringError {} -> Error
PeerMonitoringResult {} -> Debug
AcquireConnectionError {} -> Info

instance HasPrivacyAnnotation PeerSelectionCounters
instance HasSeverityAnnotation PeerSelectionCounters where
Expand Down Expand Up @@ -2059,6 +2061,10 @@ instance Show lAddr => ToObject (PeerSelectionActionsTrace SockAddr lAddr) where
, "connectionId" .= toJSON connId
, "withProtocolTemp" .= show wf
]
toObject _verb (AcquireConnectionError err) =
mconcat [ "kind" .= String "AcquireConnectionError"
, "error" .= show err
]

instance ToObject PeerSelectionCounters where
toObject _verb PeerSelectionCounters {..} =
Expand Down Expand Up @@ -2255,6 +2261,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 (ConnectionManagerTrace addr (ConnectionHandlerTrace versionNumber agreedOptions)) where
Expand All @@ -2266,10 +2276,10 @@ instance (Show addr, Show versionNumber, Show agreedOptions, ToObject addr,
, "remoteAddress" .= toObject verb peerAddr
, "provenance" .= String (pack . show $ prov)
]
TrUnregisterConnection prov peerAddr ->
TrUnregisterConnection 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 @@ -2350,7 +2360,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 @@ -2375,12 +2385,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 @@ -2415,9 +2433,9 @@ instance (Show addr, ToObject addr, ToJSON addr)

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

0 comments on commit 29f997c

Please sign in to comment.