-
Notifications
You must be signed in to change notification settings - Fork 178
/
compliance.go
230 lines (193 loc) · 7.86 KB
/
compliance.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
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"
)
type ComplianceCollector struct {
finalizedHeight prometheus.Gauge
sealedHeight prometheus.Gauge
finalizedBlocks prometheus.Counter
sealedBlocks prometheus.Counter
finalizedPayload *prometheus.CounterVec
sealedPayload *prometheus.CounterVec
lastBlockFinalizedAt time.Time
finalizedBlocksPerSecond prometheus.Summary
committedEpochFinalView prometheus.Gauge
lastEpochTransitionHeight prometheus.Gauge
currentEpochCounter prometheus.Gauge
currentEpochPhase prometheus.Gauge
currentEpochFinalView prometheus.Gauge
currentDKGPhase1FinalView prometheus.Gauge
currentDKGPhase2FinalView prometheus.Gauge
currentDKGPhase3FinalView prometheus.Gauge
epochEmergencyFallbackTriggered prometheus.Gauge
}
var _ module.ComplianceMetrics = (*ComplianceCollector)(nil)
func NewComplianceCollector() *ComplianceCollector {
cc := &ComplianceCollector{
currentEpochCounter: promauto.NewGauge(prometheus.GaugeOpts{
Name: "current_epoch_counter",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the current epoch's counter",
}),
currentEpochPhase: promauto.NewGauge(prometheus.GaugeOpts{
Name: "current_epoch_phase",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the current epoch's phase",
}),
committedEpochFinalView: promauto.NewGauge(prometheus.GaugeOpts{
Name: "committed_epoch_final_view",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the final view of the committed epoch with the greatest counter",
}),
lastEpochTransitionHeight: promauto.NewGauge(prometheus.GaugeOpts{
Name: "last_epoch_transition_height",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the height of the most recent finalized epoch transition; in other words the height of the first block of the current epoch",
}),
currentEpochFinalView: promauto.NewGauge(prometheus.GaugeOpts{
Name: "current_epoch_final_view",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the final view of the current epoch",
}),
currentDKGPhase1FinalView: promauto.NewGauge(prometheus.GaugeOpts{
Name: "current_dkg_phase1_final_view",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the final view of phase 1 of the current epochs DKG",
}),
currentDKGPhase2FinalView: promauto.NewGauge(prometheus.GaugeOpts{
Name: "current_dkg_phase2_final_view",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the final view of phase 2 of current epochs DKG",
}),
currentDKGPhase3FinalView: promauto.NewGauge(prometheus.GaugeOpts{
Name: "current_dkg_phase3_final_view",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the final view of phase 3 of the current epochs DKG (a successful DKG will end shortly after this view)",
}),
finalizedHeight: promauto.NewGauge(prometheus.GaugeOpts{
Name: "finalized_height",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the last finalized height",
}),
sealedHeight: promauto.NewGauge(prometheus.GaugeOpts{
Name: "sealed_height",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the last sealed height",
}),
finalizedBlocks: promauto.NewCounter(prometheus.CounterOpts{
Name: "finalized_blocks_total",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the number of finalized blocks",
}),
sealedBlocks: promauto.NewCounter(prometheus.CounterOpts{
Name: "sealed_blocks_total",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the number of sealed blocks",
}),
finalizedPayload: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "finalized_payload_total",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the number of resources in finalized blocks",
}, []string{LabelResource}),
sealedPayload: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "sealed_payload_total",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the number of resources in sealed blocks",
}, []string{LabelResource}),
finalizedBlocksPerSecond: promauto.NewSummary(prometheus.SummaryOpts{
Name: "finalized_blocks_per_second",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the number of finalized blocks per second/the finalized block rate",
Objectives: map[float64]float64{
0.01: 0.001,
0.1: 0.01,
0.5: 0.05,
0.9: 0.01,
0.99: 0.001,
},
MaxAge: 10 * time.Minute,
AgeBuckets: 5,
BufCap: 500,
}),
epochEmergencyFallbackTriggered: promauto.NewGauge(prometheus.GaugeOpts{
Name: "epoch_fallback_triggered",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "indicates whether epoch emergency fallback is triggered; if >0, the fallback is triggered",
}),
}
return cc
}
// FinalizedHeight sets the finalized height.
func (cc *ComplianceCollector) FinalizedHeight(height uint64) {
cc.finalizedHeight.Set(float64(height))
}
// BlockFinalized reports metrics about finalized blocks.
func (cc *ComplianceCollector) BlockFinalized(block *flow.Block) {
now := time.Now()
if !cc.lastBlockFinalizedAt.IsZero() {
cc.finalizedBlocksPerSecond.Observe(1.0 / now.Sub(cc.lastBlockFinalizedAt).Seconds())
}
cc.lastBlockFinalizedAt = now
cc.finalizedBlocks.Inc()
cc.finalizedPayload.With(prometheus.Labels{LabelResource: ResourceGuarantee}).Add(float64(len(block.Payload.Guarantees)))
cc.finalizedPayload.With(prometheus.Labels{LabelResource: ResourceSeal}).Add(float64(len(block.Payload.Seals)))
}
// SealedHeight sets the finalized height.
func (cc *ComplianceCollector) SealedHeight(height uint64) {
cc.sealedHeight.Set(float64(height))
}
// BlockSealed reports metrics about sealed blocks.
func (cc *ComplianceCollector) BlockSealed(block *flow.Block) {
cc.sealedBlocks.Inc()
cc.sealedPayload.With(prometheus.Labels{LabelResource: ResourceGuarantee}).Add(float64(len(block.Payload.Guarantees)))
cc.sealedPayload.With(prometheus.Labels{LabelResource: ResourceSeal}).Add(float64(len(block.Payload.Seals)))
}
func (cc *ComplianceCollector) CommittedEpochFinalView(view uint64) {
cc.committedEpochFinalView.Set(float64(view))
}
func (cc *ComplianceCollector) EpochTransitionHeight(height uint64) {
// An epoch transition comprises a block in epoch N followed by a block in epoch N+1.
// height here refers to the height of the first block in epoch N+1.
cc.lastEpochTransitionHeight.Set(float64(height))
}
func (cc *ComplianceCollector) CurrentEpochCounter(counter uint64) {
cc.currentEpochCounter.Set(float64(counter))
}
func (cc *ComplianceCollector) CurrentEpochPhase(phase flow.EpochPhase) {
cc.currentEpochPhase.Set(float64(phase))
}
func (cc *ComplianceCollector) CurrentEpochFinalView(view uint64) {
cc.currentEpochFinalView.Set(float64(view))
}
func (cc *ComplianceCollector) CurrentDKGPhase1FinalView(view uint64) {
cc.currentDKGPhase1FinalView.Set(float64(view))
}
func (cc *ComplianceCollector) CurrentDKGPhase2FinalView(view uint64) {
cc.currentDKGPhase2FinalView.Set(float64(view))
}
func (cc *ComplianceCollector) CurrentDKGPhase3FinalView(view uint64) {
cc.currentDKGPhase3FinalView.Set(float64(view))
}
func (cc *ComplianceCollector) EpochEmergencyFallbackTriggered() {
cc.epochEmergencyFallbackTriggered.Set(float64(1))
}