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