-
Notifications
You must be signed in to change notification settings - Fork 86
Add proxy-cache-registry-head-calls.md #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mxm-tr
wants to merge
2
commits into
goharbor:main
Choose a base branch
from
mxm-tr:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Proposal: Cache proxy-cache registry HEAD calls | ||
|
|
||
| Author: Maxime Hubert / @mxm-tr | ||
|
|
||
| Discussion: [Harbor Community Meeting - April 16th](https://hackmd.io/CyQk5FdVQwWObMLVNqxW1w?both#April-16-2025) | ||
|
|
||
| [Original issue](https://github.com/goharbor/harbor/issues/21859) | ||
|
|
||
| ## Abstract | ||
|
|
||
| Reduce the volume of HEAD requests by caching proxy cache ManifestExist calls. | ||
|
|
||
| ## Background | ||
|
|
||
| When pulling many artifacts at the same time on a proxy-cache project, we can still trigger the rate limiting on the upstream registries and get 429 Too Many Requests errors. | ||
|
|
||
| This is in part caused by HEAD requests being sent for each artifact pull. | ||
|
|
||
| ## Proposal | ||
|
|
||
| The solution could consist of a cache for calls to [HeadManifest](https://github.com/goharbor/harbor/blob/main/src/controller/proxy/controller.go#L258) | ||
|
|
||
| These cache entries can be valid for a fixed period of time, for a few seconds (10s) | ||
|
|
||
| ## Non-Goals | ||
|
|
||
| N/A | ||
|
|
||
| ## Rationale | ||
|
|
||
| The cache lifetime could be configurable via a parameter, but the current implementation has already some [hardcoded values](https://github.com/goharbor/harbor/blob/f8f1994c9ee97e41067870c4ed46b15eb21da3b6/src/controller/proxy/controller.go#L43), setting a fixed low value should be enough to not trigger rate-limiting on servers. | ||
|
|
||
| ## Compatibility | ||
|
|
||
| N/A | ||
|
|
||
| ## Implementation | ||
|
|
||
| 1. Use a new cache key in the [proxy controller cache](https://github.com/goharbor/harbor/blob/bfc29904f96e17248a4e6204d12058c1d7d05ab8/src/controller/proxy/controller.go#L78), such as: | ||
|
|
||
| ``` | ||
| cache:manifestexists:<repo>:<ref> | ||
| ``` | ||
|
|
||
| 2. Define its lifetime to a value that would prevent rate limiting from being triggered (10s?) in the [proxy-controller](https://github.com/goharbor/harbor/blob/bfc29904f96e17248a4e6204d12058c1d7d05ab8/src/controller/proxy/controller.go#L41-L48) | ||
|
|
||
| ```golang | ||
| manifestExistsCacheInterval = 10 * time.Second | ||
| ``` | ||
|
|
||
| 3. Before running [remote.ManifestExist](https://github.com/goharbor/harbor/blob/main/src/controller/proxy/controller.go#L258), run a cache fetch on the proxy controller cache. | ||
|
|
||
| If the cache is invalid or the key is not found, run remote.ManifestExist, and save a boolean in the proxy controller cache. | ||
|
|
||
| ## Open issues (if applicable) | ||
|
|
||
| https://github.com/goharbor/harbor/issues/21859 | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Maxime, by given such internal, there would be a a chance the client will pull different artifacts with the same binary from the source repo, if your pipeline is using this, you will have different testing results depending on when you run the tests. Such ambiguity will lead to difficulty when you trouble-shooting some issues. In my opinion, we should encourage the user to use sha digest instead of tag to reduce the API calling number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed the best practice is to use the sha digest, unfortunately some big open source projects (rancher for example) use hundreds of images from various origins and only allow the user to specify repository proxy urls, this proposal was made to ensure we don't send a HEAD request every time we pull an artifact.
The risk of pulling different artifacts using a tag exists indeed, maybe this behavior could be configurable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Maxime, I don't know how to make it configurable, but we should highlight to the users about the possibility of pulling different binaries in different time, thanks.