|
| 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