This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetrics.go
310 lines (251 loc) · 14 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
package caboose
import (
"sync"
"github.com/prometheus/client_golang/prometheus"
)
var (
// needed to sync over these global vars in tests
distLk sync.Mutex
peerLatencyDistribution prometheus.Collector // guarded by pool.lock
)
type m_collector struct {
m *prometheus.Collector
}
func (mc m_collector) Describe(ch chan<- *prometheus.Desc) {
if (*mc.m) != nil {
(*mc.m).Describe(ch)
}
}
func (mc m_collector) Collect(ch chan<- prometheus.Metric) {
if (*mc.m) != nil {
(*mc.m).Collect(ch)
}
}
var (
// size buckets from 256 KiB to ~8Gib
// histogram buckets will be [256KiB, 512KiB, 1Mib, , ... 8GiB] -> total 16 buckets +1 prometheus Inf bucket
carSizeHistogram = prometheus.ExponentialBuckets(256.0*1024, 2, 16)
)
var (
// size buckets from 256 KiB (default chunk in Kubo) to 4MiB (maxBlockSize), 256 KiB wide each
// histogram buckets will be [256KiB, 512KiB, 768KiB, 1MiB, ... 4MiB] -> total 16 buckets +1 prometheus Inf bucket
blockSizeHistogram = prometheus.LinearBuckets(262144, 262144, 16)
// TODO: Speed max bucket could use some further refinement,
// for now we don't expect speed being bigger than transfering 4MiB (max block) in 500ms
// histogram buckets will be [1byte/milliseconds, ... 8387 bytes/milliseconds] -> total 20 buckets +1 prometheus Inf bucket
speedBytesPerMsHistogram = prometheus.ExponentialBucketsRange(1, 4194304/500, 20)
// ----- Histogram buckets to record fetch duration metrics -----
// The upper bound on the fetch duration buckets are informed by the timeouts per block and per peer request/retry.
// buckets to record duration in milliseconds to fetch a block,
// histogram buckets will be [50ms,.., 60 seconds] -> total 20 buckets +1 prometheus Inf bucket
durationMsPerBlockHistogram = prometheus.ExponentialBucketsRange(50, 60000, 20)
// buckets to record duration in milliseconds to fetch a CAR,
// histogram buckets will be [50ms,.., 30 minutes] -> total 40 buckets +1 prometheus Inf bucket
durationMsPerCarHistogram = prometheus.ExponentialBucketsRange(50, 1800000, 40)
// buckets to measure latency between a caboose peer a Saturn L1,
// [50ms, 100ms, 150ms, ..., 2000 ms]
latencyDistMsHistogram = prometheus.LinearBuckets(50, 50, 40)
)
var (
fetchResponseCodeMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_response_code"),
Help: "Response codes observed during caboose fetches for a block",
}, []string{"resourceType", "code"})
// success cases
fetchSpeedPerPeerSuccessMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_speed_peer_success"),
Help: "Speed observed during caboose fetches for successfully fetching from a single peer in bytes/ms",
Buckets: speedBytesPerMsHistogram,
}, []string{"resourceType", "cache_status"})
fetchCacheCountSuccessTotalMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_cache_count_success_total"),
Help: "Records cache hits and cache hits for successful fetches from Saturn",
}, []string{"resourceType", "cache_status"})
)
// block metrics
var (
fetchDurationPerBlockPerPeerSuccessMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_block_peer_success"),
Help: "Latency observed during successful caboose fetches from a single peer in milliseconds",
Buckets: durationMsPerBlockHistogram,
}, []string{"cache_status"})
fetchDurationBlockSuccessMetric = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_block_success"),
Help: "Latency observed during successful caboose fetches for a block across multiple peers and retries in milliseconds",
Buckets: durationMsPerBlockHistogram,
})
fetchTTFBPerBlockPerPeerSuccessMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_ttfb_block_peer_success"),
Help: "TTFB observed during a successful caboose fetch from a single peer in milliseconds",
Buckets: durationMsPerBlockHistogram,
}, []string{"cache_status"})
// failures
fetchDurationPerBlockPerPeerFailureMetric = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_block_peer_failure"),
Help: "Latency observed during failed caboose fetches from a single peer in milliseconds",
Buckets: durationMsPerBlockHistogram,
})
fetchDurationBlockFailureMetric = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_block_failure"),
Help: "Latency observed during failed caboose fetches for a block across multiple peers and retries in milliseconds",
Buckets: durationMsPerBlockHistogram,
})
fetchSizeBlockMetric = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_size_block"),
Help: "Size in bytes of caboose block fetches",
Buckets: blockSizeHistogram,
})
)
// CAR metrics
var (
fetchDurationPerCarPerPeerSuccessMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_car_peer_success"),
Help: "Latency observed during successful caboose car fetches from a single peer in milliseconds",
Buckets: durationMsPerCarHistogram,
}, []string{"cache_status"})
fetchDurationCarSuccessMetric = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_car_success"),
Help: "Latency observed during successful caboose fetches for a car across multiple peers and retries in milliseconds",
Buckets: durationMsPerCarHistogram,
})
fetchTTFBPerCARPerPeerSuccessMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_ttfb_car_peer_success"),
Help: "TTFB observed during a successful caboose CAR fetch from a single peer in milliseconds",
Buckets: durationMsPerCarHistogram,
}, []string{"cache_status", "car_size"})
headerTTFBPerPeerMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "header_ttfb_peer"),
Buckets: durationMsPerCarHistogram,
}, []string{"resourceType", "cache_status"})
// failure
fetchDurationPerCarPerPeerFailureMetric = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_car_peer_failure"),
Help: "Latency observed during failed caboose car fetches from a single peer in milliseconds",
Buckets: durationMsPerCarHistogram,
})
fetchDurationCarFailureMetric = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_car_failure"),
Help: "Latency observed during failed caboose fetches for a car across multiple peers and retries in milliseconds",
Buckets: durationMsPerCarHistogram,
})
fetchSizeCarMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_size_car"),
Help: "Size in bytes of caboose CAR fetches",
Buckets: carSizeHistogram,
}, []string{"error_status"})
)
// Saturn Server-timings
var (
// ---------------------- For successful fetches ONLY for now----------------------
// L1 server timings
// nginx + l1 compute + lassie
fetchDurationPerPeerSuccessTotalL1NodeMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_peer_total_saturn_l1"),
Help: "Total time spent on an L1 node for a successful fetch per peer in milliseconds",
Buckets: durationMsPerCarHistogram,
}, []string{"resourceType", "cache_status"})
// total only on lassie
fetchDurationPerPeerSuccessCacheMissTotalLassieMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_peer_cache_miss_total_lassie"),
Help: "Time spent in Lassie for a Saturn L1 Nginx cache miss for a successful fetch per peer in milliseconds",
Buckets: durationMsPerCarHistogram,
}, []string{"resourceType"})
lassie5XXTimeMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_duration_5xx_total_lassie"),
Help: "Time spent in Lassie for a Saturn L1 Nginx cache miss for a 5xx in milliseconds",
Buckets: durationMsPerCarHistogram,
}, []string{"resourceType"})
// network timing
fetchNetworkSpeedPerPeerSuccessMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_network_speed_peer_success"),
Help: "Network speed observed during successful caboose fetches from a single peer in bytes per milliseconds",
Buckets: speedBytesPerMsHistogram,
}, []string{"resourceType"})
fetchNetworkLatencyPeerSuccessMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_network_latency_peer_success"),
Help: "Network latency observed during successful caboose fetches from a single peer in milliseconds",
Buckets: durationMsPerCarHistogram,
}, []string{"resourceType"})
)
var (
fetchCalledTotalMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_called_total"),
}, []string{"resourceType"})
fetchRequestContextErrorTotalMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_request_context_error_total"),
}, []string{"resourceType", "errorType", "requestStage"})
fetchRequestSuccessTimeTraceMetric = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_request_success_time_trace"),
Buckets: durationMsPerCarHistogram,
}, []string{"resourceType", "cache_status", "lifecycleStage"})
)
var (
saturnCallsTotalMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "saturn_calls_total"),
}, []string{"resourceType"})
saturnCallsSuccessTotalMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "saturn_calls_success_total"),
}, []string{"resourceType", "cache_status"})
saturnCallsFailureTotalMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "saturn_calls_failure_total"),
}, []string{"resourceType", "reason", "code"})
saturnConnectionFailureTotalMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "saturn_connection_failure_total"),
}, []string{"resourceType", "reason"})
mirroredTrafficTotalMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "mirrored_traffic_total"),
}, []string{"error_status"})
complianceCidCallsTotalMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "compliance_cids_total"),
}, []string{"error_status"})
emptyCarErrorTotalMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "empty_car_error_total"),
}, []string{"resourceType"})
)
var CabooseMetrics = prometheus.NewRegistry()
func init() {
// POOL Metrics
CabooseMetrics.MustRegister(poolRefreshErrorMetric)
CabooseMetrics.MustRegister(poolSizeMetric)
CabooseMetrics.MustRegister(poolNewMembersMetric)
CabooseMetrics.MustRegister(poolRemovedFailureTotalMetric)
CabooseMetrics.MustRegister(poolRemovedConnFailureTotalMetric)
CabooseMetrics.MustRegister(poolRemovedReadFailureTotalMetric)
CabooseMetrics.MustRegister(poolRemovedNon2xxTotalMetric)
CabooseMetrics.MustRegister(poolMembersNotAddedBecauseRemovedMetric)
CabooseMetrics.MustRegister(poolMembersRemovedAndAddedBackMetric)
CabooseMetrics.MustRegister(poolEnoughObservationsForMainSetDurationMetric)
CabooseMetrics.MustRegister(poolTierChangeMetric)
CabooseMetrics.MustRegister(fetchResponseCodeMetric)
CabooseMetrics.MustRegister(fetchSpeedPerPeerSuccessMetric)
CabooseMetrics.MustRegister(fetchDurationPerBlockPerPeerSuccessMetric)
CabooseMetrics.MustRegister(fetchDurationPerCarPerPeerSuccessMetric)
CabooseMetrics.MustRegister(fetchDurationPerBlockPerPeerFailureMetric)
CabooseMetrics.MustRegister(fetchDurationPerCarPerPeerFailureMetric)
CabooseMetrics.MustRegister(fetchDurationBlockSuccessMetric)
CabooseMetrics.MustRegister(fetchDurationCarSuccessMetric)
CabooseMetrics.MustRegister(fetchDurationBlockFailureMetric)
CabooseMetrics.MustRegister(fetchDurationCarFailureMetric)
CabooseMetrics.MustRegister(fetchTTFBPerBlockPerPeerSuccessMetric)
CabooseMetrics.MustRegister(fetchTTFBPerCARPerPeerSuccessMetric)
CabooseMetrics.MustRegister(headerTTFBPerPeerMetric)
CabooseMetrics.MustRegister(fetchCacheCountSuccessTotalMetric)
CabooseMetrics.MustRegister(fetchDurationPerPeerSuccessTotalL1NodeMetric)
CabooseMetrics.MustRegister(fetchDurationPerPeerSuccessCacheMissTotalLassieMetric)
CabooseMetrics.MustRegister(lassie5XXTimeMetric)
CabooseMetrics.MustRegister(fetchNetworkSpeedPerPeerSuccessMetric)
CabooseMetrics.MustRegister(fetchNetworkLatencyPeerSuccessMetric)
CabooseMetrics.MustRegister(m_collector{&peerLatencyDistribution})
CabooseMetrics.MustRegister(fetchSizeCarMetric)
CabooseMetrics.MustRegister(fetchSizeBlockMetric)
CabooseMetrics.MustRegister(fetchRequestContextErrorTotalMetric)
CabooseMetrics.MustRegister(fetchCalledTotalMetric)
CabooseMetrics.MustRegister(fetchRequestSuccessTimeTraceMetric)
CabooseMetrics.MustRegister(saturnCallsTotalMetric)
CabooseMetrics.MustRegister(saturnCallsFailureTotalMetric)
CabooseMetrics.MustRegister(saturnConnectionFailureTotalMetric)
CabooseMetrics.MustRegister(complianceCidCallsTotalMetric)
CabooseMetrics.MustRegister(saturnCallsSuccessTotalMetric)
CabooseMetrics.MustRegister(mirroredTrafficTotalMetric)
CabooseMetrics.MustRegister(emptyCarErrorTotalMetric)
}