Skip to content

Commit 437f2db

Browse files
jutaromgmeier
authored andcommitted
cardano-node: tipBlockHash metrics and tracing properties
1 parent 4a2ff74 commit 437f2db

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

cardano-node/src/Cardano/Node/TraceConstraints.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ type TraceConstraints blk =
4444
, HasKESInfo blk
4545
, GetKESInfo blk
4646
, RunNode blk
47-
, HasIssuer blk
4847

4948
, ToObject (ApplyTxErr blk)
5049
, ToObject (GenTx blk)

cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ instance ( LogFormatting (Header blk)
484484
forMachine dtal (ChainDB.ChangingSelection pt) =
485485
mconcat [ "kind" .= String "TraceAddBlockEvent.ChangingSelection"
486486
, "block" .= forMachine dtal pt ]
487-
forMachine dtal (ChainDB.AddedToCurrentChain events selChangedInfo base extended) =
487+
488+
forMachine DDetailed (ChainDB.AddedToCurrentChain events selChangedInfo base extended) =
488489
let ChainInformation { .. } = chainInformation selChangedInfo base extended 0
489490
tipBlockIssuerVkHashText :: Text
490491
tipBlockIssuerVkHashText =
@@ -493,21 +494,33 @@ instance ( LogFormatting (Header blk)
493494
BlockIssuerVerificationKeyHash bs ->
494495
Text.decodeLatin1 (B16.encode bs)
495496
in mconcat $
497+
[ "kind" .= String "AddedToCurrentChain"
498+
, "newtip" .= renderPointForDetails DDetailed (AF.headPoint extended)
499+
, "newTipSelectView" .= forMachine DDetailed (ChainDB.newTipSelectView selChangedInfo)
500+
]
501+
++ [ "oldTipSelectView" .= forMachine DDetailed oldTipSelectView
502+
| Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo]
503+
]
504+
++ [ "headers" .= toJSON (forMachine DDetailed `map` addedHdrsNewChain base extended)
505+
]
506+
++ [ "events" .= toJSON (map (forMachine DDetailed) events)
507+
| not (null events) ]
508+
++ [ "tipBlockHash" .= tipBlockHash
509+
, "tipBlockParentHash" .= tipBlockParentHash
510+
, "tipBlockIssuerVerificationKeyHash" .= tipBlockIssuerVkHashText]
511+
forMachine dtal (ChainDB.AddedToCurrentChain events selChangedInfo _base extended) =
512+
mconcat $
496513
[ "kind" .= String "AddedToCurrentChain"
497514
, "newtip" .= renderPointForDetails dtal (AF.headPoint extended)
498515
, "newTipSelectView" .= forMachine dtal (ChainDB.newTipSelectView selChangedInfo)
499516
]
500517
++ [ "oldTipSelectView" .= forMachine dtal oldTipSelectView
501518
| Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo]
502519
]
503-
++ [ "headers" .= toJSON (forMachine dtal `map` addedHdrsNewChain base extended)
504-
| dtal == DDetailed ]
505520
++ [ "events" .= toJSON (map (forMachine dtal) events)
506521
| not (null events) ]
507-
++ [ "tipBlockHash" .= tipBlockHash
508-
, "tipBlockParentHash" .= tipBlockParentHash
509-
, "tipBlockIssuerVerificationKeyHash" .= tipBlockIssuerVkHashText]
510-
forMachine dtal (ChainDB.SwitchedToAFork events selChangedInfo old new) =
522+
523+
forMachine DDetailed (ChainDB.SwitchedToAFork events selChangedInfo old new) =
511524
let ChainInformation { .. } = chainInformation selChangedInfo old new 0
512525
tipBlockIssuerVkHashText :: Text
513526
tipBlockIssuerVkHashText =
@@ -516,20 +529,31 @@ instance ( LogFormatting (Header blk)
516529
BlockIssuerVerificationKeyHash bs ->
517530
Text.decodeLatin1 (B16.encode bs)
518531
in mconcat $
532+
[ "kind" .= String "TraceAddBlockEvent.SwitchedToAFork"
533+
, "newtip" .= renderPointForDetails DDetailed (AF.headPoint new)
534+
, "newTipSelectView" .= forMachine DDetailed (ChainDB.newTipSelectView selChangedInfo)
535+
]
536+
++ [ "oldTipSelectView" .= forMachine DDetailed oldTipSelectView
537+
| Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo]
538+
]
539+
++ [ "headers" .= toJSON (forMachine DDetailed `map` addedHdrsNewChain old new)
540+
]
541+
++ [ "events" .= toJSON (map (forMachine DDetailed) events)
542+
| not (null events) ]
543+
++ [ "tipBlockHash" .= tipBlockHash
544+
, "tipBlockParentHash" .= tipBlockParentHash
545+
, "tipBlockIssuerVerificationKeyHash" .= tipBlockIssuerVkHashText]
546+
forMachine dtal (ChainDB.SwitchedToAFork events selChangedInfo _old new) =
547+
mconcat $
519548
[ "kind" .= String "TraceAddBlockEvent.SwitchedToAFork"
520549
, "newtip" .= renderPointForDetails dtal (AF.headPoint new)
521550
, "newTipSelectView" .= forMachine dtal (ChainDB.newTipSelectView selChangedInfo)
522551
]
523552
++ [ "oldTipSelectView" .= forMachine dtal oldTipSelectView
524553
| Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo]
525554
]
526-
++ [ "headers" .= toJSON (forMachine dtal `map` addedHdrsNewChain old new)
527-
| dtal == DDetailed ]
528555
++ [ "events" .= toJSON (map (forMachine dtal) events)
529556
| not (null events) ]
530-
++ [ "tipBlockHash" .= tipBlockHash
531-
, "tipBlockParentHash" .= tipBlockParentHash
532-
, "tipBlockIssuerVerificationKeyHash" .= tipBlockIssuerVkHashText]
533557

534558
forMachine dtal (ChainDB.AddBlockValidation ev') =
535559
forMachine dtal ev'
@@ -570,21 +594,37 @@ instance ( LogFormatting (Header blk)
570594
let forkIt = not $ AF.withinFragmentBounds (AF.headPoint oldChain)
571595
newChain
572596
ChainInformation { .. } = chainInformation selChangedInfo oldChain newChain 0
597+
tipBlockIssuerVkHashText =
598+
case tipBlockIssuerVerificationKeyHash of
599+
NoBlockIssuer -> "NoBlockIssuer"
600+
BlockIssuerVerificationKeyHash bs ->
601+
Text.decodeLatin1 (B16.encode bs)
573602
in [ DoubleM "density" (fromRational density)
574603
, IntM "slotNum" (fromIntegral slots)
575604
, IntM "blockNum" (fromIntegral blocks)
576605
, IntM "slotInEpoch" (fromIntegral slotInEpoch)
577606
, IntM "epoch" (fromIntegral (unEpochNo epoch))
578607
, CounterM "forks" (Just (if forkIt then 1 else 0))
608+
, PrometheusM "tipBlock" [("hash",tipBlockHash)
609+
,("parent hash",tipBlockParentHash)
610+
,("issuer verification key hash", tipBlockIssuerVkHashText)]
579611
]
580612
asMetrics (ChainDB.AddedToCurrentChain _warnings selChangedInfo oldChain newChain) =
581613
let ChainInformation { .. } =
582614
chainInformation selChangedInfo oldChain newChain 0
615+
tipBlockIssuerVkHashText =
616+
case tipBlockIssuerVerificationKeyHash of
617+
NoBlockIssuer -> "NoBlockIssuer"
618+
BlockIssuerVerificationKeyHash bs ->
619+
Text.decodeLatin1 (B16.encode bs)
583620
in [ DoubleM "density" (fromRational density)
584621
, IntM "slotNum" (fromIntegral slots)
585622
, IntM "blockNum" (fromIntegral blocks)
586623
, IntM "slotInEpoch" (fromIntegral slotInEpoch)
587624
, IntM "epoch" (fromIntegral (unEpochNo epoch))
625+
, PrometheusM "tipBlock" [("hash",tipBlockHash)
626+
,("parent hash",tipBlockParentHash)
627+
,("issuer verification key hash", tipBlockIssuerVkHashText)]
588628
]
589629
asMetrics _ = []
590630

0 commit comments

Comments
 (0)