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

Rate limit crane.Copy() operations #771

Merged
merged 5 commits into from
Mar 16, 2023

Conversation

puerco
Copy link
Member

@puerco puerco commented Mar 16, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR adds a new ratelimiter packaged based on geranos' roundtripper.

Based on it, we now rate limit the crane operations in the signature package to ensure
they are under the AR quotas set up by k8s infra.

Update: I've added the rate limit to the image promotion copy operations too.

(Thanks @BenTheElder ! )

Which issue(s) this PR fixes:

Part of kubernetes/release#2962

Special notes for your reviewer:

/cc @BenTheElder @xmudrii @palnabarun @ameukam

More context in this slack thread

Does this PR introduce a user-facing change?

Concurrent copy operations are now rate limited when promoting and replicating and mirroring signatures using a new `ratelimiter` package based on the [geranos rate limiter](https://github.com/kubernetes/registry.k8s.io/blob/main/cmd/geranos/ratelimitroundtrip.go) (Thanks @BenTheElder )

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Mar 16, 2023
@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 16, 2023
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 16, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: puerco

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added area/artifacts Issues or PRs related to the hosting of release artifacts for subprojects area/release-eng Issues or PRs related to the Release Engineering subproject approved Indicates a PR has been approved by an approver from all required OWNERS files. sig/release Categorizes an issue or PR as relevant to SIG Release. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 16, 2023
@puerco
Copy link
Member Author

puerco commented Mar 16, 2023

🤔
/test pull-cip-unit-tests

@@ -96,6 +103,7 @@ func (di *DefaultPromoterImplementation) CopySignatures(
) error {
// Cycle all signedEdges to copy them
logrus.Infof("Precopying %d previous signatures", len(signedEdges))
rtripper := ratelimit.NewRoundTripper(rateLimitEvents)
Copy link
Member

Choose a reason for hiding this comment

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

This object is thread safe, maybe a global until we can more easily plumb through a single shared instance? (So we can ensure the rate limit is maintained throughout)

Copy link
Member Author

Choose a reason for hiding this comment

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

I was just moving it to a global :) And also added the rate limiter to the promotion crane calls.

func (rt *RoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
// only rate limit read type calls, not writes
if r.Method == http.MethodGet || r.Method == http.MethodHead ||
r.Method == http.MethodPut || r.Method == http.MethodPost {
Copy link
Member

Choose a reason for hiding this comment

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

Put / Post should be write calls?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the comment but I was wondering if we should sniff at all 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Don't we only want to limit read calls? Put / Post should count as Write and have a different rate limit (none atm).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah gotcha I thought they had the same limit, reverted to the original.

Copy link
Member

Choose a reason for hiding this comment

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

aha. docs: https://cloud.google.com/artifact-registry/quotas

60000 requests per minute in each region or multi-region.
18000 write or delete requests per minute in each region or multi-region.

these are the shared baselines that can be raised by request (and we have raised some of them), then we have the per-user/per-ip read quota configured but not the per-user write quota (since kpromo should be the only thing performing writes/deletes anyhow)

Copy link
Member

Choose a reason for hiding this comment

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

kubernetes/registry.k8s.io#153 (comment)

Requests per project per user per minute per user
Write requests per project per user per minute per user

kubernetes/registry.k8s.io#153 (comment)

Requests per project per user per minute per user set to 5000.

@@ -46,6 +47,12 @@ const (
TestSigningAccount = "k8s-infra-promoter-test-signer@k8s-cip-test-prod.iam.gserviceaccount.com"
)

var rtripper *ratelimit.RoundTripper
Copy link
Member

Choose a reason for hiding this comment

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

Maybe move both to round trip package so there's a single process-scoped global?

most ideal would be instancing once and passing to everywhere but that may require breaking changes etc...

Copy link
Member

Choose a reason for hiding this comment

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

Unless the process authenticates with multiple accounts or something

Copy link
Member Author

Choose a reason for hiding this comment

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

OK I've moved them to a ratelimiter.Limiter global 👀

This commit adds a ratelimiter packaged based on
geranos' roundtripper:

https://github.com/kubernetes/registry.k8s.io/blob/main/cmd/geranos/ratelimitroundtrip.go

Signed-off-by: Adolfo García Veytia (Puerco) <puerco@chainguard.dev>
Calls to crane.Copy() when signing are now rate limited to
avoid hitting the AR quotas.

Signed-off-by: Adolfo García Veytia (Puerco) <puerco@chainguard.dev>
This commit uses the ratelimit package to limit the
rate copy operations at image promotion time.

Signed-off-by: Adolfo García Veytia (Puerco) <puerco@chainguard.dev>
This commit moves the default max events we feed
to the rate limiter to a constant in the package.

Signed-off-by: Adolfo García Veytia (Puerco) <puerco@chainguard.dev>
@puerco puerco force-pushed the roundtriper branch 2 times, most recently from 3d19ed7 to 0364542 Compare March 16, 2023 01:58
Signed-off-by: Adolfo García Veytia (Puerco) <puerco@chainguard.dev>
@puerco puerco changed the title Roundtriper Rate limit crane.Copy() operations Mar 16, 2023
Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

/lgtm

TODO: see if we can pass the crane transport (ratelimit.RoundTripper) around instead of global, but hopefully the global enables us to quickly integrate this everywhere in crane calls.

we went through that transition in geranos as well. quicker to get in place with the global, refactor later.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/artifacts Issues or PRs related to the hosting of release artifacts for subprojects area/release-eng Issues or PRs related to the Release Engineering subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/release Categorizes an issue or PR as relevant to SIG Release. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants