-
Notifications
You must be signed in to change notification settings - Fork 176
/
metrics_wrapper.go
32 lines (27 loc) · 1.02 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
package blockproducer
import (
"time"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
)
// BlockBuilderMetricsWrapper implements the module.Builder interface.
// It wraps a module.Builder instance and measures the time which HotStuff's core logic
// spends in the module.Builder component, i.e. the with generating block payloads.
// The measured time durations are reported as values for the
// PayloadProductionDuration metric.
type BlockBuilderMetricsWrapper struct {
builder module.Builder
metrics module.HotstuffMetrics
}
func NewMetricsWrapper(builder module.Builder, metrics module.HotstuffMetrics) *BlockBuilderMetricsWrapper {
return &BlockBuilderMetricsWrapper{
builder: builder,
metrics: metrics,
}
}
func (w BlockBuilderMetricsWrapper) BuildOn(parentID flow.Identifier, setter func(*flow.Header) error) (*flow.Header, error) {
processStart := time.Now()
header, err := w.builder.BuildOn(parentID, setter)
w.metrics.PayloadProductionDuration(time.Since(processStart))
return header, err
}