Repository navigation
feat(cache): hit/miss + bytes counters (#418) - #481
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…418) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…oder (#418) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…otal (#418) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Critical: relax the `misses` docstring's absolute hits-XOR-misses claim. Store I/O errors (`CacheError::Store`) propagate from `CacheEngine::get` via `?` on `has`/`read_local` without bumping either counter, which is the right call (storage failures are infrastructure events, not cache outcomes — conflating them would pollute hit-rate dashboards). Hoist the contract to the module-level doc and weaken per-field claims to match. Coverage: extend `concurrent_gets_coalesce_into_single_origin_fetch` to assert `1 miss + 4 hits` under coalescing — locks the waiter-retry hit increment that was previously asserted only by inspection. Test robustness: introduce `has_metric_line` line-anchored matcher for OpenMetrics output so `decdn_cache_hits_total 1` cannot accidentally substring-match a future `..._foo` series or `_created` companion. Tighten `hits_plus_misses_equals_total_gets` with a `pull_through_bytes` assertion so a stray bump in either error arm fails. Doc polish: drop the variant-name enumeration from `misses` (rot risk), drop the internal-Rust-type leakage (`OriginFetch::Found`) from the ADR row, and refresh the BLAKE3-rejection comment to reflect that `retry_fetch` already enforces `max_blob_bytes` upstream. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces four new cache metrics—hits, misses, bytes_returned_total, and pull_through_bytes_total—to the decdn_cache family, aligning with the observability ADR. The changes include logic in CacheEngine to track these metrics during cache hits, misses, and origin pull-throughs, supported by extensive integration tests. Feedback indicates that the misses counter is currently incremented at the start of the pull_through function, which could lead to incorrect accounting if a Store error occurs later; the reviewer suggests ensuring Store errors are excluded from hit/miss metrics as per the stated policy. Corresponding documentation updates are also recommended to clarify this behavior.
Coverage reportTotal: 87.90% (was 87.72%, ▲ +0.18%) — 11851/13483 lines
History
|
There was a problem hiding this comment.
Pull request overview
Adds cache-level observability to help operators (and future decdn node top) reason about cache behavior via OpenMetrics decdn_cache_* counters, including hit/miss and byte accounting.
Changes:
- Introduces
hits,misses,bytes_returned, andpull_through_bytescounters toCacheMetricsand documents their accounting contract. - Wires counter bumps into
CacheEngine::get(hit path + coalesced waiter-hit) andpull_through(miss + origin-bytes). - Expands cache/unit + node/metrics integration tests to assert correct counter behavior and exact OpenMetrics line rendering.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/node/src/metrics.rs | Strengthens metrics tests with exact-line matching and adds an integration test that drives a real CacheEngine and asserts rendered cache counters. |
| crates/cache/src/metrics.rs | Adds four new cache counters with module-level documentation describing intended semantics and invariants. |
| crates/cache/src/engine.rs | Increments new counters on hit/miss paths and on origin-byte receipt; extends existing tests and adds new ones for accounting invariants. |
| adr/appendix-observability.md | Documents the two new cache byte counters in the observability appendix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The previous module-level doc claimed Store I/O errors propagate without bumping either counter — too broad. Hit/miss accounting only applies to the local-lookup phase (`has`, `read_local`); a Store error there leaves the call genuinely unclassifiable so neither counter moves. Once `pull_through` is entered the miss is already determined and origin egress may have already been paid, so a downstream Store error (e.g. `add_bytes` failure) leaves the earlier `misses` / `pull_through_bytes` bumps in place — operators tracking origin spend need those events counted, not silently dropped. Also drop "peer" from the `hits` doc — coalescing is between in-process concurrent tasks, not network peers (per #481 review). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Closes #418. Adds four
decdn_cache_*counters so operators (and #275decdn node top) can reason about cache behaviour without log scraping:decdn_cache_hits_total—get()calls served from the local store (first-attempt + waiter-retry hits).decdn_cache_misses_total— bumped once at everypull_throughentry and once on every operator-evictedNotFound. Storage I/O failures (CacheError::Store) propagate without bumping either counter so hit-rate dashboards aren't polluted by infrastructure failures (see module-level doc incrates/cache/src/metrics.rs).decdn_cache_bytes_returned_total— bytes returned fromget()on success (cache-hit + pull-through-success paths).decdn_cache_pull_through_bytes_total— bytes received from origin during a miss, counted before BLAKE3 verification / size-cap re-check (origin egress is paid the moment bytes arrive).ADR
appendix-observability.md§2.3 already listedhits_total/misses_totalas Mandatory; this PR also registers the two new byte counters there. Wiring is purely additive — the cache crate already ownedCacheMetrics, the engine already acceptedOption<Arc<CacheMetrics>>viaopen_full, andruntime::build_cachealready passesnode_metrics.cache_metrics()through. No new deps;decdn-cache → decdn-nodedirection preserved.Test plan
crates/cache/src/engine.rs::testscover hit, evicted, no-origin, pull-through-bytes, pull-through-bytes-returned, and the hits/misses accounting invariant.concurrent_gets_coalesce_into_single_origin_fetchextended to assert1 miss + 4 hitsunder 5 concurrent gets — locks the waiter-retry-hit increment.crates/node/src/metrics.rsintegration test drives a realCacheEngineand asserts the rendered OpenMetrics output, with a line-anchored matcher (has_metric_line) so substring collisions can't pass silently.cargo nextest run— 672/672 tests pass.cargo clippy --workspace --all-targets -- -D warningsclean.cargo fmt -- --checkclean.Notes
The
missescounter docstring deliberately doesn't claim a strict hits-XOR-misses invariant: storage I/O errors propagate via?without bumping either counter, by design. The contract and reasoning are documented at the module level incrates/cache/src/metrics.rs.🤖 Generated with Claude Code