@@ -50,6 +50,26 @@ const OVERSIZED_OBJECT_SIZE_BUCKETS: &[f64] = &[
5050 1_000_000_000.0 , // 1000000 KiB
5151] ;
5252
53+ const EVICTION_AGE_BUCKETS : & [ f64 ] = & [
54+ 60.0 , // 1 min
55+ 300.0 , // 5 min
56+ 600.0 , // 10 min
57+ 1_800.0 , // 30 min
58+ 3_600.0 , // 1 h
59+ 7_200.0 , // 2 h
60+ 14_400.0 , // 4 h
61+ 28_800.0 , // 8 h
62+ 86_400.0 , // 1 day
63+ 172_800.0 , // 2 days
64+ 604_800.0 , // 1 week
65+ 1_209_600.0 , // 2 weeks
66+ 2_592_000.0 , // 1 month
67+ 5_184_000.0 , // 2 months
68+ 7_776_000.0 , // 3 months
69+ 15_552_000.0 , // 6 months
70+ 31_536_000.0 , // 1 year
71+ ] ;
72+
5373pub ( crate ) fn initialize_telemetry (
5474 config : & Config ,
5575) -> crate :: Result < (
@@ -301,6 +321,37 @@ pub(crate) fn record_cache_eviction(bytes: u64) {
301321 PROM_CACHE_EVICTION_BYTES_TOTAL . inc_by ( bytes) ;
302322}
303323
324+ // MARK: Eviction Age
325+
326+ pub ( crate ) fn record_cache_eviction_age ( age_secs : f64 ) {
327+ static CACHE_EVICTION_AGE_HISTOGRAM : LazyLock < Histogram < f64 > > = LazyLock :: new ( || {
328+ opentelemetry:: global:: meter ( CARGO_CRATE_NAME )
329+ . f64_histogram ( "cache.eviction_age_histogram" )
330+ . with_description ( "Age of objects (in seconds) at the time of eviction, capped at TTL" )
331+ . with_unit ( "s" )
332+ . build ( )
333+ } ) ;
334+
335+ static PROM_CACHE_EVICTION_AGE_HISTOGRAM : LazyLock < prometheus:: Histogram > =
336+ LazyLock :: new ( || {
337+ let histogram = prometheus:: Histogram :: with_opts (
338+ HistogramOpts :: new (
339+ "cache_eviction_age_histogram" ,
340+ "Age of objects (in seconds) at the time of eviction, capped at TTL" ,
341+ )
342+ . buckets ( EVICTION_AGE_BUCKETS . to_vec ( ) ) ,
343+ )
344+ . unwrap ( ) ;
345+ PROMETHEUS_REGISTRY
346+ . register ( Box :: new ( histogram. clone ( ) ) )
347+ . unwrap ( ) ;
348+ histogram
349+ } ) ;
350+
351+ CACHE_EVICTION_AGE_HISTOGRAM . record ( age_secs, & [ ] ) ;
352+ PROM_CACHE_EVICTION_AGE_HISTOGRAM . observe ( age_secs) ;
353+ }
354+
304355// MARK: Oversized Objects
305356
306357pub ( crate ) fn record_cache_oversized ( bytes : u64 ) {
0 commit comments