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

     1  package consensus
     2  
     3  import (
     4  	"github.com/onflow/flow-go/consensus/hotstuff"
     5  	"github.com/onflow/flow-go/consensus/hotstuff/model"
     6  	"github.com/onflow/flow-go/consensus/hotstuff/notifications"
     7  	"github.com/onflow/flow-go/model/flow"
     8  	"github.com/onflow/flow-go/module"
     9  )
    10  
    11  // MetricsConsumer is a consumer that subscribes to hotstuff events and
    12  // collects metrics data when certain events trigger.
    13  // It depends on Metrics module to report metrics data.
    14  type MetricsConsumer struct {
    15  	// inherit from noop consumer in order to satisfy the full interface
    16  	notifications.NoopConsumer
    17  	metrics module.HotstuffMetrics
    18  }
    19  
    20  var _ hotstuff.Consumer = (*MetricsConsumer)(nil)
    21  
    22  func NewMetricsConsumer(metrics module.HotstuffMetrics) *MetricsConsumer {
    23  	return &MetricsConsumer{
    24  		metrics: metrics,
    25  	}
    26  }
    27  
    28  func (c *MetricsConsumer) OnQcTriggeredViewChange(_ uint64, newView uint64, qc *flow.QuorumCertificate) {
    29  	c.metrics.SetCurView(newView)
    30  	c.metrics.SetQCView(qc.View)
    31  	c.metrics.CountSkipped()
    32  }
    33  
    34  func (c *MetricsConsumer) OnTcTriggeredViewChange(_ uint64, newView uint64, tc *flow.TimeoutCertificate) {
    35  	c.metrics.SetCurView(newView)
    36  	c.metrics.SetTCView(tc.View)
    37  	c.metrics.CountTimeout()
    38  }
    39  
    40  func (c *MetricsConsumer) OnStartingTimeout(info model.TimerInfo) {
    41  	c.metrics.SetTimeout(info.Duration)
    42  }