Skip to content

Commit 1295a0d

Browse files
committed
Rename metrics, unifying prefix to "s3_cache" and dropping redundant "cache" infix
1 parent 0eb605c commit 1295a0d

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

src/telemetry.rs

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::{sync::LazyLock, time::Duration};
23

34
use opentelemetry::KeyValue;
@@ -12,15 +13,18 @@ use crate::{CARGO_CRATE_NAME, Config};
1213

1314
static RESOURCE: LazyLock<opentelemetry_sdk::Resource> = LazyLock::new(|| {
1415
opentelemetry_sdk::Resource::builder()
16+
.with_service_name("s3_cache")
1517
.with_service_name(CARGO_CRATE_NAME)
1618
.build()
1719
});
1820

1921
// Prometheus registry and metrics
2022

2123
pub(crate) static PROMETHEUS_REGISTRY: LazyLock<Registry> = LazyLock::new(|| {
22-
Registry::new_custom(Some("s3_cache".to_string()), None)
23-
.expect("Failed to create Prometheus registry")
24+
let mut labels = HashMap::default();
25+
labels.insert("service_name".to_string(), "s3_cache".to_string());
26+
27+
Registry::new_custom(None, Some(labels)).expect("Failed to create Prometheus registry")
2428
});
2529

2630
const OBJECT_SIZE_BUCKETS: &[f64] = &[
@@ -175,15 +179,15 @@ pub(crate) fn shutdown_metrics(metric_provider: opentelemetry_sdk::metrics::SdkM
175179
pub(crate) fn record_cache_hit(bytes: u64) {
176180
static CACHE_HIT_BYTES_HISTOGRAM: LazyLock<Histogram<u64>> = LazyLock::new(|| {
177181
opentelemetry::global::meter(CARGO_CRATE_NAME)
178-
.u64_histogram("cache.hit_bytes_histogram")
182+
.u64_histogram("s3_cache.hit_bytes_histogram")
179183
.with_description("Distribution of object sizes on cache hits")
180184
.build()
181185
});
182186

183187
static PROM_CACHE_HIT_BYTES_HISTOGRAM: LazyLock<prometheus::Histogram> = LazyLock::new(|| {
184188
let histogram = prometheus::Histogram::with_opts(
185189
HistogramOpts::new(
186-
"cache_hit_bytes_histogram",
190+
"s3_cache_hit_bytes_histogram",
187191
"Distribution of object sizes on cache hits",
188192
)
189193
.buckets(OBJECT_SIZE_BUCKETS.to_vec()),
@@ -197,14 +201,14 @@ pub(crate) fn record_cache_hit(bytes: u64) {
197201

198202
static CACHE_HIT_BYTES_TOTAL: LazyLock<Counter<u64>> = LazyLock::new(|| {
199203
opentelemetry::global::meter(CARGO_CRATE_NAME)
200-
.u64_counter("cache.hit_bytes_total")
204+
.u64_counter("s3_cache.hit_bytes_total")
201205
.with_description("Total bytes received from cache hits")
202206
.build()
203207
});
204208

205209
static PROM_CACHE_HIT_BYTES_TOTAL: LazyLock<IntCounter> = LazyLock::new(|| {
206210
let counter = IntCounter::new(
207-
"cache_hit_bytes_total",
211+
"s3_cache_hit_bytes_total",
208212
"Total bytes received from cache hits",
209213
)
210214
.unwrap();
@@ -225,15 +229,15 @@ pub(crate) fn record_cache_hit(bytes: u64) {
225229
pub(crate) fn record_cache_miss(bytes: u64) {
226230
static CACHE_MISS_BYTES_HISTOGRAM: LazyLock<Histogram<u64>> = LazyLock::new(|| {
227231
opentelemetry::global::meter(CARGO_CRATE_NAME)
228-
.u64_histogram("cache.miss_bytes_histogram")
232+
.u64_histogram("s3_cache.miss_bytes_histogram")
229233
.with_description("Distribution of object sizes on cache misses")
230234
.build()
231235
});
232236

233237
static PROM_CACHE_MISS_BYTES_HISTOGRAM: LazyLock<prometheus::Histogram> = LazyLock::new(|| {
234238
let histogram = prometheus::Histogram::with_opts(
235239
HistogramOpts::new(
236-
"cache_miss_bytes_histogram",
240+
"s3_cache_miss_bytes_histogram",
237241
"Distribution of object sizes on cache misses",
238242
)
239243
.buckets(OBJECT_SIZE_BUCKETS.to_vec()),
@@ -247,14 +251,14 @@ pub(crate) fn record_cache_miss(bytes: u64) {
247251

248252
static CACHE_MISS_BYTES_TOTAL: LazyLock<Counter<u64>> = LazyLock::new(|| {
249253
opentelemetry::global::meter(CARGO_CRATE_NAME)
250-
.u64_counter("cache.miss_bytes_total")
254+
.u64_counter("s3_cache.miss_bytes_total")
251255
.with_description("Total bytes received from cache misses")
252256
.build()
253257
});
254258

255259
static PROM_CACHE_MISS_BYTES_TOTAL: LazyLock<IntCounter> = LazyLock::new(|| {
256260
let counter = IntCounter::new(
257-
"cache_miss_bytes_total",
261+
"s3_cache_miss_bytes_total",
258262
"Total bytes received from cache misses",
259263
)
260264
.unwrap();
@@ -275,7 +279,7 @@ pub(crate) fn record_cache_miss(bytes: u64) {
275279
pub(crate) fn record_cache_eviction(bytes: u64) {
276280
static CACHE_EVICTION_BYTES_HISTOGRAM: LazyLock<Histogram<u64>> = LazyLock::new(|| {
277281
opentelemetry::global::meter(CARGO_CRATE_NAME)
278-
.u64_histogram("cache.eviction_bytes_histogram")
282+
.u64_histogram("s3_cache.eviction_bytes_histogram")
279283
.with_description("Distribution of object sizes on cache evictions")
280284
.build()
281285
});
@@ -284,7 +288,7 @@ pub(crate) fn record_cache_eviction(bytes: u64) {
284288
LazyLock::new(|| {
285289
let histogram = prometheus::Histogram::with_opts(
286290
HistogramOpts::new(
287-
"cache_eviction_bytes_histogram",
291+
"s3_cache_eviction_bytes_histogram",
288292
"Distribution of object sizes on cache evictions",
289293
)
290294
.buckets(OBJECT_SIZE_BUCKETS.to_vec()),
@@ -298,14 +302,14 @@ pub(crate) fn record_cache_eviction(bytes: u64) {
298302

299303
static CACHE_EVICTION_BYTES_TOTAL: LazyLock<Counter<u64>> = LazyLock::new(|| {
300304
opentelemetry::global::meter(CARGO_CRATE_NAME)
301-
.u64_counter("cache.eviction_bytes_total")
305+
.u64_counter("s3_cache.eviction_bytes_total")
302306
.with_description("Total bytes evicted from cache")
303307
.build()
304308
});
305309

306310
static PROM_CACHE_EVICTION_BYTES_TOTAL: LazyLock<IntCounter> = LazyLock::new(|| {
307311
let counter = IntCounter::new(
308-
"cache_eviction_bytes_total",
312+
"s3_cache_eviction_bytes_total",
309313
"Total bytes evicted from cache",
310314
)
311315
.unwrap();
@@ -326,7 +330,7 @@ pub(crate) fn record_cache_eviction(bytes: u64) {
326330
pub(crate) fn record_cache_eviction_age(age_secs: f64) {
327331
static CACHE_EVICTION_AGE_HISTOGRAM: LazyLock<Histogram<f64>> = LazyLock::new(|| {
328332
opentelemetry::global::meter(CARGO_CRATE_NAME)
329-
.f64_histogram("cache.eviction_age_histogram")
333+
.f64_histogram("s3_cache.eviction_age_histogram")
330334
.with_description("Age of objects (in seconds) at the time of eviction, capped at TTL")
331335
.with_unit("s")
332336
.build()
@@ -336,7 +340,7 @@ pub(crate) fn record_cache_eviction_age(age_secs: f64) {
336340
LazyLock::new(|| {
337341
let histogram = prometheus::Histogram::with_opts(
338342
HistogramOpts::new(
339-
"cache_eviction_age_histogram",
343+
"s3_cache_eviction_age_histogram",
340344
"Age of objects (in seconds) at the time of eviction, capped at TTL",
341345
)
342346
.buckets(EVICTION_AGE_BUCKETS.to_vec()),
@@ -357,7 +361,7 @@ pub(crate) fn record_cache_eviction_age(age_secs: f64) {
357361
pub(crate) fn record_cache_oversized(bytes: u64) {
358362
static CACHE_OVERSIZED_BYTES_HISTOGRAM: LazyLock<Histogram<u64>> = LazyLock::new(|| {
359363
opentelemetry::global::meter(CARGO_CRATE_NAME)
360-
.u64_histogram("cache.oversized_bytes_histogram")
364+
.u64_histogram("s3_cache.oversized_bytes_histogram")
361365
.with_description("Distribution of object sizes that exceeded the max cacheable size")
362366
.build()
363367
});
@@ -366,7 +370,7 @@ pub(crate) fn record_cache_oversized(bytes: u64) {
366370
LazyLock::new(|| {
367371
let histogram = prometheus::Histogram::with_opts(
368372
HistogramOpts::new(
369-
"cache_oversized_bytes_histogram",
373+
"s3_cache_oversized_bytes_histogram",
370374
"Distribution of object sizes that exceeded the max cacheable size",
371375
)
372376
.buckets(OVERSIZED_OBJECT_SIZE_BUCKETS.to_vec()),
@@ -380,7 +384,7 @@ pub(crate) fn record_cache_oversized(bytes: u64) {
380384

381385
static CACHE_OVERSIZED_BYTES_TOTAL: LazyLock<Counter<u64>> = LazyLock::new(|| {
382386
opentelemetry::global::meter(CARGO_CRATE_NAME)
383-
.u64_counter("cache.oversized_bytes_total")
387+
.u64_counter("s3_cache.oversized_bytes_total")
384388
.with_description(
385389
"Total number of objects encountered exceeding the max cacheable size",
386390
)
@@ -389,7 +393,7 @@ pub(crate) fn record_cache_oversized(bytes: u64) {
389393

390394
static PROM_CACHE_OVERSIZED_BYTES_TOTAL: LazyLock<IntCounter> = LazyLock::new(|| {
391395
let counter = IntCounter::new(
392-
"cache_oversized_bytes_total",
396+
"s3_cache_oversized_bytes_total",
393397
"Total number of objects encountered exceeding the max cacheable size",
394398
)
395399
.unwrap();
@@ -410,7 +414,7 @@ pub(crate) fn record_cache_oversized(bytes: u64) {
410414
pub(crate) fn record_unique_requested(bytes: u64) {
411415
static CACHE_UNIQUE_REQUESTED_BYTES_HISTOGRAM: LazyLock<Histogram<u64>> = LazyLock::new(|| {
412416
opentelemetry::global::meter(CARGO_CRATE_NAME)
413-
.u64_histogram("cache.estimated_unique_bytes_histogram")
417+
.u64_histogram("s3_cache.estimated_unique_bytes_histogram")
414418
.with_description("Distribution of estimated unique object sizes")
415419
.build()
416420
});
@@ -419,7 +423,7 @@ pub(crate) fn record_unique_requested(bytes: u64) {
419423
LazyLock::new(|| {
420424
let histogram = prometheus::Histogram::with_opts(
421425
HistogramOpts::new(
422-
"cache_estimated_unique_bytes_histogram",
426+
"s3_cache_estimated_unique_bytes_histogram",
423427
"Distribution of estimated unique object sizes",
424428
)
425429
.buckets(OBJECT_SIZE_BUCKETS.to_vec()),
@@ -433,14 +437,14 @@ pub(crate) fn record_unique_requested(bytes: u64) {
433437

434438
static CACHE_UNIQUE_REQUESTED_BYTES_TOTAL: LazyLock<Counter<u64>> = LazyLock::new(|| {
435439
opentelemetry::global::meter(CARGO_CRATE_NAME)
436-
.u64_counter("cache.estimated_unique_bytes_total")
440+
.u64_counter("s3_cache.estimated_unique_bytes_total")
437441
.with_description("Estimated total bytes for unique keys accessed")
438442
.build()
439443
});
440444

441445
static PROM_CACHE_UNIQUE_REQUESTED_BYTES_TOTAL: LazyLock<IntCounter> = LazyLock::new(|| {
442446
let counter = IntCounter::new(
443-
"cache_estimated_unique_bytes_total",
447+
"s3_cache_estimated_unique_bytes_total",
444448
"Estimated total bytes for unique keys accessed",
445449
)
446450
.unwrap();
@@ -461,14 +465,17 @@ pub(crate) fn record_unique_requested(bytes: u64) {
461465
pub(crate) fn record_cache_invalidation() {
462466
static CACHE_INVALIDATION_TOTAL: LazyLock<Counter<u64>> = LazyLock::new(|| {
463467
opentelemetry::global::meter(CARGO_CRATE_NAME)
464-
.u64_counter("cache.invalidation_total")
468+
.u64_counter("s3_cache.invalidation_total")
465469
.with_description("Number of cache invalidations")
466470
.build()
467471
});
468472

469473
static PROM_CACHE_INVALIDATION_TOTAL: LazyLock<IntCounter> = LazyLock::new(|| {
470-
let counter =
471-
IntCounter::new("cache_invalidation_total", "Number of cache invalidations").unwrap();
474+
let counter = IntCounter::new(
475+
"s3_cache_invalidation_total",
476+
"Number of cache invalidations",
477+
)
478+
.unwrap();
472479
PROMETHEUS_REGISTRY
473480
.register(Box::new(counter.clone()))
474481
.unwrap();
@@ -484,14 +491,14 @@ pub(crate) fn record_cache_invalidation() {
484491
pub(crate) fn record_cache_mismatch() {
485492
static CACHE_MISMATCH_ERROR_TOTAL: LazyLock<Counter<u64>> = LazyLock::new(|| {
486493
opentelemetry::global::meter(CARGO_CRATE_NAME)
487-
.u64_counter("cache.mismatch_error_total")
494+
.u64_counter("s3_cache.mismatch_error_total")
488495
.with_description("Number of cache mismatches detected in dry-run mode")
489496
.build()
490497
});
491498

492499
static PROM_CACHE_MISMATCH_ERROR_TOTAL: LazyLock<IntCounter> = LazyLock::new(|| {
493500
let counter = IntCounter::new(
494-
"cache_mismatch_error_total",
501+
"s3_cache_mismatch_error_total",
495502
"Number of cache mismatches detected in dry-run mode",
496503
)
497504
.unwrap();
@@ -510,14 +517,17 @@ pub(crate) fn record_cache_mismatch() {
510517
pub(crate) fn record_upstream_error() {
511518
static UPSTREAM_ERROR: LazyLock<Counter<u64>> = LazyLock::new(|| {
512519
opentelemetry::global::meter(CARGO_CRATE_NAME)
513-
.u64_counter("cache.upstream_error")
520+
.u64_counter("s3_cache.upstream_error")
514521
.with_description("Number of upstream S3 errors")
515522
.build()
516523
});
517524

518525
static PROM_UPSTREAM_ERROR: LazyLock<IntCounter> = LazyLock::new(|| {
519-
let counter =
520-
IntCounter::new("cache_upstream_error_total", "Number of upstream S3 errors").unwrap();
526+
let counter = IntCounter::new(
527+
"s3_cache_upstream_error_total",
528+
"Number of upstream S3 errors",
529+
)
530+
.unwrap();
521531
PROMETHEUS_REGISTRY
522532
.register(Box::new(counter.clone()))
523533
.unwrap();
@@ -533,7 +543,7 @@ pub(crate) fn record_upstream_error() {
533543
pub(crate) fn record_buffering_error() {
534544
static BUFFERING_ERROR: LazyLock<Counter<u64>> = LazyLock::new(|| {
535545
opentelemetry::global::meter(CARGO_CRATE_NAME)
536-
.u64_counter("cache.buffering_error")
546+
.u64_counter("s3_cache.buffering_error")
537547
.with_description(
538548
"Number of buffering errors (object exceeded size limit during streaming)",
539549
)
@@ -542,7 +552,7 @@ pub(crate) fn record_buffering_error() {
542552

543553
static PROM_BUFFERING_ERROR: LazyLock<IntCounter> = LazyLock::new(|| {
544554
let counter = IntCounter::new(
545-
"cache_buffering_error_total",
555+
"s3_cache_buffering_error_total",
546556
"Number of buffering errors (object exceeded size limit during streaming)",
547557
)
548558
.unwrap();
@@ -561,14 +571,14 @@ pub(crate) fn record_buffering_error() {
561571
pub(crate) fn record_cache_size_count(size_count: usize) {
562572
static CACHE_SIZE_COUNT: LazyLock<Gauge<u64>> = LazyLock::new(|| {
563573
opentelemetry::global::meter(CARGO_CRATE_NAME)
564-
.u64_gauge("cache.size_count")
574+
.u64_gauge("s3_cache.size_count")
565575
.with_description("Current number of objects in cache")
566576
.build()
567577
});
568578

569579
static PROM_CACHE_SIZE_COUNT: LazyLock<IntGauge> = LazyLock::new(|| {
570580
let gauge =
571-
IntGauge::new("cache_size_count", "Current number of objects in cache").unwrap();
581+
IntGauge::new("s3_cache_size_count", "Current number of objects in cache").unwrap();
572582
PROMETHEUS_REGISTRY
573583
.register(Box::new(gauge.clone()))
574584
.unwrap();
@@ -584,13 +594,13 @@ pub(crate) fn record_cache_size_count(size_count: usize) {
584594
pub(crate) fn record_cache_size_bytes(size_bytes: usize) {
585595
static CACHE_SIZE_BYTES: LazyLock<Gauge<u64>> = LazyLock::new(|| {
586596
opentelemetry::global::meter(CARGO_CRATE_NAME)
587-
.u64_gauge("cache.size_bytes")
597+
.u64_gauge("s3_cache.size_bytes")
588598
.with_description("Current cache size in bytes")
589599
.build()
590600
});
591601

592602
static PROM_CACHE_SIZE_BYTES: LazyLock<IntGauge> = LazyLock::new(|| {
593-
let gauge = IntGauge::new("cache_size_bytes", "Current cache size in bytes").unwrap();
603+
let gauge = IntGauge::new("s3_cache_size_bytes", "Current cache size in bytes").unwrap();
594604
PROMETHEUS_REGISTRY
595605
.register(Box::new(gauge.clone()))
596606
.unwrap();

0 commit comments

Comments
 (0)