github.com/koko1123/flow-go-1@v0.29.6/consensus/hotstuff/committees/metrics_wrapper.go (about) 1 // (c) 2020 Dapper Labs - ALL RIGHTS RESERVED 2 package committees 3 4 import ( 5 "time" 6 7 "github.com/koko1123/flow-go-1/consensus/hotstuff" 8 "github.com/koko1123/flow-go-1/model/flow" 9 "github.com/koko1123/flow-go-1/module" 10 ) 11 12 // CommitteeMetricsWrapper implements the hotstuff.Committee interface. 13 // It wraps a hotstuff.Committee instance and measures the time which the HotStuff's core logic 14 // spends in the hotstuff.Committee component, i.e. the time determining consensus committee 15 // relations. The measured time durations are reported as values for the 16 // CommitteeProcessingDuration metric. 17 type CommitteeMetricsWrapper struct { 18 committee hotstuff.Committee 19 metrics module.HotstuffMetrics 20 } 21 22 var _ hotstuff.Committee = (*CommitteeMetricsWrapper)(nil) 23 24 func NewMetricsWrapper(committee hotstuff.Committee, metrics module.HotstuffMetrics) *CommitteeMetricsWrapper { 25 return &CommitteeMetricsWrapper{ 26 committee: committee, 27 metrics: metrics, 28 } 29 } 30 31 func (w CommitteeMetricsWrapper) Identities(blockID flow.Identifier) (flow.IdentityList, error) { 32 processStart := time.Now() 33 identities, err := w.committee.Identities(blockID) 34 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 35 return identities, err 36 } 37 38 func (w CommitteeMetricsWrapper) Identity(blockID flow.Identifier, participantID flow.Identifier) (*flow.Identity, error) { 39 processStart := time.Now() 40 identity, err := w.committee.Identity(blockID, participantID) 41 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 42 return identity, err 43 } 44 45 func (w CommitteeMetricsWrapper) LeaderForView(view uint64) (flow.Identifier, error) { 46 processStart := time.Now() 47 id, err := w.committee.LeaderForView(view) 48 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 49 return id, err 50 } 51 52 func (w CommitteeMetricsWrapper) Self() flow.Identifier { 53 processStart := time.Now() 54 id := w.committee.Self() 55 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 56 return id 57 } 58 59 func (w CommitteeMetricsWrapper) DKG(blockID flow.Identifier) (hotstuff.DKG, error) { 60 processStart := time.Now() 61 dkg, err := w.committee.DKG(blockID) 62 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 63 return dkg, err 64 }