github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/metrics/consensus.go (about)

     1  package metrics
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/prometheus/client_golang/prometheus"
     7  
     8  	"github.com/onflow/flow-go/model/flow"
     9  	"github.com/onflow/flow-go/module"
    10  )
    11  
    12  // ConsensusCollector ...
    13  type ConsensusCollector struct {
    14  	tracer module.Tracer
    15  
    16  	// Total time spent in onReceipt excluding checkSealing
    17  	onReceiptDuration prometheus.Counter
    18  
    19  	// Total time spent in onApproval excluding checkSealing
    20  	onApprovalDuration prometheus.Counter
    21  
    22  	// Total time spent in checkSealing
    23  	checkSealingDuration prometheus.Counter
    24  
    25  	// The number of emergency seals
    26  	emergencySealedBlocks prometheus.Counter
    27  }
    28  
    29  // NewConsensusCollector created a new consensus collector
    30  func NewConsensusCollector(tracer module.Tracer, registerer prometheus.Registerer) *ConsensusCollector {
    31  	onReceiptDuration := prometheus.NewCounter(prometheus.CounterOpts{
    32  		Name:      "push_receipts_on_receipt_duration_seconds_total",
    33  		Namespace: namespaceConsensus,
    34  		Subsystem: subsystemMatchEngine,
    35  		Help:      "time spent in consensus matching engine's onReceipt method in seconds",
    36  	})
    37  	onApprovalDuration := prometheus.NewCounter(prometheus.CounterOpts{
    38  		Name:      "on_approval_duration_seconds_total",
    39  		Namespace: namespaceConsensus,
    40  		Subsystem: subsystemMatchEngine,
    41  		Help:      "time spent in consensus matching engine's onApproval method in seconds",
    42  	})
    43  	checkSealingDuration := prometheus.NewCounter(prometheus.CounterOpts{
    44  		Name:      "check_sealing_duration_seconds_total",
    45  		Namespace: namespaceConsensus,
    46  		Subsystem: subsystemMatchEngine,
    47  		Help:      "time spent in consensus matching engine's checkSealing method in seconds",
    48  	})
    49  	emergencySealedBlocks := prometheus.NewCounter(prometheus.CounterOpts{
    50  		Name:      "emergency_sealed_blocks_total",
    51  		Namespace: namespaceConsensus,
    52  		Subsystem: subsystemCompliance,
    53  		Help:      "the number of blocks sealed in emergency mode",
    54  	})
    55  	registerer.MustRegister(
    56  		onReceiptDuration,
    57  		onApprovalDuration,
    58  		checkSealingDuration,
    59  		emergencySealedBlocks,
    60  	)
    61  	cc := &ConsensusCollector{
    62  		tracer:                tracer,
    63  		onReceiptDuration:     onReceiptDuration,
    64  		onApprovalDuration:    onApprovalDuration,
    65  		checkSealingDuration:  checkSealingDuration,
    66  		emergencySealedBlocks: emergencySealedBlocks,
    67  	}
    68  	return cc
    69  }
    70  
    71  // StartCollectionToFinalized reports Metrics C1: Collection Received by CCL→ Collection Included in Finalized Block
    72  func (cc *ConsensusCollector) StartCollectionToFinalized(collectionID flow.Identifier) {
    73  }
    74  
    75  // FinishCollectionToFinalized reports Metrics C1: Collection Received by CCL→ Collection Included in Finalized Block
    76  func (cc *ConsensusCollector) FinishCollectionToFinalized(collectionID flow.Identifier) {
    77  }
    78  
    79  // StartBlockToSeal reports Metrics C4: Block Received by CCL → Block Seal in finalized block
    80  func (cc *ConsensusCollector) StartBlockToSeal(blockID flow.Identifier) {
    81  }
    82  
    83  // FinishBlockToSeal reports Metrics C4: Block Received by CCL → Block Seal in finalized block
    84  func (cc *ConsensusCollector) FinishBlockToSeal(blockID flow.Identifier) {
    85  }
    86  
    87  // EmergencySeal increments the counter of emergency seals.
    88  func (cc *ConsensusCollector) EmergencySeal() {
    89  	cc.emergencySealedBlocks.Inc()
    90  }
    91  
    92  // OnReceiptProcessingDuration increases the number of seconds spent processing receipts
    93  func (cc *ConsensusCollector) OnReceiptProcessingDuration(duration time.Duration) {
    94  	cc.onReceiptDuration.Add(duration.Seconds())
    95  }
    96  
    97  // OnApprovalProcessingDuration increases the number of seconds spent processing approvals
    98  func (cc *ConsensusCollector) OnApprovalProcessingDuration(duration time.Duration) {
    99  	cc.onApprovalDuration.Add(duration.Seconds())
   100  }
   101  
   102  // CheckSealingDuration increases the number of seconds spent in checkSealing
   103  func (cc *ConsensusCollector) CheckSealingDuration(duration time.Duration) {
   104  	cc.checkSealingDuration.Add(duration.Seconds())
   105  }