Skip to content

Commit e2bad2b

Browse files
committed
connection-manager: counters
* Added `terminating` connections; * Fixed an issue when we trace counters, but they haven't changed.
1 parent 46eed5a commit e2bad2b

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

ouroboros-network-framework/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Breaking changes
88

9+
* Added `terminatingConns` to `ConnectionManagerCounters`
10+
911
## 0.17.0.0 -- 2025-02-25
1012

1113
### Breaking changes

ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/Server/Sim.hs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,17 +1330,17 @@ prop_connection_manager_counters (Fixed rnd) serverAcc (ArbDataFlow dataFlow)
13301330
. List.foldl'
13311331
(\ st ce -> case ce of
13321332
StartClient _ ta ->
1333-
Map.alter (let c = ConnectionManagerCounters 0 0 1 0 0 in
1333+
Map.alter (let c = ConnectionManagerCounters 0 0 1 0 0 0 in
13341334
maybe (Just c) (Just . maxCounters c))
13351335
ta st
13361336

13371337
OutboundConnection _ ta ->
1338-
Map.alter (let c = ConnectionManagerCounters 0 ifDuplex ifUni 0 1 in
1338+
Map.alter (let c = ConnectionManagerCounters 0 ifDuplex ifUni 0 1 0 in
13391339
maybe (Just c) (Just . maxCounters c))
13401340
ta st
13411341

13421342
InboundConnection _ ta ->
1343-
Map.alter (let c = ConnectionManagerCounters 0 ifDuplex ifUni 1 0 in
1343+
Map.alter (let c = ConnectionManagerCounters 0 ifDuplex ifUni 1 0 0 in
13441344
maybe (Just c) (Just . maxCounters c))
13451345
ta st
13461346

@@ -1359,8 +1359,8 @@ prop_connection_manager_counters (Fixed rnd) serverAcc (ArbDataFlow dataFlow)
13591359
(\cmc' provenance ->
13601360
cmc' <>
13611361
if provenance == serverAddress
1362-
then ConnectionManagerCounters 0 0 0 0 1
1363-
else ConnectionManagerCounters 0 0 0 1 0
1362+
then ConnectionManagerCounters 0 0 0 0 1 0
1363+
else ConnectionManagerCounters 0 0 0 1 0 0
13641364
)
13651365
mempty
13661366
conns
@@ -1372,14 +1372,15 @@ prop_connection_manager_counters (Fixed rnd) serverAcc (ArbDataFlow dataFlow)
13721372
maxCounters :: ConnectionManagerCounters
13731373
-> ConnectionManagerCounters
13741374
-> ConnectionManagerCounters
1375-
maxCounters (ConnectionManagerCounters a b c d e)
1376-
(ConnectionManagerCounters a' b' c' d' e') =
1375+
maxCounters (ConnectionManagerCounters a b c d e f)
1376+
(ConnectionManagerCounters a' b' c' d' e' f') =
13771377
ConnectionManagerCounters
13781378
(max a a')
13791379
(max b b')
13801380
(max c c')
13811381
(max d d')
13821382
(max e e')
1383+
(max f f')
13831384

13841385
-- It is possible for the ObservableNetworkState to have discrepancies between the
13851386
-- counters traced by TrConnectionManagerCounters. This leads to different
@@ -1402,10 +1403,14 @@ prop_connection_manager_counters (Fixed rnd) serverAcc (ArbDataFlow dataFlow)
14021403
-- of the total sum.
14031404
-> ConnectionManagerCounters
14041405
-> (Int, Int, Int)
1405-
collapseCounters t (ConnectionManagerCounters _ a b c d) =
1406+
collapseCounters t ConnectionManagerCounters { duplexConns,
1407+
unidirectionalConns,
1408+
inboundConns,
1409+
outboundConns
1410+
} =
14061411
if t
1407-
then (a, b, c + d)
1408-
else (a, b, c + d - a)
1412+
then (duplexConns, unidirectionalConns, inboundConns + outboundConns)
1413+
else (duplexConns, unidirectionalConns, inboundConns + outboundConns - duplexConns)
14091414

14101415
networkStateTracer getState =
14111416
Tracer $ \_ -> getState >>= traceM

ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Core.hs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ import Data.Typeable (Typeable)
4343
import GHC.Stack (CallStack, HasCallStack, callStack)
4444
import System.Random (StdGen, split)
4545

46+
import Data.List qualified as List
4647
import Data.Map.Strict (Map)
4748
import Data.Map.Strict qualified as Map
48-
import Data.Set qualified as Set
49-
5049
import Data.Monoid.Synchronisation
5150
import Data.Set (Set)
51+
import Data.Set qualified as Set
5252
import Data.Tuple (swap)
5353
import Data.Wedge
5454
import Data.Word (Word32)
@@ -209,14 +209,15 @@ connectionStateToCounters state =
209209
<> inboundConn
210210
<> outboundConn
211211

212-
TerminatingState {} -> mempty
212+
TerminatingState {} -> terminatingConn
213213
TerminatedState {} -> mempty
214214
where
215-
fullDuplexConn = ConnectionManagerCounters 1 0 0 0 0
216-
duplexConn = ConnectionManagerCounters 0 1 0 0 0
217-
unidirectionalConn = ConnectionManagerCounters 0 0 1 0 0
218-
inboundConn = ConnectionManagerCounters 0 0 0 1 0
219-
outboundConn = ConnectionManagerCounters 0 0 0 0 1
215+
fullDuplexConn = ConnectionManagerCounters 1 0 0 0 0 0
216+
duplexConn = ConnectionManagerCounters 0 1 0 0 0 0
217+
unidirectionalConn = ConnectionManagerCounters 0 0 1 0 0 0
218+
inboundConn = ConnectionManagerCounters 0 0 0 1 0 0
219+
outboundConn = ConnectionManagerCounters 0 0 0 0 1 0
220+
terminatingConn = ConnectionManagerCounters 0 0 0 0 0 1
220221

221222

222223
getConnThread :: ConnectionState peerAddr handle handleError version m
@@ -781,7 +782,8 @@ with args@Arguments {
781782
else return [ ]
782783

783784
traverse_ (traceWith trTracer . TransitionTrace connStateId) trs
784-
traceCounters stateVar
785+
when (not $ List.null trs) $
786+
traceCounters stateVar
785787

786788
-- Pruning is done in two stages:
787789
-- * an STM transaction which selects which connections to prune, and sets

ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Types.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,16 +695,17 @@ data ConnectionManagerCounters = ConnectionManagerCounters {
695695
-- (including DuplexState connections)
696696
unidirectionalConns :: !Int, -- ^ number of negotiated unidirectional connections
697697
inboundConns :: !Int, -- ^ number of inbound connections
698-
outboundConns :: !Int -- ^ number of outbound connections
698+
outboundConns :: !Int, -- ^ number of outbound connections
699+
terminatingConns :: !Int -- ^ number of terminating connections
699700
}
700701
deriving (Show, Eq, Ord)
701702

702703
instance Semigroup ConnectionManagerCounters where
703-
ConnectionManagerCounters fd1 d1 s1 i1 o1 <> ConnectionManagerCounters fd2 d2 s2 i2 o2 =
704-
ConnectionManagerCounters (fd1 + fd2) (d1 + d2) (s1 + s2) (i1 + i2) (o1 + o2)
704+
ConnectionManagerCounters fd1 d1 s1 i1 o1 t1 <> ConnectionManagerCounters fd2 d2 s2 i2 o2 t2 =
705+
ConnectionManagerCounters (fd1 + fd2) (d1 + d2) (s1 + s2) (i1 + i2) (o1 + o2) (t1 + t2)
705706

706707
instance Monoid ConnectionManagerCounters where
707-
mempty = ConnectionManagerCounters 0 0 0 0 0
708+
mempty = ConnectionManagerCounters 0 0 0 0 0 0
708709

709710
-- | Exceptions used by 'ConnectionManager'.
710711
--

0 commit comments

Comments
 (0)