Skip to content

Commit 268072a

Browse files
committed
Consolidate rate limiter metrics
Signed-off-by: Arve Knudsen <[email protected]>
1 parent 7d8248c commit 268072a

File tree

2 files changed

+186
-180
lines changed

2 files changed

+186
-180
lines changed

pkg/storage/bucket/gcs/rate_limiter.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type rateLimiter struct {
4545

4646
// newRateLimiter creates a new rate limiter with exponential doubling.
4747
// The rate starts at initialQPS (capped by maxQPS) and doubles every rampPeriod until it reaches maxQPS.
48-
// The operation parameter is used to differentiate metrics (e.g., "upload" or "read").
48+
// The mode parameter configures whether to rate limit uploads or reads.
4949
// If reg is nil, no metrics will be registered.
5050
func newRateLimiter(maxQPS int, rampPeriod time.Duration, mode rateLimiterMode, reg prometheus.Registerer) *rateLimiter {
5151
var initialQPS int
@@ -71,17 +71,21 @@ func newRateLimiter(maxQPS int, rampPeriod time.Duration, mode rateLimiterMode,
7171
}
7272

7373
if reg != nil {
74+
constLabels := prometheus.Labels{"operation": operation}
7475
rl.rateLimitedSeconds = promauto.With(reg).NewCounter(prometheus.CounterOpts{
75-
Name: "cortex_gcs_" + operation + "_rate_limited_seconds_total",
76-
Help: "Total seconds spent waiting due to GCS " + operation + " rate limiting.",
76+
Name: "cortex_gcs_rate_limited_seconds_total",
77+
Help: "Total seconds spent waiting due to GCS rate limiting.",
78+
ConstLabels: constLabels,
7779
})
7880
rl.currentQPSGauge = promauto.With(reg).NewGauge(prometheus.GaugeOpts{
79-
Name: "cortex_gcs_" + operation + "_current_qps",
80-
Help: "Current queries per second limit for GCS " + operation + "s.",
81+
Name: "cortex_gcs_current_qps",
82+
Help: "Current queries per second limit for GCS operations.",
83+
ConstLabels: constLabels,
8184
})
8285
rl.requestsTotal = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
83-
Name: "cortex_gcs_" + operation + "_requests_total",
84-
Help: "Total GCS " + operation + " requests, labeled by whether they were allowed immediately or rate limited.",
86+
Name: "cortex_gcs_requests_total",
87+
Help: "Total GCS requests, labeled by whether they were allowed immediately or rate limited.",
88+
ConstLabels: constLabels,
8589
}, []string{"allowed"})
8690
rl.currentQPSGauge.Set(float64(startQPS))
8791
}

0 commit comments

Comments
 (0)