github.com/koko1123/flow-go-1@v0.29.6/module/metrics/verification.go (about)

     1  package metrics
     2  
     3  import (
     4  	"github.com/prometheus/client_golang/prometheus"
     5  
     6  	"github.com/koko1123/flow-go-1/module"
     7  )
     8  
     9  type VerificationCollector struct {
    10  	tracer module.Tracer
    11  
    12  	// Job Consumers
    13  	lastProcessedBlockJobIndexBlockConsumer prometheus.Gauge
    14  	lastProcessedChunkJobIndexChunkConsumer prometheus.Gauge
    15  
    16  	// Assigner Engine
    17  	receivedFinalizedHeightAssigner prometheus.Gauge   // the last finalized height received by assigner engine
    18  	assignedChunkTotalAssigner      prometheus.Counter // total chunks assigned to this verification node
    19  	processedChunkTotalAssigner     prometheus.Counter // total chunks sent by assigner engine to chunk consumer (i.e., fetcher input)
    20  	receivedResultsTotalAssigner    prometheus.Counter // total execution results arrived at assigner
    21  
    22  	// Fetcher Engine
    23  	receivedAssignedChunkTotalFetcher  prometheus.Counter // total assigned chunks received by fetcher engine from assigner engine.
    24  	sentVerifiableChunksTotalFetcher   prometheus.Counter // total verifiable chunk sent by fetcher engine and sent to verifier engine.
    25  	receivedChunkDataPackTotalFetcher  prometheus.Counter // total chunk data packs received by fetcher engine
    26  	requestedChunkDataPackTotalFetcher prometheus.Counter // total number of chunk data packs requested by fetcher engine
    27  
    28  	// Requester Engine
    29  	//
    30  	// total number of chunk data pack requests received by requester engine from fetcher engine.
    31  	receivedChunkDataPackRequestsTotalRequester prometheus.Counter
    32  	// total number of chunk data request messages dispatched in the network by requester engine.
    33  	sentChunkDataRequestMessagesTotalRequester prometheus.Counter
    34  	// total number of chunk data response messages received by requester from network.
    35  	receivedChunkDataResponseMessageTotalRequester prometheus.Counter
    36  	// total number of chunk data pack sent by requester to fetcher engine.
    37  	sentChunkDataPackByRequesterTotal prometheus.Counter
    38  	// maximum number of attempts made for requesting a chunk data pack belonging to the next unsealed height.
    39  	maxChunkDataPackRequestAttemptForNextUnsealedHeight prometheus.Gauge
    40  
    41  	// Verifier Engine
    42  	receivedVerifiableChunkTotalVerifier prometheus.Counter // total verifiable chunks received by verifier engine
    43  	sentResultApprovalTotalVerifier      prometheus.Counter // total result approvals sent by verifier engine
    44  
    45  }
    46  
    47  func NewVerificationCollector(tracer module.Tracer, registerer prometheus.Registerer) *VerificationCollector {
    48  	// Job Consumers
    49  	lastProcessedBlockJobIndexBlockConsumer := prometheus.NewGauge(prometheus.GaugeOpts{
    50  		Name:      "last_processed_block_job_index",
    51  		Namespace: namespaceVerification,
    52  		Subsystem: subsystemBlockConsumer,
    53  		Help:      "the last block job index processed by block consumer",
    54  	})
    55  
    56  	lastProcessedChunkJobIndexChunkConsumer := prometheus.NewGauge(prometheus.GaugeOpts{
    57  		Name:      "last_processed_chunk_job_index",
    58  		Namespace: namespaceVerification,
    59  		Subsystem: subsystemChunkConsumer,
    60  		Help:      "the last chunk job index processed by chunk consumer",
    61  	})
    62  
    63  	// Assigner Engine
    64  	receivedFinalizedHeightAssigner := prometheus.NewGauge(prometheus.GaugeOpts{
    65  		Name:      "finalized_height",
    66  		Namespace: namespaceVerification,
    67  		Subsystem: subsystemAssignerEngine,
    68  		Help:      "the last finalized height received by assigner engine",
    69  	})
    70  
    71  	receivedResultsTotalAssigner := prometheus.NewGauge(prometheus.GaugeOpts{
    72  		Name:      "received_result_total",
    73  		Namespace: namespaceVerification,
    74  		Subsystem: subsystemAssignerEngine,
    75  		Help:      "total number of execution results received by assigner engine",
    76  	})
    77  
    78  	assignedChunksTotalAssigner := prometheus.NewCounter(prometheus.CounterOpts{
    79  		Name:      "chunk_assigned_total",
    80  		Namespace: namespaceVerification,
    81  		Subsystem: subsystemAssignerEngine,
    82  		Help:      "total number of chunks assigned to verification node",
    83  	})
    84  
    85  	sentChunksTotalAssigner := prometheus.NewCounter(prometheus.CounterOpts{
    86  		Name:      "processed_chunk_sent_total",
    87  		Namespace: namespaceVerification,
    88  		Subsystem: subsystemAssignerEngine,
    89  		Help:      "total number chunks sent by assigner engine to chunk consumer",
    90  	})
    91  
    92  	// Fetcher Engine
    93  	receivedAssignedChunksTotalFetcher := prometheus.NewCounter(prometheus.CounterOpts{
    94  		Name:      "assigned_chunk_received_total",
    95  		Namespace: namespaceVerification,
    96  		Subsystem: subsystemFetcherEngine,
    97  		Help:      "total number of chunks received by fetcher engine from assigner engine through chunk consumer",
    98  	})
    99  
   100  	// Requester Engine
   101  	receivedChunkDataPackRequestsTotalRequester := prometheus.NewCounter(prometheus.CounterOpts{
   102  		Name:      "chunk_data_pack_request_received_total",
   103  		Namespace: namespaceVerification,
   104  		Subsystem: subsystemRequesterEngine,
   105  		Help:      "total number of chunk data pack requests received by requester engine from fetcher engine",
   106  	})
   107  
   108  	sentChunkDataRequestMessagesTotalRequester := prometheus.NewCounter(prometheus.CounterOpts{
   109  		Name:      "chunk_data_pack_request_message_sent_total",
   110  		Namespace: namespaceVerification,
   111  		Subsystem: subsystemRequesterEngine,
   112  		Help:      "total number of chunk data pack request messages sent in the network by requester engine",
   113  	})
   114  
   115  	receivedChunkDataResponseMessagesTotalRequester := prometheus.NewCounter(prometheus.CounterOpts{
   116  		Name:      "chunk_data_response_message_received_total",
   117  		Namespace: namespaceVerification,
   118  		Subsystem: subsystemRequesterEngine,
   119  		Help:      "total number of chunk data response messages received from network by requester engine",
   120  	})
   121  
   122  	sentChunkDataPackByRequesterTotal := prometheus.NewCounter(prometheus.CounterOpts{
   123  		Name:      "chunk_data_pack_sent_total",
   124  		Namespace: namespaceVerification,
   125  		Subsystem: subsystemRequesterEngine,
   126  		Help:      "total number of chunk data packs sent by requester engine to fetcher engine",
   127  	})
   128  
   129  	sentVerifiableChunksTotalFetcher := prometheus.NewCounter(prometheus.CounterOpts{
   130  		Name:      "verifiable_chunk_sent_total",
   131  		Namespace: namespaceVerification,
   132  		Subsystem: subsystemFetcherEngine,
   133  		Help:      "total number of verifiable chunks sent by fetcher engine to verifier engine",
   134  	})
   135  
   136  	receivedChunkDataPackTotalFetcher := prometheus.NewCounter(prometheus.CounterOpts{
   137  		Name:      "chunk_data_pack_received_total",
   138  		Namespace: namespaceVerification,
   139  		Subsystem: subsystemFetcherEngine,
   140  		Help:      "total number of chunk data packs received by fetcher engine",
   141  	})
   142  
   143  	requestedChunkDataPackTotalFetcher := prometheus.NewCounter(prometheus.CounterOpts{
   144  		Name:      "chunk_data_pack_requested_total",
   145  		Namespace: namespaceVerification,
   146  		Subsystem: subsystemFetcherEngine,
   147  		Help:      "total number of chunk data packs requested by fetcher engine",
   148  	})
   149  
   150  	maxChunkDataPackRequestAttemptForNextUnsealedHeight := prometheus.NewGauge(prometheus.GaugeOpts{
   151  		Name:      "next_unsealed_height_max_chunk_data_pack_request_attempt_times",
   152  		Namespace: namespaceVerification,
   153  		Subsystem: subsystemRequesterEngine,
   154  		// an indicator for when execution nodes is unresponsive to chunk data pack requests,
   155  		// in which case verification node will keep requesting the chunk data pack, and this
   156  		// metrics number will go up.
   157  		Help: "among all the pending chunk data packs requested by the requester engine for the next unsealed height the maximum number of times a" +
   158  			" certain chunk data pack was requested",
   159  	})
   160  
   161  	// Verifier Engine
   162  	receivedVerifiableChunksTotalVerifier := prometheus.NewCounter(prometheus.CounterOpts{
   163  		Name:      "verifiable_chunk_received_total",
   164  		Namespace: namespaceVerification,
   165  		Subsystem: subsystemVerifierEngine,
   166  		Help:      "total number verifiable chunks received by verifier engine from fetcher engine",
   167  	})
   168  
   169  	sentResultApprovalTotalVerifier := prometheus.NewCounter(prometheus.CounterOpts{
   170  		Name:      "result_approvals_total",
   171  		Namespace: namespaceVerification,
   172  		Subsystem: subsystemVerifierEngine,
   173  		Help:      "total number of emitted result approvals by verifier engine",
   174  	})
   175  
   176  	// registers all metrics and panics if any fails.
   177  	registerer.MustRegister(
   178  		// job consumers
   179  		lastProcessedBlockJobIndexBlockConsumer,
   180  		lastProcessedChunkJobIndexChunkConsumer,
   181  
   182  		// assigner
   183  		receivedFinalizedHeightAssigner,
   184  		assignedChunksTotalAssigner,
   185  		sentChunksTotalAssigner,
   186  		receivedResultsTotalAssigner,
   187  
   188  		// fetcher engine
   189  		receivedAssignedChunksTotalFetcher,
   190  		sentVerifiableChunksTotalFetcher,
   191  		receivedChunkDataPackTotalFetcher,
   192  		requestedChunkDataPackTotalFetcher,
   193  
   194  		// requester engine
   195  		receivedChunkDataPackRequestsTotalRequester,
   196  		sentChunkDataRequestMessagesTotalRequester,
   197  		receivedChunkDataResponseMessagesTotalRequester,
   198  		sentChunkDataPackByRequesterTotal,
   199  		maxChunkDataPackRequestAttemptForNextUnsealedHeight,
   200  
   201  		// verifier engine
   202  		receivedVerifiableChunksTotalVerifier,
   203  		sentResultApprovalTotalVerifier)
   204  
   205  	vc := &VerificationCollector{
   206  		tracer: tracer,
   207  
   208  		// job consumers
   209  		lastProcessedChunkJobIndexChunkConsumer: lastProcessedChunkJobIndexChunkConsumer,
   210  		lastProcessedBlockJobIndexBlockConsumer: lastProcessedBlockJobIndexBlockConsumer,
   211  
   212  		// assigner
   213  		receivedFinalizedHeightAssigner: receivedFinalizedHeightAssigner,
   214  		assignedChunkTotalAssigner:      assignedChunksTotalAssigner,
   215  		processedChunkTotalAssigner:     sentChunksTotalAssigner,
   216  		receivedResultsTotalAssigner:    receivedResultsTotalAssigner,
   217  
   218  		// fetcher
   219  		receivedAssignedChunkTotalFetcher:  receivedAssignedChunksTotalFetcher,
   220  		receivedChunkDataPackTotalFetcher:  receivedChunkDataPackTotalFetcher,
   221  		requestedChunkDataPackTotalFetcher: requestedChunkDataPackTotalFetcher,
   222  		sentVerifiableChunksTotalFetcher:   sentVerifiableChunksTotalFetcher,
   223  
   224  		// verifier
   225  		sentResultApprovalTotalVerifier:      sentResultApprovalTotalVerifier,
   226  		receivedVerifiableChunkTotalVerifier: receivedVerifiableChunksTotalVerifier,
   227  
   228  		// requester
   229  		receivedChunkDataPackRequestsTotalRequester:         receivedChunkDataPackRequestsTotalRequester,
   230  		sentChunkDataRequestMessagesTotalRequester:          sentChunkDataRequestMessagesTotalRequester,
   231  		receivedChunkDataResponseMessageTotalRequester:      receivedChunkDataResponseMessagesTotalRequester,
   232  		sentChunkDataPackByRequesterTotal:                   sentChunkDataPackByRequesterTotal,
   233  		maxChunkDataPackRequestAttemptForNextUnsealedHeight: maxChunkDataPackRequestAttemptForNextUnsealedHeight,
   234  	}
   235  
   236  	return vc
   237  }
   238  
   239  // OnExecutionResultReceivedAtAssignerEngine is called whenever a new execution result arrives
   240  // at Assigner engine. It increments total number of received results.
   241  func (vc *VerificationCollector) OnExecutionResultReceivedAtAssignerEngine() {
   242  	vc.receivedResultsTotalAssigner.Inc()
   243  }
   244  
   245  // OnVerifiableChunkReceivedAtVerifierEngine is called whenever a verifiable chunk is received by Verifier engine
   246  // from Assigner engine.It increments the total number of sent verifiable chunks.
   247  func (vc *VerificationCollector) OnVerifiableChunkReceivedAtVerifierEngine() {
   248  	vc.receivedVerifiableChunkTotalVerifier.Inc()
   249  }
   250  
   251  // OnResultApprovalDispatchedInNetwork is called whenever a result approval for is emitted to consensus nodes.
   252  // It increases the total number of result approvals.
   253  func (vc *VerificationCollector) OnResultApprovalDispatchedInNetworkByVerifier() {
   254  	// increases the counter of disseminated result approvals
   255  	// fo by one. Each result approval corresponds to a single chunk of the block
   256  	// the approvals disseminated by verifier engine
   257  	vc.sentResultApprovalTotalVerifier.Inc()
   258  }
   259  
   260  // OnFinalizedBlockArrivedAtAssigner sets a gauge that keeps track of number of the latest block height arrives
   261  // at assigner engine. Note that it assumes blocks are coming to assigner engine in strictly increasing order of their height.
   262  func (vc *VerificationCollector) OnFinalizedBlockArrivedAtAssigner(height uint64) {
   263  	vc.receivedFinalizedHeightAssigner.Set(float64(height))
   264  }
   265  
   266  // OnChunksAssignmentDoneAtAssigner increments a counter that keeps track of the total number of assigned chunks to
   267  // the verification node.
   268  func (vc *VerificationCollector) OnChunksAssignmentDoneAtAssigner(chunks int) {
   269  	vc.assignedChunkTotalAssigner.Add(float64(chunks))
   270  }
   271  
   272  // OnAssignedChunkProcessedAtAssigner increments a counter that keeps track of the total number of assigned chunks pushed by
   273  // assigner engine to the fetcher engine.
   274  func (vc *VerificationCollector) OnAssignedChunkProcessedAtAssigner() {
   275  	vc.processedChunkTotalAssigner.Inc()
   276  }
   277  
   278  // OnAssignedChunkReceivedAtFetcher increments a counter that keeps track of number of assigned chunks arrive at fetcher engine.
   279  func (vc *VerificationCollector) OnAssignedChunkReceivedAtFetcher() {
   280  	vc.receivedAssignedChunkTotalFetcher.Inc()
   281  }
   282  
   283  // OnChunkDataPackRequestSentByFetcher increments a counter that keeps track of number of chunk data pack requests that fetcher engine
   284  // sends to requester engine.
   285  func (vc *VerificationCollector) OnChunkDataPackRequestSentByFetcher() {
   286  	vc.requestedChunkDataPackTotalFetcher.Inc()
   287  }
   288  
   289  // OnChunkDataPackRequestReceivedByRequester increments a counter that keeps track of number of chunk data pack requests
   290  // arrive at the requester engine from the fetcher engine.
   291  func (vc *VerificationCollector) OnChunkDataPackRequestReceivedByRequester() {
   292  	vc.receivedChunkDataPackRequestsTotalRequester.Inc()
   293  }
   294  
   295  // OnChunkDataPackRequestDispatchedInNetworkByRequester increments a counter that keeps track of number of chunk data pack requests that the
   296  // requester engine dispatches in the network (to the execution nodes).
   297  func (vc *VerificationCollector) OnChunkDataPackRequestDispatchedInNetworkByRequester() {
   298  	vc.sentChunkDataRequestMessagesTotalRequester.Inc()
   299  }
   300  
   301  // OnChunkDataPackResponseReceivedFromNetworkByRequester increments a counter that keeps track of number of chunk data pack responses that the
   302  // requester engine receives from execution nodes (through network).
   303  func (vc *VerificationCollector) OnChunkDataPackResponseReceivedFromNetworkByRequester() {
   304  	vc.receivedChunkDataResponseMessageTotalRequester.Inc()
   305  }
   306  
   307  // OnChunkDataPackSentToFetcher increases a counter that keeps track of number of chunk data packs sent to the fetcher engine from
   308  // requester engine.
   309  func (vc *VerificationCollector) OnChunkDataPackSentToFetcher() {
   310  	vc.sentChunkDataPackByRequesterTotal.Inc()
   311  }
   312  
   313  // OnChunkDataPackArrivedAtFetcher increments a counter that keeps track of number of chunk data packs arrived at fetcher engine from
   314  // requester engine.
   315  func (vc *VerificationCollector) OnChunkDataPackArrivedAtFetcher() {
   316  	vc.receivedChunkDataPackTotalFetcher.Inc()
   317  }
   318  
   319  // OnVerifiableChunkSentToVerifier increments a counter that keeps track of number of verifiable chunks fetcher engine sent to verifier engine.
   320  func (vc *VerificationCollector) OnVerifiableChunkSentToVerifier() {
   321  	vc.sentVerifiableChunksTotalFetcher.Inc()
   322  }
   323  
   324  // OnChunkConsumerJobDone is invoked by chunk consumer whenever it is notified a job is done by a worker. It
   325  // sets the last processed chunk job index.
   326  func (vc *VerificationCollector) OnChunkConsumerJobDone(processedIndex uint64) {
   327  	vc.lastProcessedChunkJobIndexChunkConsumer.Set(float64(processedIndex))
   328  }
   329  
   330  // OnBlockConsumerJobDone is invoked by block consumer whenever it is notified a job is done by a worker. It
   331  // sets the last processed block job index.
   332  func (vc *VerificationCollector) OnBlockConsumerJobDone(processedIndex uint64) {
   333  	vc.lastProcessedBlockJobIndexBlockConsumer.Set(float64(processedIndex))
   334  }
   335  
   336  // SetMaxChunkDataPackAttemptsForNextUnsealedHeightAtRequester is invoked when a cycle of requesting chunk data packs is done by requester engine.
   337  // It updates the maximum number of attempts made by requester engine for requesting the chunk data packs of the next unsealed height.
   338  // The maximum is taken over the history of all chunk data packs requested during that cycle that belong to the next unsealed height.
   339  func (vc *VerificationCollector) SetMaxChunkDataPackAttemptsForNextUnsealedHeightAtRequester(attempts uint64) {
   340  	vc.maxChunkDataPackRequestAttemptForNextUnsealedHeight.Set(float64(attempts))
   341  }