Repository navigation
Description
Goal
Surface cache hit/miss and bytes-from-cache as decdn_cache_* metrics so operators (and downstream features like decdn node top, #275) can reason about cache behaviour without log scraping.
Background
The cache crate (crates/cache/) currently emits zero metrics. The single read path is CacheEngine::get(&self, hash: Hash) -> CacheResult<Bytes> at crates/cache/src/engine.rs:663 — that's where hit vs. miss is decided and where Bytes flows back to the caller. Node-side metrics live in crates/node/src/metrics.rs (DecdnMetrics, registered against iroh_metrics::Registry).
This issue is a hard prerequisite for #275 (decdn node top), which assumes hit-rate is observable.
Scope
Add the following counters, all in the decdn_cache_* family per ADR 020 naming:
decdn_cache_hits_total— incremented whengetfinds the blob locally.decdn_cache_misses_total— incremented whengettriggers an origin pull-through (or returnsNotFoundif no origin is configured).decdn_cache_bytes_returned_total— bytes returned fromgetto the caller (bytes.len()on success).decdn_cache_pull_through_bytes_total— bytes fetched from origin during a miss. Independent signal frombytes_returned: useful for distinguishing 'serving from cache' vs. 'paying origin egress'.
Out of scope:
decdn_bytes_served_total(network-side bytes streamed to clients). Belongs in thecdn/client/v1serving handler tracked by Implement cdn/client/v1 paid delivery protocol (StreamRequest, StreamResponse, ChunkData, vouchers) #317; cache-side instrumentation is upstream of that and complementary, not a substitute.- Latency histograms / pull-through duration. Useful but separable; file as follow-up if wanted.
- Per-blob / per-origin breakdowns. Cardinality risk; defer.
Design sketch (not prescriptive)
The decdn/CLAUDE.md leaf-crate rule means decdn-cache must not depend on decdn-node. Two reasonable shapes:
- Cache owns its
MetricsGroup. Addiroh-metricstodecdn-cachedeps, definepub struct CacheMetricsin cache, and letnoderegister it viaRegistry::register— mirroring hownode::Metrics::register_iroh_endpointregisters iroh's own metrics today (crates/node/src/metrics.rs:110). Recommended. - Observer trait. Cache defines
trait CacheObserver { fn on_hit(...); fn on_miss(...); ... }; node provides an impl wired to its metrics. More indirection; useful only if a non-metrics observer also wants the events.
(1) is closer to the existing pattern and easier to test in isolation.
Test plan
- Unit test: open a
CacheEngine,puta blob, callgetfor present + absent hashes, assert hit/miss counters move correctly. The cache crate's existing tests inengine.rsalready cover the underlying behavior — these additions are pure observability. - Integration: ensure
noderegisters the cache metrics and they appear in/metricsoutput (extendcrates/node/tests/or admin tests).
Acceptance
- All four counters defined and exported from
decdn-cache. - Counters increment from inside
CacheEngine::getand the pull-through path; no caller (node, tests) needs to manually call them. -
decdn-noderegisters the cache metrics group; counters appear in/metricsoutput withdecdn_cache_prefix. - Tests cover hit, miss, and pull-through paths.
- No new dependency from
decdn-cacheondecdn-node(leaf-crate rule).
Refs: #275 (consumer), #317 (network-side bytes-served counter, separate concern).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
docs(cache): scope store-error carve-out by phase (#418 review)
feat(cache): hit/miss + bytes counters (#418) (#481)
fixup(cache): correct gc cycle-break docs + orphan ratio framing (#518)
feat(cache): wire iroh-blobs GC into runtime (#518) (#521)