-
Notifications
You must be signed in to change notification settings - Fork 272
Expand file tree
/
Copy pathblob_fetcher_metrics.go
More file actions
108 lines (98 loc) · 3.69 KB
/
blob_fetcher_metrics.go
File metadata and controls
108 lines (98 loc) · 3.69 KB
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
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2025, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.
package blockchain
import (
"github.com/berachain/beacon-kit/observability/metrics"
)
// Metric reason constants for blob fetcher.
const (
expiredReasonOutsideDA = "outside_da_period"
expiredReasonMaxRetries = "max_retries"
)
// BlobFetcherMetrics contains metrics for the blob fetcher queue and retry operations.
type BlobFetcherMetrics struct {
RetriesTotal metrics.Counter
RequestsExpiredTotal metrics.Counter
RequestsCompletedTotal metrics.Counter
RequestsQueuedTotal metrics.Counter
QueueDepth metrics.Gauge
}
// NewBlobFetcherMetrics returns a new BlobFetcherMetrics instance with metrics from the provided factory.
// Metric names are kept identical to cosmos-sdk/telemetry output for Grafana compatibility.
func NewBlobFetcherMetrics(factory metrics.Factory) *BlobFetcherMetrics {
return &BlobFetcherMetrics{
RetriesTotal: factory.NewCounter(
metrics.CounterOpts{
Name: "beacon_kit_blob_fetcher_retries_total",
Help: "Number of times a blob request was retried after failure",
},
nil,
),
RequestsExpiredTotal: factory.NewCounter(
metrics.CounterOpts{
Name: "beacon_kit_blob_fetcher_requests_expired_total",
Help: "Number of blob fetch requests that expired before completion",
},
[]string{"reason"},
),
RequestsCompletedTotal: factory.NewCounter(
metrics.CounterOpts{
Name: "beacon_kit_blob_fetcher_requests_completed_total",
Help: "Number of blob fetch requests that completed successfully",
},
nil,
),
RequestsQueuedTotal: factory.NewCounter(
metrics.CounterOpts{
Name: "beacon_kit_blob_fetcher_requests_queued_total",
Help: "Number of new blob fetch requests added to the queue",
},
nil,
),
QueueDepth: factory.NewGauge(
metrics.GaugeOpts{
Name: "beacon_kit_blob_fetcher_queue_depth",
Help: "Current depth of the blob fetcher queue",
},
nil,
),
}
}
// recordRetry increments counter when a blob request is retried after failure.
func (m *BlobFetcherMetrics) recordRetry() {
m.RetriesTotal.Add(1)
}
// recordRequestExpired increments counter when request expires before completion.
// Reason: "outside_da_period", "max_retries"
func (m *BlobFetcherMetrics) recordRequestExpired(reason string) {
m.RequestsExpiredTotal.With("reason", reason).Add(1)
}
// recordRequestComplete increments counter when request completes successfully.
func (m *BlobFetcherMetrics) recordRequestComplete() {
m.RequestsCompletedTotal.Add(1)
}
// recordRequestQueued increments counter when a new request is added to queue.
func (m *BlobFetcherMetrics) recordRequestQueued() {
m.RequestsQueuedTotal.Add(1)
}
// setQueueDepth sets the current depth of the blob fetcher queue.
func (m *BlobFetcherMetrics) setQueueDepth(depth int) {
m.QueueDepth.Set(float64(depth))
}