Skip to content

Commit 3219209

Browse files
committed
Report indexed cache purge tier ratios
1 parent 8f066fc commit 3219209

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ behavior when the change improves security or project direction.
6767
operators can quickly see how much of a requested purge batch matched.
6868
- Protected bulk cache purge responses now also echo the selected `route` and
6969
cache `scope`, matching single and indexed purge responses.
70+
- Protected indexed cache purge responses now include per-tier
71+
`memory_purged_ratio_per_mille` and `disk_purged_ratio_per_mille` fields.
7072
- `server.default_vhost` validation now hints at `include_conf_d = true` or
7173
directory-based config loading when the named vhost is not loaded.
7274
- Cache policies can now set `stale_if_error_secs` to permit serving stale

docs/cache-backends.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ internal cache implementation.
207207
`x-fluxheim-cache-limit`, default to a bounded batch size, and return
208208
the effective `limit`, cache `scope`, and `purged_ratio_per_mille` in their
209209
response. The ratio reports how much of the matched batch was actually
210-
purged, where `1000` means every matched entry was removed. They return
210+
purged, where `1000` means every matched entry was removed. Indexed purge
211+
responses also include `memory_purged_ratio_per_mille` and
212+
`disk_purged_ratio_per_mille` so operators can see which tier needs cleanup.
213+
They return
211214
`truncated = true` and `repeat_required = true` when more indexed entries
212215
remain for the requested scope and the same purge should be run again. The
213216
index is bounded in memory, mirrors disk-tier writes, and is designed for

src/admin.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ impl AdminApp {
668668
}) {
669669
Ok(result) => {
670670
let body = format!(
671-
r#"{{"status":"ok","matched":{},"purged":{},"purged_ratio_per_mille":{},"truncated":{},"repeat_required":{},"limit":{},"vhost":"{}","route":{},"scope":"{}","memory_matched":{},"memory_purged":{},"memory_truncated":{},"disk_matched":{},"disk_purged":{},"disk_truncated":{}}}"#,
671+
r#"{{"status":"ok","matched":{},"purged":{},"purged_ratio_per_mille":{},"truncated":{},"repeat_required":{},"limit":{},"vhost":"{}","route":{},"scope":"{}","memory_matched":{},"memory_purged":{},"memory_purged_ratio_per_mille":{},"memory_truncated":{},"disk_matched":{},"disk_purged":{},"disk_purged_ratio_per_mille":{},"disk_truncated":{}}}"#,
672672
result.matched(),
673673
result.purged(),
674674
ratio_per_mille_usize(result.purged(), result.matched()),
@@ -680,9 +680,11 @@ impl AdminApp {
680680
cache_scope(result.route.as_deref()),
681681
result.memory_matched,
682682
result.memory_purged,
683+
ratio_per_mille_usize(result.memory_purged, result.memory_matched),
683684
result.memory_truncated,
684685
result.disk_matched,
685686
result.disk_purged,
687+
ratio_per_mille_usize(result.disk_purged, result.disk_matched),
686688
result.disk_truncated
687689
);
688690
json_response(StatusCode::OK, body.as_bytes())
@@ -730,7 +732,7 @@ impl AdminApp {
730732
) {
731733
Ok(result) => {
732734
let body = format!(
733-
r#"{{"status":"ok","matched":{},"purged":{},"purged_ratio_per_mille":{},"truncated":{},"repeat_required":{},"limit":{},"vhost":"{}","route":{},"scope":"{}","path_prefix":"{}","memory_matched":{},"memory_purged":{},"memory_truncated":{},"disk_matched":{},"disk_purged":{},"disk_truncated":{}}}"#,
735+
r#"{{"status":"ok","matched":{},"purged":{},"purged_ratio_per_mille":{},"truncated":{},"repeat_required":{},"limit":{},"vhost":"{}","route":{},"scope":"{}","path_prefix":"{}","memory_matched":{},"memory_purged":{},"memory_purged_ratio_per_mille":{},"memory_truncated":{},"disk_matched":{},"disk_purged":{},"disk_purged_ratio_per_mille":{},"disk_truncated":{}}}"#,
734736
result.matched(),
735737
result.purged(),
736738
ratio_per_mille_usize(result.purged(), result.matched()),
@@ -743,9 +745,11 @@ impl AdminApp {
743745
json_escape(path_prefix),
744746
result.memory_matched,
745747
result.memory_purged,
748+
ratio_per_mille_usize(result.memory_purged, result.memory_matched),
746749
result.memory_truncated,
747750
result.disk_matched,
748751
result.disk_purged,
752+
ratio_per_mille_usize(result.disk_purged, result.disk_matched),
749753
result.disk_truncated
750754
);
751755
json_response(StatusCode::OK, body.as_bytes())
@@ -793,7 +797,7 @@ impl AdminApp {
793797
) {
794798
Ok(result) => {
795799
let body = format!(
796-
r#"{{"status":"ok","matched":{},"purged":{},"purged_ratio_per_mille":{},"truncated":{},"repeat_required":{},"limit":{},"vhost":"{}","route":{},"scope":"{}","path_pattern":"{}","memory_matched":{},"memory_purged":{},"memory_truncated":{},"disk_matched":{},"disk_purged":{},"disk_truncated":{}}}"#,
800+
r#"{{"status":"ok","matched":{},"purged":{},"purged_ratio_per_mille":{},"truncated":{},"repeat_required":{},"limit":{},"vhost":"{}","route":{},"scope":"{}","path_pattern":"{}","memory_matched":{},"memory_purged":{},"memory_purged_ratio_per_mille":{},"memory_truncated":{},"disk_matched":{},"disk_purged":{},"disk_purged_ratio_per_mille":{},"disk_truncated":{}}}"#,
797801
result.matched(),
798802
result.purged(),
799803
ratio_per_mille_usize(result.purged(), result.matched()),
@@ -806,9 +810,11 @@ impl AdminApp {
806810
json_escape(path_pattern),
807811
result.memory_matched,
808812
result.memory_purged,
813+
ratio_per_mille_usize(result.memory_purged, result.memory_matched),
809814
result.memory_truncated,
810815
result.disk_matched,
811816
result.disk_purged,
817+
ratio_per_mille_usize(result.disk_purged, result.disk_matched),
812818
result.disk_truncated
813819
);
814820
json_response(StatusCode::OK, body.as_bytes())
@@ -2305,6 +2311,8 @@ mod tests {
23052311
assert!(body.contains(r#""matched":0"#));
23062312
assert!(body.contains(r#""purged":0"#));
23072313
assert!(body.contains(r#""purged_ratio_per_mille":0"#));
2314+
assert!(body.contains(r#""memory_purged_ratio_per_mille":0"#));
2315+
assert!(body.contains(r#""disk_purged_ratio_per_mille":0"#));
23082316
assert!(body.contains(r#""truncated":false"#));
23092317
assert!(body.contains(r#""repeat_required":false"#));
23102318
assert!(body.contains(r#""limit":16"#));
@@ -2353,6 +2361,8 @@ mod tests {
23532361
assert!(body.contains(r#""path_prefix":"/assets/""#));
23542362
assert!(body.contains(r#""matched":0"#));
23552363
assert!(body.contains(r#""purged_ratio_per_mille":0"#));
2364+
assert!(body.contains(r#""memory_purged_ratio_per_mille":0"#));
2365+
assert!(body.contains(r#""disk_purged_ratio_per_mille":0"#));
23562366
assert!(body.contains(r#""repeat_required":false"#));
23572367
assert!(body.contains(r#""limit":16"#));
23582368
assert!(body.contains(r#""scope":"vhost""#));
@@ -2413,6 +2423,8 @@ mod tests {
24132423
assert!(body.contains(r#""path_pattern":"/assets/*.png""#));
24142424
assert!(body.contains(r#""matched":0"#));
24152425
assert!(body.contains(r#""purged_ratio_per_mille":0"#));
2426+
assert!(body.contains(r#""memory_purged_ratio_per_mille":0"#));
2427+
assert!(body.contains(r#""disk_purged_ratio_per_mille":0"#));
24162428
assert!(body.contains(r#""repeat_required":false"#));
24172429
assert!(body.contains(r#""limit":16"#));
24182430
assert!(body.contains(r#""scope":"vhost""#));

0 commit comments

Comments
 (0)