Skip to content

Commit 08f3f8f

Browse files
committed
ouroboros-network:logging
1 parent eb2e9d4 commit 08f3f8f

File tree

12 files changed

+2207
-0
lines changed

12 files changed

+2207
-0
lines changed

ouroboros-network/logging/Ouroboros/Network/Logging.hs

Lines changed: 418 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE PackageImports #-}
3+
4+
-------------------------------------------------------------------------------
5+
6+
-- Orphan instances module for Cardano tracer.
7+
{-# OPTIONS_GHC -Wno-orphans #-}
8+
-- Extracted from "cardano-node" `Cardano.Node.Tracing.Tracers.P2P`.
9+
-- Branch "ana/10.6-final-integration-mix"
10+
11+
-------------------------------------------------------------------------------
12+
13+
module Ouroboros.Network.Logging.PeerSelection.ChurnCounters () where
14+
15+
-------------------------------------------------------------------------------
16+
17+
---------
18+
-- base -
19+
---------
20+
--
21+
---------------------
22+
-- Package: "aeson" -
23+
---------------------
24+
import "aeson" Data.Aeson (Value (String), (.=))
25+
---------------------------------
26+
-- Package: "ouroboros-network" -
27+
---------------------------------
28+
import "ouroboros-network" Ouroboros.Network.PeerSelection.Churn
29+
( ChurnCounters (..) )
30+
--------------------
31+
-- Package: "text" -
32+
--------------------
33+
import "text" Data.Text (pack)
34+
------------------------------
35+
-- Package: trace-dispatcher -
36+
------------------------------
37+
import "trace-dispatcher" Cardano.Logging
38+
39+
--------------------------------------------------------------------------------
40+
-- ChurnCounters Tracer.
41+
--------------------------------------------------------------------------------
42+
43+
instance LogFormatting ChurnCounters where
44+
forMachine _dtal (ChurnCounter action c) =
45+
mconcat [ "kind" .= String "ChurnCounter"
46+
, "action" .= String (pack $ show action)
47+
, "counter" .= c
48+
]
49+
asMetrics (ChurnCounter action c) =
50+
[ IntM
51+
("peerSelection.churn." <> pack (show action))
52+
(fromIntegral c)
53+
]
54+
55+
instance MetaTrace ChurnCounters where
56+
namespaceFor ChurnCounter {} = Namespace [] ["ChurnCounters"]
57+
58+
severityFor (Namespace _ ["ChurnCounters"]) _ = Just Info
59+
severityFor _ _ = Nothing
60+
61+
documentFor (Namespace _ ["ChurnCounters"]) = Just
62+
"churn counters"
63+
documentFor _ = Nothing
64+
65+
metricsDocFor (Namespace _ ["ChurnCounters"]) =
66+
[ ("peerSelection.churn.DecreasedActivePeers", "number of decreased active peers")
67+
, ("peerSelection.churn.IncreasedActivePeers", "number of increased active peers")
68+
, ("peerSelection.churn.DecreasedActiveBigLedgerPeers", "number of decreased active big ledger peers")
69+
, ("peerSelection.churn.IncreasedActiveBigLedgerPeers", "number of increased active big ledger peers")
70+
, ("peerSelection.churn.DecreasedEstablishedPeers", "number of decreased established peers")
71+
, ("peerSelection.churn.IncreasedEstablishedPeers", "number of increased established peers")
72+
, ("peerSelection.churn.IncreasedEstablishedBigLedgerPeers", "number of increased established big ledger peers")
73+
, ("peerSelection.churn.DecreasedEstablishedBigLedgerPeers", "number of decreased established big ledger peers")
74+
, ("peerSelection.churn.DecreasedKnownPeers", "number of decreased known peers")
75+
, ("peerSelection.churn.IncreasedKnownPeers", "number of increased known peers")
76+
, ("peerSelection.churn.DecreasedKnownBigLedgerPeers", "number of decreased known big ledger peers")
77+
, ("peerSelection.churn.IncreasedKnownBigLedgerPeers", "number of increased known big ledger peers")
78+
]
79+
metricsDocFor _ = []
80+
81+
allNamespaces =[
82+
Namespace [] ["ChurnCounters"]
83+
]
84+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{-# LANGUAGE PackageImports #-}
2+
3+
-------------------------------------------------------------------------------
4+
5+
module Ouroboros.Network.Logging.PeerSelection.Governor () where
6+
7+
-------------------------------------------------------------------------------
8+
9+
------------------
10+
-- Package: self -
11+
------------------
12+
import Ouroboros.Network.Logging.PeerSelection.Governor.DebugPeerSelection ()
13+
import Ouroboros.Network.Logging.PeerSelection.Governor.PeerSelectionCounters ()
14+
import Ouroboros.Network.Logging.PeerSelection.Governor.TracePeerSelection ()
15+
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{-# LANGUAGE FlexibleInstances #-}
2+
{-# LANGUAGE NamedFieldPuns #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE PackageImports #-}
5+
6+
-------------------------------------------------------------------------------
7+
8+
-- Orphan instances module for Cardano tracer.
9+
{-# OPTIONS_GHC -Wno-orphans #-}
10+
-- Extracted from "cardano-node" `Cardano.Node.Tracing.Tracers.P2P`.
11+
-- Branch "ana/10.6-final-integration-mix"
12+
13+
{- TODO: All references to package "cardano-diffusion" were removed.
14+
-- See all the TODO annotations.
15+
import "cardano-diffusion" -- "cardano-diffusion:???"
16+
Cardano.Network.PeerSelection.Governor.Monitor
17+
( ExtraTrace (TraceLedgerStateJudgementChanged, TraceUseBootstrapPeersChanged)
18+
)
19+
--}
20+
21+
-------------------------------------------------------------------------------
22+
23+
module Ouroboros.Network.Logging.PeerSelection.Governor.DebugPeerSelection () where
24+
25+
-------------------------------------------------------------------------------
26+
27+
---------
28+
-- base -
29+
---------
30+
--
31+
---------------------
32+
-- Package: "aeson" -
33+
---------------------
34+
import "aeson" Data.Aeson (Value (String), (.=))
35+
-----------------------
36+
-- Package: "network" -
37+
-----------------------
38+
import "network" Network.Socket (SockAddr)
39+
---------------------------------
40+
-- Package: "ouroboros-network" -
41+
---------------------------------
42+
import "ouroboros-network" -- "ouroboros-network:ouroboros-network"
43+
Ouroboros.Network.PeerSelection.Governor.Types
44+
( DebugPeerSelection (..)
45+
, PeerSelectionState (..)
46+
)
47+
------------------
48+
-- Package: text -
49+
------------------
50+
import "text" Data.Text (pack)
51+
------------------------------
52+
-- Package: trace-dispatcher -
53+
------------------------------
54+
import "trace-dispatcher" Cardano.Logging
55+
------------------
56+
-- Package: self -
57+
------------------
58+
import Ouroboros.Network.Logging.PeerSelection.Governor.Utils
59+
( peerSelectionTargetsToObject
60+
)
61+
62+
--------------------------------------------------------------------------------
63+
-- DebugPeerSelection Tracer
64+
--------------------------------------------------------------------------------
65+
66+
{-- TODO: Before "cardano-diffusion" removal:
67+
instance LogFormatting (DebugPeerSelection Cardano.ExtraState PeerTrustable (Cardano.PublicRootPeers.ExtraPeers SockAddr) SockAddr) where
68+
--}
69+
instance ( Show extraState
70+
, Show extraFlags
71+
, Show extraPeers
72+
)
73+
=> LogFormatting (DebugPeerSelection extraState extraFlags extraPeers SockAddr) where
74+
forMachine _dtal@DNormal (TraceGovernorState blockedAt wakeupAfter
75+
_st@PeerSelectionState { targets }) =
76+
mconcat [ "kind" .= String "DebugPeerSelection"
77+
, "blockedAt" .= String (pack $ show blockedAt)
78+
, "wakeupAfter" .= String (pack $ show wakeupAfter)
79+
, "targets" .= peerSelectionTargetsToObject targets
80+
{-- TODO:Before "cardano-diffusion" removal:
81+
82+
, "counters" .= forMachine dtal (peerSelectionStateToCounters Cardano.PublicRootPeers.toSet Cardano.cardanoPeerSelectionStatetoCounters st)
83+
--}
84+
]
85+
forMachine _ (TraceGovernorState blockedAt wakeupAfter ev) =
86+
mconcat [ "kind" .= String "DebugPeerSelection"
87+
, "blockedAt" .= String (pack $ show blockedAt)
88+
, "wakeupAfter" .= String (pack $ show wakeupAfter)
89+
, "peerSelectionState" .= String (pack $ show ev)
90+
]
91+
forHuman = pack . show
92+
93+
instance MetaTrace (DebugPeerSelection extraState extraFlags extraPeers SockAddr) where
94+
namespaceFor TraceGovernorState {} = Namespace [] ["GovernorState"]
95+
96+
severityFor (Namespace _ ["GovernorState"]) _ = Just Debug
97+
severityFor _ _ = Nothing
98+
99+
documentFor (Namespace _ ["GovernorState"]) = Just ""
100+
documentFor _ = Nothing
101+
102+
allNamespaces = [
103+
Namespace [] ["GovernorState"]
104+
]
105+

0 commit comments

Comments
 (0)