Skip to content

Commit 4430ccf

Browse files
committed
Report cache purge index fill ratios
1 parent 75665a2 commit 4430ccf

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

docs/cache-backends.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ internal cache implementation.
157157
stores, disk evictions, and purges. Activity blocks include derived
158158
`requests` and `hit_ratio_per_mille` fields so operators can read hit-rate
159159
health without external JSON post-processing. Memory and disk tier status
160-
also reports `fill_ratio_per_mille`, `purge_index_entries`, and
161-
`purge_index_max_entries`, and totals report the same values split by memory
162-
and disk tiers, so operators can tell whether storage is under pressure and
163-
whether indexed scope, prefix, and wildcard purges have useful coverage or
164-
are near the bounded index cap. `POST /_fluxheim/cache/activity/reset`
165-
resets vhost and route activity counters without clearing cached objects.
160+
also reports `fill_ratio_per_mille`, `purge_index_entries`,
161+
`purge_index_max_entries`, and `purge_index_fill_ratio_per_mille`, and
162+
totals report the same values split by memory and disk tiers, so operators
163+
can tell whether storage is under pressure and whether indexed scope, prefix,
164+
and wildcard purges have useful coverage or are near the bounded index cap.
165+
`POST /_fluxheim/cache/activity/reset` resets vhost and route activity
166+
counters without clearing cached objects.
166167
- `cache.status_header` can expose compact response debug states such as
167168
`HIT`, `MISS`, `STALE`, and `BYPASS`. `cache.status_reason_header` can expose
168169
bounded no-cache reasons such as `OriginNotCache`, `ResponseTooLarge`, or

src/admin.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ fn cache_purge_results_json(results: &[crate::proxy::CachePurgeResult]) -> Strin
15781578
#[cfg(feature = "cache")]
15791579
fn cache_totals_json(totals: &crate::proxy::CacheRuntimeTotals) -> String {
15801580
format!(
1581-
r#"{{"vhosts":{},"enabled_vhosts":{},"tiered_vhosts":{},"enabled_routes":{},"tiered_routes":{},"memory_entries":{},"memory_weighted_size_bytes":{},"memory_max_size_bytes":{},"memory_fill_ratio_per_mille":{},"memory_purge_index_entries":{},"memory_purge_index_max_entries":{},"disk_entries":{},"disk_size_bytes":{},"disk_max_size_bytes":{},"disk_fill_ratio_per_mille":{},"disk_purge_index_entries":{},"disk_purge_index_max_entries":{},"activity":{}}}"#,
1581+
r#"{{"vhosts":{},"enabled_vhosts":{},"tiered_vhosts":{},"enabled_routes":{},"tiered_routes":{},"memory_entries":{},"memory_weighted_size_bytes":{},"memory_max_size_bytes":{},"memory_fill_ratio_per_mille":{},"memory_purge_index_entries":{},"memory_purge_index_max_entries":{},"memory_purge_index_fill_ratio_per_mille":{},"disk_entries":{},"disk_size_bytes":{},"disk_max_size_bytes":{},"disk_fill_ratio_per_mille":{},"disk_purge_index_entries":{},"disk_purge_index_max_entries":{},"disk_purge_index_fill_ratio_per_mille":{},"activity":{}}}"#,
15821582
totals.vhosts,
15831583
totals.enabled_vhosts,
15841584
totals.tiered_vhosts,
@@ -1593,12 +1593,20 @@ fn cache_totals_json(totals: &crate::proxy::CacheRuntimeTotals) -> String {
15931593
),
15941594
totals.memory_purge_index_entries,
15951595
totals.memory_purge_index_max_entries,
1596+
ratio_per_mille(
1597+
totals.memory_purge_index_entries,
1598+
totals.memory_purge_index_max_entries,
1599+
),
15961600
totals.disk_entries,
15971601
totals.disk_size_bytes,
15981602
totals.disk_max_size_bytes,
15991603
ratio_per_mille(totals.disk_size_bytes, totals.disk_max_size_bytes),
16001604
totals.disk_purge_index_entries,
16011605
totals.disk_purge_index_max_entries,
1606+
ratio_per_mille(
1607+
totals.disk_purge_index_entries,
1608+
totals.disk_purge_index_max_entries,
1609+
),
16021610
cache_activity_json(&crate::cache::CacheActivityStats {
16031611
hits: totals.hits,
16041612
misses: totals.misses,
@@ -1654,14 +1662,15 @@ fn memory_cache_stats_json(stats: Option<&crate::cache::MemoryCacheStats>) -> St
16541662
stats
16551663
.map(|stats| {
16561664
format!(
1657-
r#"{{"entries":{},"weighted_size_bytes":{},"max_size_bytes":{},"fill_ratio_per_mille":{},"max_object_bytes":{},"purge_index_entries":{},"purge_index_max_entries":{},"activity":{}}}"#,
1665+
r#"{{"entries":{},"weighted_size_bytes":{},"max_size_bytes":{},"fill_ratio_per_mille":{},"max_object_bytes":{},"purge_index_entries":{},"purge_index_max_entries":{},"purge_index_fill_ratio_per_mille":{},"activity":{}}}"#,
16581666
stats.entries,
16591667
stats.weighted_size_bytes,
16601668
stats.max_size_bytes.as_u64(),
16611669
ratio_per_mille(stats.weighted_size_bytes, stats.max_size_bytes.as_u64()),
16621670
stats.max_object_bytes.as_u64(),
16631671
stats.purge_index_entries,
16641672
stats.purge_index_max_entries,
1673+
ratio_per_mille(stats.purge_index_entries, stats.purge_index_max_entries),
16651674
cache_activity_json(&stats.activity)
16661675
)
16671676
})
@@ -1673,14 +1682,15 @@ fn disk_cache_stats_json(stats: Option<&crate::cache::DiskCacheStats>) -> String
16731682
stats
16741683
.map(|stats| {
16751684
format!(
1676-
r#"{{"entries":{},"size_bytes":{},"max_size_bytes":{},"fill_ratio_per_mille":{},"max_object_bytes":{},"purge_index_entries":{},"purge_index_max_entries":{},"activity":{}}}"#,
1685+
r#"{{"entries":{},"size_bytes":{},"max_size_bytes":{},"fill_ratio_per_mille":{},"max_object_bytes":{},"purge_index_entries":{},"purge_index_max_entries":{},"purge_index_fill_ratio_per_mille":{},"activity":{}}}"#,
16771686
stats.entries,
16781687
stats.size_bytes,
16791688
stats.max_size_bytes.as_u64(),
16801689
ratio_per_mille(stats.size_bytes, stats.max_size_bytes.as_u64()),
16811690
stats.max_object_bytes.as_u64(),
16821691
stats.purge_index_entries,
16831692
stats.purge_index_max_entries,
1693+
ratio_per_mille(stats.purge_index_entries, stats.purge_index_max_entries),
16841694
cache_activity_json(&stats.activity)
16851695
)
16861696
})
@@ -2472,10 +2482,12 @@ mod tests {
24722482
assert!(body.contains(r#""memory_fill_ratio_per_mille":0"#));
24732483
assert!(body.contains(r#""memory_purge_index_entries":0"#));
24742484
assert!(body.contains(r#""memory_purge_index_max_entries":131072"#));
2485+
assert!(body.contains(r#""memory_purge_index_fill_ratio_per_mille":0"#));
24752486
assert!(body.contains(r#""disk_entries":0"#));
24762487
assert!(body.contains(r#""disk_fill_ratio_per_mille":0"#));
24772488
assert!(body.contains(r#""disk_purge_index_entries":0"#));
24782489
assert!(body.contains(r#""disk_purge_index_max_entries":65536"#));
2490+
assert!(body.contains(r#""disk_purge_index_fill_ratio_per_mille":0"#));
24792491
assert!(body.contains(
24802492
r#""activity":{"hits":0,"misses":0,"requests":0,"hit_ratio_per_mille":0,"stores":0,"store_refusals":0,"evictions":0,"purges":0"#
24812493
));
@@ -2486,6 +2498,7 @@ mod tests {
24862498
assert!(body.contains(r#""fill_ratio_per_mille":0"#));
24872499
assert!(body.contains(r#""purge_index_entries":0"#));
24882500
assert!(body.contains(r#""purge_index_max_entries":65536"#));
2501+
assert!(body.contains(r#""purge_index_fill_ratio_per_mille":0"#));
24892502
assert!(body.contains(r#""disk":{"entries":0"#));
24902503
assert!(body.contains(r#""routes":[{"name":"assets""#));
24912504

0 commit comments

Comments
 (0)