88
99module Cardano.Node.Tracing.Consistency
1010 ( getAllNamespaces
11- , asNSLookup
12- , checkConfiguration
13- , checkConfiguration'
11+ , checkNodeTraceConfiguration
12+ , checkNodeTraceConfiguration'
1413 ) where
1514
1615import Control.Exception (SomeException )
17- import Data.Foldable (foldl' )
18- import qualified Data.Map.Strict as Map
19- import Data.Maybe (mapMaybe )
2016import qualified Data.Text as T
2117import Network.Mux (MuxTrace (.. ), WithMuxBearer (.. ))
2218import qualified Network.Socket as Socket
@@ -30,8 +26,7 @@ import qualified Cardano.Node.Tracing.StateRep as SR
3026import Cardano.Node.Tracing.Tracers.BlockReplayProgress
3127import Cardano.Node.Tracing.Tracers.Consensus
3228import Cardano.Node.Tracing.Tracers.Diffusion ()
33- -- import Cardano.Node.Tracing.Tracers.ForgingThreadStats (ForgeThreadStats,
34- -- forgeThreadStats, ForgingStats)
29+
3530import Cardano.Node.Handlers.Shutdown (ShutdownTrace )
3631import Cardano.Node.Startup
3732import Cardano.Node.Tracing.Tracers.KESInfo ()
@@ -96,82 +91,30 @@ import Ouroboros.Network.Subscription.Worker (SubscriptionTrace (..))
9691import Ouroboros.Network.TxSubmission.Inbound (TraceTxSubmissionInbound )
9792import Ouroboros.Network.TxSubmission.Outbound (TraceTxSubmissionOutbound )
9893
99- -- | A data structure for the lookup of namespaces as nested maps
100- newtype NSLookup = NSLookup (Map. Map T. Text NSLookup )
101- deriving Show
10294
103- -- | Warniings as a list of text
104- type NSWarnings = [T. Text ]
10595
10696-- | Check the configuration in the given file.
10797-- If there is no configuration in the file check the standard configuration
10898-- An empty return list means, everything is well
109- checkConfiguration ::
99+ checkNodeTraceConfiguration ::
110100 FilePath
111101 -> IO NSWarnings
112- checkConfiguration configFileName = do
113- trConfig <- readConfigurationWithDefault configFileName defaultCardanoConfig
114- pure (checkConfiguration' trConfig)
102+ checkNodeTraceConfiguration configFileName =
103+ checkTraceConfiguration
104+ configFileName
105+ defaultCardanoConfig
106+ getAllNamespaces
115107
116- checkConfiguration' ::
108+ -- | Check the configuration in the given file.
109+ -- If there is no configuration in the file check the standard configuration
110+ -- An empty return list means, everything is well
111+ checkNodeTraceConfiguration' ::
117112 TraceConfig
118113 -> NSWarnings
119- checkConfiguration' trConfig =
120- let namespaces = Map. keys (tcOptions trConfig)
121- (nsLookup, systemWarnings) = asNSLookup getAllNamespaces
122- configWarnings = mapMaybe (checkNamespace nsLookup) namespaces
123- allWarnings = map (" System namespace error: " <> ) systemWarnings ++
124- map (" Config namespace error: " <> ) configWarnings
125- in allWarnings
126-
127- -- | Check if a single namespace is legal. Returns just a warning test,
128- -- if this is not the case
129- checkNamespace :: NSLookup -> [T. Text ] -> Maybe T. Text
130- checkNamespace nsLookup ns = go nsLookup ns
131- where
132- go :: NSLookup -> [T. Text ] -> Maybe T. Text
133- go _ [] = Nothing
134- go (NSLookup l) (nshd : nstl) = case Map. lookup nshd l of
135- Nothing -> Just (" Illegal namespace "
136- <> T. intercalate " ." ns)
137- Just l2 -> go l2 nstl
138-
139- -- | Builds a namespace lookup structure from a list of namespaces
140- -- Warns if namespaces are not unique, and if a namespace is a subnamespace
141- -- of other namespaces
142- asNSLookup :: [[T. Text ]] -> (NSLookup , NSWarnings )
143- asNSLookup = foldl' (fillLookup [] ) (NSLookup Map. empty, [] )
144- where
145- fillLookup :: [T. Text ] -> (NSLookup , NSWarnings ) -> [T. Text ] -> (NSLookup , NSWarnings )
146- fillLookup _nsFull (NSLookup nsl, nsw) [] = (NSLookup nsl, nsw)
147- fillLookup nsFull (NSLookup nsl, nsw) (ns1 : nstail) =
148- case Map. lookup ns1 nsl of
149- Nothing -> let nsNew = Map. empty
150- (NSLookup nsl2, nsw2) = fillLookup
151- (nsFull <> [ns1])
152- (NSLookup nsNew, [] )
153- nstail
154- res = NSLookup (Map. insert ns1 (NSLookup nsl2) nsl)
155- newWarnings = nsw <> nsw2
156- in (res, newWarnings)
157- Just (NSLookup nsm)
158- -> let (NSLookup nsl2, nsw2) = fillLookup
159- (nsFull <> [ns1])
160- (NSLookup nsm, [] )
161- nstail
162- res = NSLookup (Map. insert ns1 (NSLookup nsl2) nsl)
163- condWarning = if null nstail
164- then
165- if Map. null nsm
166- then Just (" Duplicate namespace "
167- <> T. intercalate " ." (nsFull <> [ns1]))
168- else Just (" Inner namespace duplicate "
169- <> T. intercalate " ." (nsFull <> [ns1]))
170- else Nothing
171- newWarnings = case condWarning of
172- Nothing -> nsw <> nsw2
173- Just w -> w : (nsw <> nsw2)
174- in (res, newWarnings)
114+ checkNodeTraceConfiguration' trConfig =
115+ checkTraceConfiguration'
116+ trConfig
117+ getAllNamespaces
175118
176119
177120-- | Returns a list of all namepsaces from all tracers
@@ -212,8 +155,6 @@ getAllNamespaces =
212155 remotePeer
213156 (BlockFetch. TraceFetchClientState (Header blk)))])
214157
215- -- TODO Yup
216- -- blockFetchClientMetricsTr <- do
217158 blockFetchServerNS = map (nsGetComplete . nsReplacePrefix [" BlockFetch" , " Server" ])
218159 (allNamespaces :: [Namespace (TraceBlockFetchServerEvent blk )])
219160
0 commit comments