Repository navigation
Conversation
CachedImage returns a digest-pinned image that is complete in the store without contacting the registry, and nil otherwise. A caller can then serve such images locally and send the rest elsewhere.
| img, err := s.cachedImageHit(digest) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if img != nil { | ||
| s.recordRequest(ctx, ateattr.ImageCacheOutcomeHit, nil) | ||
| slog.InfoContext(ctx, "Image cache hit", slog.String("ref", ref), slog.String("digest", digest.String())) |
There was a problem hiding this comment.
On the error path this returns without recordRequest, and in #4028 the caller returns that error directly, so EnsureImage never counts it either. Should this record the error outcome? A miss that the plugin then serves is also never counted, is that intended for the hit ratio?
There was a problem hiding this comment.
Yes, the error path was a bug. CachedImage now records it, so atelet's early return is counted. The uncounted miss is intended: if the plugin declines, EnsureImage counts the miss, so counting it here would count it twice. A plugin-served image causes no pull, so it isn't a cache miss. It shows in ate.imageprovider.requests. I documented this in the CachedImage comment and both registry notes.
| // complete on disk, with no network I/O. It returns (nil, nil) on a miss and | ||
| // for refs that are not digest-pinned or do not parse, so the caller can fall | ||
| // back to EnsureImage, which reports the parse error. | ||
| func (s *Store) CachedImage(ctx context.Context, ref string) (*Image, error) { |
There was a problem hiding this comment.
This repeats EnsureImage's digest-parse and hit path. Have you considered a shared helper so the logging and metric handling can't drift between the two?
There was a problem hiding this comment.
Done. pinnedDigest and lookup are shared, so the digest parse, the hit check and the hit log are in one place. Each caller still calls recordRequest, because EnsureImage counts misses and CachedImage doesn't.
CachedImage now records a failed lookup. A miss is still not counted, because the caller counts it or gets the image without a pull. pinnedDigest and lookup are shared with EnsureImage.
Part of #4023.
CachedImage returns a digest ref's image when the cache holds all of it, without a registry call, and nil otherwise. atelet uses it in #4028 to serve cached images before asking the plugin.
CachedImage counts its hits and failures in ate.imagecache.requests, but not its misses. The caller then either pulls through EnsureImage, which counts the miss, or gets the image without a pull. CachedImage and EnsureImage share the digest parse, the hit check and the hit log.
Testing: new table rows in TestCachedImage, including a corrupt record, which check what each lookup counts. go test -race ./internal/imagecache/....
I used an AI agent to port this commit from our fork, address review comments, and draft this description. I reviewed the code and commit message.