-
Notifications
You must be signed in to change notification settings - Fork 178
/
hotstuff.go
217 lines (185 loc) · 9.11 KB
/
hotstuff.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/onflow/flow-go/model/flow"
)
// HotStuff Metrics
const (
HotstuffEventTypeTimeout = "timeout"
HotstuffEventTypeOnProposal = "onproposal"
HotstuffEventTypeOnVote = "onvote"
HotstuffEventTypeOnQC = "onqc"
)
// HotstuffCollector implements only the metrics emitted by the HotStuff core logic.
// We have multiple instances of HotStuff running within Flow: Consensus Nodes form
// the main consensus committee. In addition each Collector node cluster runs their
// own HotStuff instance. Depending on the node role, the name space is different. Furthermore,
// even within the `collection` name space, we need to separate metrics between the different
// clusters. We do this by adding the label `committeeID` to the HotStuff metrics and
// allowing for configurable name space.
type HotstuffCollector struct {
busyDuration *prometheus.HistogramVec
idleDuration prometheus.Histogram
waitDuration *prometheus.HistogramVec
curView prometheus.Gauge
qcView prometheus.Gauge
skips prometheus.Counter
timeouts prometheus.Counter
timeoutDuration prometheus.Gauge
committeeComputationsDuration prometheus.Histogram
signerComputationsDuration prometheus.Histogram
validatorComputationsDuration prometheus.Histogram
payloadProductionDuration prometheus.Histogram
}
func NewHotstuffCollector(chain flow.ChainID) *HotstuffCollector {
hc := &HotstuffCollector{
busyDuration: promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "busy_duration_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "duration [seconds; measured with float64 precision] of how long HotStuff's event loop has been busy processing one event",
Buckets: []float64{0.05, 0.2, 0.5, 1, 2, 5},
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}, []string{"event_type"}),
idleDuration: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "idle_duration_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "duration [seconds; measured with float64 precision] of how long HotStuff's event loop has been idle without processing any event",
Buckets: []float64{0.05, 0.2, 0.5, 1, 2, 5},
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
waitDuration: promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "wait_duration_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "duration [seconds; measured with float64 precision] of how long an event has been waited in the HotStuff event loop queue before being processed.",
Buckets: []float64{0.05, 0.2, 0.5, 1, 2, 5},
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}, []string{"event_type"}),
curView: promauto.NewGauge(prometheus.GaugeOpts{
Name: "cur_view",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "the current view that the event handler has entered",
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
qcView: promauto.NewGauge(prometheus.GaugeOpts{
Name: "qc_view",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "The view of the newest known qc from HotStuff",
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
skips: promauto.NewCounter(prometheus.CounterOpts{
Name: "skips_total",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "The number of times we skipped ahead some views",
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
timeouts: promauto.NewCounter(prometheus.CounterOpts{
Name: "timeouts_total",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "The number of times we timed out during a view",
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
timeoutDuration: promauto.NewGauge(prometheus.GaugeOpts{
Name: "timeout_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "The current length of the timeout",
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
committeeComputationsDuration: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "committee_computations_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "duration [seconds; measured with float64 precision] of how long HotStuff sends computing consensus committee relations",
Buckets: []float64{0.02, 0.05, 0.1, 0.2, 0.5, 1, 2},
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
signerComputationsDuration: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "crypto_computations_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "duration [seconds; measured with float64 precision] of how long HotStuff sends with crypto-related operations",
Buckets: []float64{0.02, 0.05, 0.1, 0.2, 0.5, 1, 2},
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
validatorComputationsDuration: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "message_validation_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "duration [seconds; measured with float64 precision] of how long HotStuff sends with message-validation",
Buckets: []float64{0.02, 0.05, 0.1, 0.2, 0.5, 1, 2},
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
payloadProductionDuration: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "payload_production_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "duration [seconds; measured with float64 precision] of how long HotStuff sends with payload production",
Buckets: []float64{0.02, 0.05, 0.1, 0.2, 0.5, 1, 2},
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
}
return hc
}
// HotStuffBusyDuration reports Metrics C6 HotStuff Busy Duration
func (hc *HotstuffCollector) HotStuffBusyDuration(duration time.Duration, event string) {
hc.busyDuration.WithLabelValues(event).Observe(duration.Seconds()) // unit: seconds; with float64 precision
}
// HotStuffIdleDuration reports Metrics C6 HotStuff Idle Duration
func (hc *HotstuffCollector) HotStuffIdleDuration(duration time.Duration) {
hc.idleDuration.Observe(duration.Seconds()) // unit: seconds; with float64 precision
}
// HotStuffWaitDuration reports Metrics C6 HotStuff Wait Duration
func (hc *HotstuffCollector) HotStuffWaitDuration(duration time.Duration, event string) {
hc.waitDuration.WithLabelValues(event).Observe(duration.Seconds()) // unit: seconds; with float64 precision
}
// HotstuffCollector reports Metrics C8: Current View
func (hc *HotstuffCollector) SetCurView(view uint64) {
hc.curView.Set(float64(view))
}
// NewestKnownQC reports Metrics C9: View of Newest Known QC
func (hc *HotstuffCollector) SetQCView(view uint64) {
hc.qcView.Set(float64(view))
}
// CountSkipped counts the number of skips we did.
func (hc *HotstuffCollector) CountSkipped() {
hc.skips.Inc()
}
// CountTimeout counts the number of timeouts we had.
func (hc *HotstuffCollector) CountTimeout() {
hc.timeouts.Inc()
}
// SetTimeout sets the current timeout duration.
func (hc *HotstuffCollector) SetTimeout(duration time.Duration) {
hc.timeoutDuration.Set(duration.Seconds()) // unit: seconds; with float64 precision
}
// CommitteeProcessingDuration measures the time which the HotStuff's core logic
// spends in the hotstuff.Committee component, i.e. the time determining consensus
// committee relations.
func (hc *HotstuffCollector) CommitteeProcessingDuration(duration time.Duration) {
hc.committeeComputationsDuration.Observe(duration.Seconds()) // unit: seconds; with float64 precision
}
// SignerProcessingDuration reports the time which the HotStuff's core logic
// spends in the hotstuff.Signer component, i.e. the with crypto-related operations.
func (hc *HotstuffCollector) SignerProcessingDuration(duration time.Duration) {
hc.signerComputationsDuration.Observe(duration.Seconds()) // unit: seconds; with float64 precision
}
// ValidatorProcessingDuration reports the time which the HotStuff's core logic
// spends in the hotstuff.Validator component, i.e. the with verifying higher-level
// consensus messages.
func (hc *HotstuffCollector) ValidatorProcessingDuration(duration time.Duration) {
hc.validatorComputationsDuration.Observe(duration.Seconds()) // unit: seconds; with float64 precision
}
// PayloadProductionDuration reports the time which the HotStuff's core logic
// spends in the module.Builder component, i.e. the with generating block payloads
func (hc *HotstuffCollector) PayloadProductionDuration(duration time.Duration) {
hc.payloadProductionDuration.Observe(duration.Seconds()) // unit: seconds; with float64 precision
}