Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import Data.Time (NominalDiffTime)
import Data.Word (Word32, Word64)
import Network.TypedProtocol.Core

import LeiosDemoDb.Trace (TraceLeiosDb (..))
import LeiosDemoTypes (TraceLeiosKernel (..), TraceLeiosPeer (..),
traceLeiosKernelToObject, traceLeiosPeerToObject)
import LeiosUtils.CallTrace (SomeJsonCallTrace (..), callTraceToObject)
Expand Down Expand Up @@ -2361,7 +2362,43 @@ instance LogFormatting TraceLeiosKernel where
TraceLeiosAnnouncementAccepted src equiv fields mbAge ->
"EB announcement accepted from " <> Text.pack (show src)
<> " (" <> Text.pack (show equiv) <> "): " <> Text.pack (show fields) <> " age=" <> showT mbAge
asMetrics _ = []

-- The LeiosDb size gauges and activity counters, which together make the
-- volatile/immutable partitioning of the Leios DB observable: the immutable
-- gauges climb with what the immutable chain references, while GC keeps the
-- volatile ones bounded by evicting un-certified leftovers. Both size events
-- ride the same stats-sampler timer.
--
-- NOTE: metric names live in a single flat global namespace (the 'Namespace'
-- above names the log message, not the metric), so they are prefixed to stay
-- unique. 'IntM' gets an "_int" suffix and 'CounterM' a "_counter" one, on top
-- of 'TraceOptionMetricsPrefix'.
asMetrics = \case
-- Sampled on a timer, so these exist from node start.
TraceLeiosDb TraceLeiosDbVolatileStats { volatileEbs, volatileEbTxs, volatileTxs
, dbFileBytes, walBytes } ->
[ IntM "leiosDbVolatileEbs" (fromIntegral volatileEbs)
, IntM "leiosDbVolatileEbTxs" (fromIntegral volatileEbTxs)
, IntM "leiosDbVolatileTxs" (fromIntegral volatileTxs)
, IntM "leiosDbFileBytes" dbFileBytes
, IntM "leiosDbWalBytes" walBytes
]
TraceLeiosDb TraceLeiosDbImmutableStats { immutableEbs, immutableEbTxs, immutableTxs } ->
[ IntM "leiosDbImmutableEbs" (fromIntegral immutableEbs)
, IntM "leiosDbImmutableEbTxs" (fromIntegral immutableEbTxs)
, IntM "leiosDbImmutableTxs" (fromIntegral immutableTxs)
]
TraceLeiosDb TraceLeiosDbCopiedToImmutable { copiedEbs, copiedEbTxs, copiedTxs } ->
[ CounterM "leiosDbCopiedEbs" (Just copiedEbs)
, CounterM "leiosDbCopiedEbTxs" (Just copiedEbTxs)
, CounterM "leiosDbCopiedTxs" (Just copiedTxs)
]
TraceLeiosDb TraceLeiosDbEvicted { evictedEbs, evictedEbTxs, evictedTxs } ->
[ CounterM "leiosDbEvictedEbs" (Just evictedEbs)
, CounterM "leiosDbEvictedEbTxs" (Just evictedEbTxs)
, CounterM "leiosDbEvictedTxs" (Just evictedTxs)
]
_ -> []

instance MetaTrace TraceLeiosKernel where
namespaceFor MkTraceLeiosKernel{} = Namespace [] ["Msg"]
Expand All @@ -2377,16 +2414,44 @@ instance MetaTrace TraceLeiosKernel where
namespaceFor TraceLeiosCertified{} = Namespace [] ["Certified"]
namespaceFor TraceLeiosNotVoted{} = Namespace [] ["NotVoted"]
namespaceFor TraceLeiosDbException{} = Namespace [] ["DbException"]
-- Call spans get their own namespace under Db so their severity and
-- frequency can be configured apart from the stats gauges (a dozen span
-- events per GC vs one stats event).
namespaceFor (TraceLeiosDb TraceLeiosDbCall{}) = Namespace [] ["Db", "Call"]
namespaceFor TraceLeiosDb{} = Namespace [] ["Db"]
namespaceFor TraceLeiosCertifiedAndAnnounced{} = Namespace [] ["CertifiedAndAnnounced"]
namespaceFor TraceLeiosAnnouncementAccepted{} = Namespace [] ["AnnouncementAccepted"]

severityFor (Namespace _ ["DbException"]) _ = Just Error
severityFor (Namespace _ ["BlockPointMissing"]) _ = Just Warning
severityFor (Namespace _ ["Db", "Call"]) _ = Just Debug
severityFor _ _ = Just Info

documentFor _ = Nothing

-- REQUIRED for the metrics in 'asMetrics' to be emitted at all, despite the
-- name: 'hasNoMetrics' is @all (null . metricsDocFor) allNamespaces@, and
-- 'mkCardanoTracer' uses it to silence a tracer's entire metrics branch at
-- configuration time. Leaving this at its @[]@ default drops every metric
-- above, with no error.
metricsDocFor (Namespace _ ["Db"]) =
[ ("leiosDbVolatileEbs", "LeiosDb: announced EB rows in the volatile partition")
, ("leiosDbVolatileEbTxs", "LeiosDb: EB body rows in the volatile partition")
, ("leiosDbVolatileTxs", "LeiosDb: transactions in the volatile partition")
, ("leiosDbImmutableEbs", "LeiosDb: announced EB rows in the immutable partition")
, ("leiosDbImmutableEbTxs", "LeiosDb: EB body rows in the immutable partition")
, ("leiosDbImmutableTxs", "LeiosDb: transactions in the immutable partition")
, ("leiosDbFileBytes", "LeiosDb: size of the main database file in bytes")
, ("leiosDbWalBytes", "LeiosDb: current size of the write-ahead log in bytes")
, ("leiosDbCopiedEbs", "LeiosDb: announcement rows copied into the immutable partition")
, ("leiosDbCopiedEbTxs", "LeiosDb: EB body rows copied into the immutable partition")
, ("leiosDbCopiedTxs", "LeiosDb: transactions copied into the immutable partition")
, ("leiosDbEvictedEbs", "LeiosDb: announcement rows garbage collected from the volatile partition")
, ("leiosDbEvictedEbTxs", "LeiosDb: EB body rows garbage collected from the volatile partition")
, ("leiosDbEvictedTxs", "LeiosDb: transactions garbage collected from the volatile partition")
]
metricsDocFor _ = []

allNamespaces =
[ Namespace [] ["Msg"]
, Namespace [] ["BlockAcquired"]
Expand All @@ -2402,6 +2467,7 @@ instance MetaTrace TraceLeiosKernel where
, Namespace [] ["NotVoted"]
, Namespace [] ["DbException"]
, Namespace [] ["Db"]
, Namespace [] ["Db", "Call"]
, Namespace [] ["CertifiedAndAnnounced"]
, Namespace [] ["AnnouncementAccepted"]
]
Expand Down
Loading