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

api: sharing global ratelimit buckets #5227

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

Conversation

ryanhristovski
Copy link
Contributor

@ryanhristovski ryanhristovski commented Feb 6, 2025

Related to #5194 (comment)

Currently using shared: bool for setting a global rate limiting rule, another option discussed was scope: gateway/httproute.

Does anyone have a strong opinion on how rate limit policies should be labeled to have a global scope?

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.00%. Comparing base (22eb14f) to head (ec32888).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5227      +/-   ##
==========================================
+ Coverage   67.94%   68.00%   +0.05%     
==========================================
  Files         214      214              
  Lines       33532    33532              
==========================================
+ Hits        22782    22802      +20     
+ Misses       9360     9345      -15     
+ Partials     1390     1385       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@arkodg arkodg changed the title API PR, shared vs scope api: sharing global ratelimit buckets Feb 10, 2025
@arkodg
Copy link
Contributor

arkodg commented Feb 10, 2025

added some comments, but overall +1 with the feature
ptal @envoyproxy/gateway-maintainers

the implementation will be tricky, since we cannot rely on per route based keys and descriptors, and find a way to share it, one idea is to create a key prefix in the gateway api layer and use it in the xds layer if its set

@ryanhristovski ryanhristovski marked this pull request as ready for review February 12, 2025 16:16
@ryanhristovski ryanhristovski requested a review from a team as a code owner February 12, 2025 16:16
@ryanhristovski
Copy link
Contributor Author

/retest

ryanhristovski and others added 17 commits February 12, 2025 13:17
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
Signed-off-by: Ryan Hristovski <[email protected]>
* build(deps): bump github.com/envoyproxy/go-control-plane/contrib

Bumps [github.com/envoyproxy/go-control-plane/contrib](https://github.com/envoyproxy/go-control-plane) from 1.32.3 to 1.32.4.
- [Release notes](https://github.com/envoyproxy/go-control-plane/releases)
- [Changelog](https://github.com/envoyproxy/go-control-plane/blob/main/CHANGELOG.md)
- [Commits](envoyproxy/go-control-plane@envoy/v1.32.3...envoy/v1.32.4)

---
updated-dependencies:
- dependency-name: github.com/envoyproxy/go-control-plane/contrib
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* build(deps): bump github.com/spf13/pflag from 1.0.5 to 1.0.6

Bumps [github.com/spf13/pflag](https://github.com/spf13/pflag) from 1.0.5 to 1.0.6.
- [Release notes](https://github.com/spf13/pflag/releases)
- [Commits](spf13/pflag@v1.0.5...v1.0.6)

---
updated-dependencies:
- dependency-name: github.com/spf13/pflag
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix gen

Signed-off-by: zirain <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: zirain <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Ryan Hristovski <[email protected]>
@ryanhristovski ryanhristovski force-pushed the feat-global-gateway-ratelimitting branch from ba808e1 to 29b72b7 Compare February 12, 2025 18:17
@ryanhristovski
Copy link
Contributor Author

/retest

@ryanhristovski
Copy link
Contributor Author

@arkodg i fixed a test in this PR unrelated to my changes

Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM thanks !

@arkodg arkodg requested review from a team February 12, 2025 19:49
// +optional
// +notImplementedHide
// +kubebuilder:default=false
Shared *bool `json:"shared,omitempty"`
Copy link
Collaborator

@sanposhiho sanposhiho Feb 14, 2025

Choose a reason for hiding this comment

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

Using bool is not recommended generally speaking..
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#primitive-types

Any strong reason for that? Can we consider enum instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for linking that @sanposhiho , it does say to think twice before using bool, mainly because intent/field could be multidimensional in the future (which enums like type really come in handy).
the intent here is to say that this ratelimit bucket is a singleton or is shared across all targets, can recommendations for enums here ?

Copy link
Collaborator

@sanposhiho sanposhiho Feb 16, 2025

Choose a reason for hiding this comment

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

You can make a final decision based on other API designs in EG, but, at k/k (around me), we've mostly (or probably always) used enum for new APIs even if we first thought it was a two-value switching and likely won't get changed in the future when we designed them. So, if you ask me, I'd probably change it to enum and change the name from Shared. (some general name, like ApplyPolicy etc)

Copy link
Contributor

Choose a reason for hiding this comment

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

I like @rudrakhp's suggestion #5227 (comment)

// +optional
// +notImplementedHide
// +kubebuilder:default=false
Shared *bool `json:"shared,omitempty"`
Copy link
Member

@rudrakhp rudrakhp Feb 16, 2025

Choose a reason for hiding this comment

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

Suggested change
Shared *bool `json:"shared,omitempty"`
BucketScope RateLimitBucketScope `json:"bucketScope,omitempty"`

You can define enums:

type RateLimitBucketScope string

const (
	SharedBucketScope    RateLimitBucketScope = "shared"    // Shared across routes
	PerRouteBucketScope  RateLimitBucketScope = "perRoute" // Independent for each route, default
)

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to future proof this API for other scopes (e.g. vhost?)

Copy link
Contributor

Choose a reason for hiding this comment

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

prefer just scope
and instead of perRoute it may help to define it as perTarget

Copy link
Member

Choose a reason for hiding this comment

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

Just scope might be confusing with the rate limit scope, i.e, Global/Local. But I guess that could be clarified in the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could see the confusion with scope being confused with type (Global/Local), bucketScope could provide more clarity. Also agree with @arkodg for perTarget rather than perRoute.

I'll push through whichever changes we agree upon here

Copy link
Contributor

Choose a reason for hiding this comment

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

i was trying to avoid the bucket prefix, because i was unsure if it should be bucket, rule (which is an existing noun in the API) or somethingElse
we can brainstorm a little more here

Copy link
Member

@rudrakhp rudrakhp Feb 19, 2025

Choose a reason for hiding this comment

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

How about "context" (values are shared, target, vHost, etc)? I am ok with "scope" as well since it's explicitly defined under GlobalRateLimit API, just that context feels less confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

though i see the potential confusion, scope: shared/target/vHost does seem most clear

can the vHost option be added in another patch? was hoping to just focus on shared/target

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah we can't add vHost yet, because that noun doesn't exist in any user facing docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants