generated from flashbots/go-template
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathmetrics.go
281 lines (252 loc) · 7.58 KB
/
metrics.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
// Package metrics provides prometheus metrics primitives to the rest of the app
package metrics
import (
"context"
"math"
"go.opentelemetry.io/otel/exporters/prometheus"
otelapi "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
)
const (
metricsNamespace = "mev-boost-relay"
)
var (
meter otelapi.Meter
GetHeaderLatencyHistogram otelapi.Float64Histogram
GetPayloadLatencyHistogram otelapi.Float64Histogram
PublishBlockLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockReadLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockDecodeLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockPrechecksLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockSimulationLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockRedisLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockRedisPayloadLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockRedisTopBidLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockRedisFloorLatencyHistogram otelapi.Float64Histogram
BuilderDemotionCount otelapi.Int64Counter
// latencyBoundariesMs is the set of buckets of exponentially growing
// latencies that are ranging from 5ms up to 12s
latencyBoundariesMs = otelapi.WithExplicitBucketBoundaries(func() []float64 {
base := math.Exp(math.Log(12.0) / 15.0)
res := make([]float64, 0, 48)
for i := -31; i < 16; i++ {
res = append(res,
1000.0*math.Pow(base, float64(i)),
)
}
return res
}()...)
)
func Setup(ctx context.Context) error {
for _, setup := range []func(context.Context) error{
setupMeter, // must come first
setupGetHeaderLatency,
setupGetPayloadLatency,
setupPublishBlockLatency,
setupSubmitNewBlockLatency,
setupSubmitNewBlockReadLatency,
setupSubmitNewBlockDecodeLatency,
setupSubmitNewBlockPrechecksLatency,
setupSubmitNewBlockSimulationLatency,
setupSubmitNewBlockRedisLatency,
setupSubmitNewBlockRedisPayloadLatency,
setupSubmitNewBlockRedisTopBidLatency,
setupSubmitNewBlockRedisFloorLatency,
setupBuilderDemotionCount,
} {
if err := setup(ctx); err != nil {
return err
}
}
return nil
}
func setupMeter(ctx context.Context) error {
res, err := resource.New(ctx,
resource.WithAttributes(semconv.ServiceName(metricsNamespace)),
)
if err != nil {
return err
}
exporter, err := prometheus.New(
prometheus.WithNamespace(metricsNamespace),
)
if err != nil {
return err
}
provider := metric.NewMeterProvider(
metric.WithReader(exporter),
metric.WithResource(res),
)
meter = provider.Meter(metricsNamespace)
return nil
}
func setupGetHeaderLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"get_header_latency",
otelapi.WithDescription("statistics on the duration of getHeader requests execution"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
GetHeaderLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupGetPayloadLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"get_payload_latency",
otelapi.WithDescription("statistics on the duration of getPayload requests execution"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
GetPayloadLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupPublishBlockLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"publish_block_latency",
otelapi.WithDescription("statistics on the duration of publishBlock requests sent to beacon node"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
PublishBlockLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupSubmitNewBlockLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_latency",
otelapi.WithDescription("statistics on the duration of submitNewBlock requests execution"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupSubmitNewBlockReadLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_read_latency",
otelapi.WithDescription("statistics on the duration of reading the payload of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockReadLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupSubmitNewBlockDecodeLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_decode_latency",
otelapi.WithDescription("statistics on the duration of decoding the payload of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockDecodeLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupSubmitNewBlockPrechecksLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_prechecks_latency",
otelapi.WithDescription("statistics on the duration of prechecks (floor bid, signature etc.) of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockPrechecksLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupSubmitNewBlockSimulationLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_simulation_latency",
otelapi.WithDescription("statistics on the block simulation duration of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockSimulationLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupSubmitNewBlockRedisLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_redis_latency",
otelapi.WithDescription("statistics on the redis update duration of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockRedisLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupSubmitNewBlockRedisPayloadLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_redis_payload_latency",
otelapi.WithDescription("statistics on the redis save payload duration during redis updates of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockRedisPayloadLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupSubmitNewBlockRedisTopBidLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_redis_top_bid_latency",
otelapi.WithDescription("statistics on the redis update top bid duration during redis updates of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockRedisTopBidLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupSubmitNewBlockRedisFloorLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_redis_floor_latency",
otelapi.WithDescription("statistics on the redis update floor bid duration during redis updates of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockRedisFloorLatencyHistogram = latency
if err != nil {
return err
}
return nil
}
func setupBuilderDemotionCount(_ context.Context) error {
counter, err := meter.Int64Counter(
"builder_demotion_count",
otelapi.WithDescription("number of times a builder has been demoted"),
)
BuilderDemotionCount = counter
if err != nil {
return err
}
return nil
}