-
Notifications
You must be signed in to change notification settings - Fork 175
/
metrics_wrapper.go
62 lines (53 loc) · 2.12 KB
/
metrics_wrapper.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// (c) 2020 Dapper Labs - ALL RIGHTS RESERVED
package committee
import (
"time"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
)
// CommitteeMetricsWrapper implements the hotstuff.Committee interface.
// It wraps a hotstuff.Committee instance and measures the time which the HotStuff's core logic
// spends in the hotstuff.Committee component, i.e. the time determining consensus committee
// relations. The measured time durations are reported as values for the
// CommitteeProcessingDuration metric.
type CommitteeMetricsWrapper struct {
committee hotstuff.Committee
metrics module.HotstuffMetrics
}
func NewMetricsWrapper(committee hotstuff.Committee, metrics module.HotstuffMetrics) *CommitteeMetricsWrapper {
return &CommitteeMetricsWrapper{
committee: committee,
metrics: metrics,
}
}
func (w CommitteeMetricsWrapper) Identities(blockID flow.Identifier, selector flow.IdentityFilter) (flow.IdentityList, error) {
processStart := time.Now()
identities, err := w.committee.Identities(blockID, selector)
w.metrics.CommitteeProcessingDuration(time.Since(processStart))
return identities, err
}
func (w CommitteeMetricsWrapper) Identity(blockID flow.Identifier, participantID flow.Identifier) (*flow.Identity, error) {
processStart := time.Now()
identity, err := w.committee.Identity(blockID, participantID)
w.metrics.CommitteeProcessingDuration(time.Since(processStart))
return identity, err
}
func (w CommitteeMetricsWrapper) LeaderForView(view uint64) (flow.Identifier, error) {
processStart := time.Now()
id, err := w.committee.LeaderForView(view)
w.metrics.CommitteeProcessingDuration(time.Since(processStart))
return id, err
}
func (w CommitteeMetricsWrapper) Self() flow.Identifier {
processStart := time.Now()
id := w.committee.Self()
w.metrics.CommitteeProcessingDuration(time.Since(processStart))
return id
}
func (w CommitteeMetricsWrapper) DKG(blockID flow.Identifier) (hotstuff.DKG, error) {
processStart := time.Now()
dkg, err := w.committee.DKG(blockID)
w.metrics.CommitteeProcessingDuration(time.Since(processStart))
return dkg, err
}