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

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