feat(metrics): record compression cache hits and misses - #2486
Merged
Conversation
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
enabled auto-merge (squash)
September 9, 2026 17:01
kevinmdavis
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
compressionas a third cache on the existingapko_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 oncel.compressed != "", so theDigest()thenSize()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
bypassresult. 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
TestCacheAccessesextended to cover the new cache. Fullpkg/...suite passes.