Skip to content

feat(metrics): record compression cache hits and misses - #2486

Merged
coreydaley-cg merged 1 commit into
mainfrom
coreydaley/compression-cache-metrics
Sep 9, 2026
Merged

feat(metrics): record compression cache hits and misses#2486
coreydaley-cg merged 1 commit into
mainfrom
coreydaley/compression-cache-metrics

Conversation

@coreydaley-cg

Copy link
Copy Markdown
Contributor

Adds compression as a third cache on the existing apko_cache_accesses_total{cache,result} counter, so the diffID to descriptor cache's hit rate can be measured in a real deployment.

Context is #2485. That cache is the reason layer writes are two-pass — deferring compression requires a materialized plain tar to defer against — and whether the trade pays depends on how often the same diffID recurs inside one process. That has never been measured, and local approximation is not convincing for a heavily scaled service where the cache is per-process and builds are spread across many instances.

Notes

Nothing to do on the consumer side. Callers that already run metrics.Register(...) pick up the new label value with no change.

Only the first lookup per layer is recorded. compress() short-circuits once l.compressed != "", so the Digest() then Size() second lookup on the same layer costs nothing whether it hits or misses. Counting it would roughly double the apparent hit rate and overstate what the cache saves. A hit here means a layer genuinely avoided being compressed.

No bypass result. The compression cache is always consulted, so unlike the index and resolver caches there is no bypass path, and pre-initialising one would create a series that can never be non-zero.

Testing

TestCacheAccesses extended to cover the new cache. Full pkg/... suite passes.

The diffID to descriptor cache is the reason layer writes are two-pass:
deferring compression needs a materialized plain tar to defer against.
Whether that trade pays depends on how often the same diffID recurs
within a single process, which has never been measured.

This adds "compression" as a third cache on the existing
apko_cache_accesses_total{cache,result} counter, so consumers already
registering apko's collector pick up the hit rate without any change on
their side.

Only the first lookup per layer is recorded. compress() short-circuits
once a layer has been compressed, so the Digest() then Size() second
lookup on the same layer is free whether it hits or misses, and counting
it would overstate what the cache actually saves. The compression cache
is always consulted, so unlike the index and resolver caches it has no
bypass result.

Co-authored-by: Claude <noreply@anthropic.com>
@coreydaley-cg
coreydaley-cg enabled auto-merge (squash) September 9, 2026 17:01
@coreydaley-cg
coreydaley-cg merged commit 9e66cfb into main Sep 9, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants