Skip to content
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

Add support for dockerhub rate-limiting #19984

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Grimm75
Copy link

@Grimm75 Grimm75 commented Feb 15, 2024

Add support for dockerhub API rate-limiting

Added function which wraps around client.Do() and:

  • pauses when rate-limit is hit (HTTP err:429) for time given in retry-after header.
  • checks the limit info from HTTP headers sent by API and will pause
    appropriately if rate-limit depletion is eminent.
  • max. 2 attempts are made in addition to initial one before giving up.

And replaced calls to client.Do() with wrapped one.

See:
https://docs.docker.com/docker-hub/api/latest/#tag/rate-limiting

PS: Above docs are incorrect about x-retry-after header - name and content doesn't match observed headers from dockerhub, which are retry-after (without x-) and content is positive integer - number of seconds to wait, conforming to RFC9110 10.2.3.

Issue being fixed

Fixes #19967

Please indicate you've done the following:

  • Well Written Title and Summary of the PR
  • Label the PR as needed. "release-note/ignore-for-release, release-note/new-feature, release-note/update, release-note/enhancement, release-note/community, release-note/breaking-change, release-note/docs, release-note/infra, release-note/deprecation"
  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Made sure tests are passing and test coverage is added if needed.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed in website repository.

@Grimm75 Grimm75 marked this pull request as ready for review February 15, 2024 14:16
@Grimm75 Grimm75 requested a review from a team as a code owner February 15, 2024 14:16
@Vad1mo Vad1mo added the release-note/enhancement Label to mark PR to be added under release notes as enhancement label Feb 16, 2024
@Vad1mo Vad1mo enabled auto-merge (squash) February 16, 2024 17:53
Copy link
Member

@Vad1mo Vad1mo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a great contribution. thank you very much.. We need to give it a test

auto-merge was automatically disabled February 16, 2024 19:17

Head branch was pushed to by a user without write access

@Grimm75
Copy link
Author

Grimm75 commented Feb 16, 2024

Thank you too, I just sqished some style related bugs, we'll see how it goes now.

@stonezdj stonezdj self-assigned this Feb 19, 2024
Copy link
Author

@Grimm75 Grimm75 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed/explained in Fix: review - ... commits.

src/pkg/reg/adapter/dockerhub/adapter.go Outdated Show resolved Hide resolved
src/pkg/reg/adapter/dockerhub/adapter.go Outdated Show resolved Hide resolved
@Grimm75 Grimm75 force-pushed the main branch 2 times, most recently from bd59e2d to 55be54b Compare February 26, 2024 16:25
@Grimm75 Grimm75 requested review from Vad1mo and microyahoo February 26, 2024 16:35
@Grimm75 Grimm75 force-pushed the main branch 3 times, most recently from cc483a2 to b443030 Compare March 1, 2024 22:46
@MinerYang
Copy link
Contributor

  • add retry will increase your request to docker which actually would increase your risk of having rate limit error.
  • response time will hang in there

@Grimm75 Grimm75 force-pushed the main branch 2 times, most recently from 701420e to 43f6e95 Compare March 4, 2024 13:51
@Grimm75
Copy link
Author

Grimm75 commented Mar 4, 2024

  • add retry will increase your request to docker which actually would increase your risk of having rate limit error.
  • response time will hang in there

Fixed, 'retry' is now used ONLY when last response was 429 and we waited.

@wy65701436
Copy link
Contributor

From the perspective of Harbor core, adding retry would result in more GET or HEAD requests to the upstream Docker registry, potentially increasing the chances of hitting rate limits.

Personally, I believe it's better to fail early and inform the client of the failure ASAP. This allows the client to decide whether to implement retry on their end. Hiding the retry functionality on the server side would inevitably increase response time, which could lead to timeouts for some clients. This approach doesn't seem practical to me.

@MinerYang MinerYang self-assigned this Mar 12, 2024
@Grimm75 Grimm75 force-pushed the main branch 5 times, most recently from d1a4f00 to 4ee91bf Compare March 18, 2024 12:58
@Grimm75 Grimm75 force-pushed the main branch 3 times, most recently from d366a14 to 5e8ecfc Compare March 31, 2024 19:09
@Grimm75
Copy link
Author

Grimm75 commented Apr 8, 2024

Is there anybody to help me with this PR?

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

Attention: Patch coverage is 27.27273% with 32 lines in your changes missing coverage. Please review.

Project coverage is 66.22%. Comparing base (b7b8847) to head (ed0bbf0).
Report is 216 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #19984      +/-   ##
==========================================
- Coverage   67.56%   66.22%   -1.34%     
==========================================
  Files         991     1045      +54     
  Lines      109181   113531    +4350     
  Branches     2719     2845     +126     
==========================================
+ Hits        73768    75188    +1420     
- Misses      31449    34234    +2785     
- Partials     3964     4109     +145     
Flag Coverage Δ
unittests 66.22% <27.27%> (-1.34%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/pkg/reg/adapter/dockerhub/adapter.go 30.50% <27.27%> (-0.47%) ⬇️

... and 571 files with indirect coverage changes

@Vad1mo
Copy link
Member

Vad1mo commented Apr 9, 2024

@wy65701436 can we get some indication for @Grimm75 in what direction to move?

Copy link

github-actions bot commented Jun 9, 2024

This PR is being marked stale due to a period of inactivty. If this PR is still relevant, please comment or remove the stale label. Otherwise, this PR will close in 30 days.

@github-actions github-actions bot added the Stale label Jun 9, 2024
@OrlinVasilev
Copy link
Member

Hey @wy65701436 @stonezdj can you check that please!

@Vad1mo Vad1mo added the never-stale Do not stale label Jun 10, 2024
@Vad1mo Vad1mo enabled auto-merge (squash) June 12, 2024 07:38
@Vad1mo
Copy link
Member

Vad1mo commented Jun 12, 2024

@Grimm75, we are ready to go. Can you add a test to your function, to bump up the codecov?

// - Allows 2 more attempts before giving up.
// Reason: Observed (02/2024) penalty for hitting the limit is 120s, normal reset is 60s,
// so it is better to not hit the wall.
func (a *adapter) limitAwareDo(method string, path string, body io.Reader) (*http.Response, error) {
Copy link
Member

@Vad1mo Vad1mo Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The PR is not complete yet, as there are some missing test cases and the low test coverage. It is blocked from merging.
  • In addition, I find there is too much logging into info, We can put all in debug, especially since we now can handle the rate limit there is nothing to info about.
  • I would allow one info statement, when we reach/hit the limit. Other information is relevant for debut only.

@wy65701436
Copy link
Contributor

I believe we should avoid implementing hidden retry logic on the server side, and I’ve shared my personal opinion on this matter.

@Vad1mo @OrlinVasilev We can discuss this in the community meeting if you think it's necessary.

Personally, I believe it's better to fail early and inform the client of the failure ASAP. This allows the client to decide whether to implement retry on their end. Hiding the retry functionality on the server side would inevitably increase response time, which could lead to timeouts for some clients. This approach doesn't seem practical to me.

@wy65701436 wy65701436 removed the release-note/enhancement Label to mark PR to be added under release notes as enhancement label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
never-stale Do not stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dockerhub replication: 429 Rate limit exceeded on project with lots of tags
9 participants