-
Notifications
You must be signed in to change notification settings - Fork 179
/
hotstuff.go
304 lines (265 loc) · 13.5 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
)
// HotStuff Metrics
const (
HotstuffEventTypeLocalTimeout = "localtimeout"
HotstuffEventTypeOnProposal = "onproposal"
HotstuffEventTypeOnQC = "onqc"
HotstuffEventTypeOnTC = "ontc"
HotstuffEventTypeOnPartialTc = "onpartialtc"
)
// 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
tcView prometheus.Gauge
skips prometheus.Counter
timeouts prometheus.Counter
timeoutDuration prometheus.Gauge
voteProcessingDuration prometheus.Histogram
timeoutProcessingDuration prometheus.Histogram
blockProcessingDuration prometheus.Histogram
committeeComputationsDuration prometheus.Histogram
signerComputationsDuration prometheus.Histogram
validatorComputationsDuration prometheus.Histogram
payloadProductionDuration prometheus.Histogram
timeoutCollectorsRange *prometheus.GaugeVec
numberOfActiveCollectors prometheus.Gauge
}
var _ module.HotstuffMetrics = (*HotstuffCollector)(nil)
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()},
}),
tcView: promauto.NewGauge(prometheus.GaugeOpts{
Name: "tc_view",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "The view of the newest known TC 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 views that this replica left due to observing a TC",
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()},
}),
blockProcessingDuration: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "block_processing_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "duration [seconds; measured with float64 precision] of how long compliance engine processes one block",
Buckets: []float64{0.02, 0.05, 0.1, 0.2, 0.5, 1, 2},
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
voteProcessingDuration: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "vote_processing_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "duration [seconds; measured with float64 precision] of how long VoteAggregator processes one message",
Buckets: []float64{0.02, 0.05, 0.1, 0.2, 0.5, 1, 2},
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
timeoutProcessingDuration: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "timeout_object_processing_seconds",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "duration [seconds; measured with float64 precision] of how long TimeoutAggregator processes one message",
Buckets: []float64{0.02, 0.05, 0.1, 0.2, 0.5, 1, 2},
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}),
timeoutCollectorsRange: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "timeout_collectors_range",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "lowest and highest views that we are maintaining TimeoutCollectors for",
ConstLabels: prometheus.Labels{LabelChain: chain.String()},
}, []string{"prefix"}),
numberOfActiveCollectors: promauto.NewGauge(prometheus.GaugeOpts{
Name: "active_collectors",
Namespace: namespaceConsensus,
Subsystem: subsystemHotstuff,
Help: "number of active TimeoutCollectors that the TimeoutAggregator component currently maintains",
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 Idle Duration - the time between receiving and
// enqueueing a message to beginning to process that message.
func (hc *HotstuffCollector) HotStuffWaitDuration(duration time.Duration, event string) {
hc.waitDuration.WithLabelValues(event).Observe(duration.Seconds()) // unit: seconds; with float64 precision
}
// CountSkipped counts the number of skips we did.
func (hc *HotstuffCollector) CountSkipped() {
hc.skips.Inc()
}
// CountTimeout tracks the number of views that this replica left due to observing a TC.
func (hc *HotstuffCollector) CountTimeout() {
hc.timeouts.Inc()
}
// SetCurView reports Metrics C8: Current View
func (hc *HotstuffCollector) SetCurView(view uint64) {
hc.curView.Set(float64(view))
}
// SetQCView reports Metrics C9: View of Newest Known QC
func (hc *HotstuffCollector) SetQCView(view uint64) {
hc.qcView.Set(float64(view))
}
// SetTCView reports the view of the newest known TC
func (hc *HotstuffCollector) SetTCView(view uint64) {
hc.tcView.Set(float64(view))
}
// BlockProcessingDuration measures the time which the compliance engine
// spends to process one block proposal.
func (hc *HotstuffCollector) BlockProcessingDuration(duration time.Duration) {
hc.blockProcessingDuration.Observe(duration.Seconds())
}
// VoteProcessingDuration reports the processing time for a single vote
func (hc *HotstuffCollector) VoteProcessingDuration(duration time.Duration) {
hc.voteProcessingDuration.Observe(duration.Seconds())
}
// TimeoutObjectProcessingDuration reports the processing time for a TimeoutObject
func (hc *HotstuffCollector) TimeoutObjectProcessingDuration(duration time.Duration) {
hc.timeoutProcessingDuration.Observe(duration.Seconds())
}
// 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
}
// TimeoutCollectorsRange collects information from the node's `TimeoutAggregator` component.
// Specifically, it measurers the number of views for which we are currently collecting timeouts
// (i.e. the number of `TimeoutCollector` instances we are maintaining) and their lowest/highest view.
func (hc *HotstuffCollector) TimeoutCollectorsRange(lowestRetainedView uint64, newestViewCreatedCollector uint64, activeCollectors int) {
hc.timeoutCollectorsRange.WithLabelValues("lowest_view_of_active_timeout_collectors").Set(float64(lowestRetainedView))
hc.timeoutCollectorsRange.WithLabelValues("newest_view_of_active_timeout_collectors").Set(float64(newestViewCreatedCollector))
hc.numberOfActiveCollectors.Set(float64(activeCollectors))
}