Skip to content

Commit

Permalink
WIP: count works
Browse files Browse the repository at this point in the history
  • Loading branch information
karknu committed Oct 19, 2021
1 parent a76cf82 commit 96d3e03
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions cardano-node/src/Cardano/Tracing/Tracers.hs
Expand Up @@ -489,23 +489,23 @@ traceChainMetrics
-> Trace IO Text
-> Tracer IO (ChainDB.TraceEvent blk)
traceChainMetrics Nothing _ _ _ = nullTracer
traceChainMetrics (Just _ekgDirect) _blockConfig _fStats tr = do
traceChainMetrics (Just ekgDirect) _blockConfig _fStats tr = do
Tracer $ \ev ->
fromMaybe (pure ()) $ doTrace <$> chainTipInformation ev
where
chainTipInformation :: ChainDB.TraceEvent blk -> Maybe ChainInformation
chainTipInformation = \case
ChainDB.TraceAddBlockEvent ev -> case ev of
ChainDB.SwitchedToAFork _warnings newTipInfo _oldChain newChain ->
Just $ chainInformation newTipInfo newChain 0
ChainDB.SwitchedToAFork _warnings newTipInfo oldChain newChain ->
Just $ chainInformation newTipInfo (Just oldChain) newChain 0
ChainDB.AddedToCurrentChain _warnings newTipInfo _oldChain newChain ->
Just $ chainInformation newTipInfo newChain 0
Just $ chainInformation newTipInfo Nothing newChain 0
_ -> Nothing
_ -> Nothing
doTrace :: ChainInformation -> IO ()

doTrace
ChainInformation { slots, blocks, density, epoch, slotInEpoch } = do
ChainInformation { slots, blocks, density, epoch, slotInEpoch, fork } = do
-- TODO this is executed each time the newFhain changes. How cheap is it?
meta <- mkLOMeta Critical Public

Expand All @@ -514,6 +514,8 @@ traceChainMetrics (Just _ekgDirect) _blockConfig _fStats tr = do
traceI tr meta "blockNum" blocks
traceI tr meta "slotInEpoch" slotInEpoch
traceI tr meta "epoch" (unEpochNo epoch)
when (fork) $
sendEKGDirectCounter ekgDirect "cardano.node.metrics.forks.count"

traceD :: Trace IO a -> LOMeta -> Text -> Double -> IO ()
traceD tr meta msg d = traceNamedObject tr (meta, LogValue msg (PureD d))
Expand Down Expand Up @@ -1381,21 +1383,30 @@ data ChainInformation = ChainInformation
, blocksUncoupledDelta :: Int64
-- ^ The net change in number of blocks forged since last restart not on the
-- current chain.
, fork :: Bool
-- ^ Was this a fork.
}

chainInformation
:: forall blk. HasHeader (Header blk)
=> ChainDB.NewTipInfo blk
-> Maybe (AF.AnchoredFragment (Header blk))
-> AF.AnchoredFragment (Header blk)
-> Int64
-> ChainInformation
chainInformation newTipInfo frag blocksUncoupledDelta = ChainInformation
{ slots = unSlotNo $ fromWithOrigin 0 (AF.headSlot frag)
, blocks = unBlockNo $ fromWithOrigin (BlockNo 1) (AF.headBlockNo frag)
, density = fragmentChainDensity frag
chainInformation newTipInfo oldFrag_m newFrag blocksUncoupledDelta = ChainInformation
{ slots = unSlotNo $ fromWithOrigin 0 (AF.headSlot newFrag)
, blocks = unBlockNo $ fromWithOrigin (BlockNo 1) (AF.headBlockNo newFrag)
, density = fragmentChainDensity newFrag
, epoch = ChainDB.newTipEpoch newTipInfo
, slotInEpoch = ChainDB.newTipSlotInEpoch newTipInfo
, blocksUncoupledDelta = blocksUncoupledDelta
, fork = case oldFrag_m of
Nothing -> False
Just oldFrag ->
if AF.null oldFrag || AF.null newFrag
then False
else isJust $ (AF.intersectionPoint newFrag) <$> oldFrag_m
}

fragmentChainDensity ::
Expand Down

0 comments on commit 96d3e03

Please sign in to comment.