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

ratelimit: support per-descriptor hits_addend #37361

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

agrawroh
Copy link
Contributor

@agrawroh agrawroh commented Nov 26, 2024

Description

We can now provide multiple descriptor(s) in the same RateLimit request, but they all share same hits_addend. If we want to limit the QPS and bandwidth at same time, we need to configure two rate limit filters in the same filter chain. It's a little complex and add additional overhead/latency.

In this PR, we are exposing hits_addend at the per-descriptor level which could be overridden to achieve the behavior described above.

Fixes #37347


Commit Message: ratelimit: support per-descriptor hits_addend
Additional Description: This PR exposes hits_addend at the per-descriptor level which could be overridden to achieve the behavior described above.
Risk Level: Low
Testing: Added Unit Tests
Docs Changes: Added
Release Notes: Added

Copy link

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #37361 was opened by agrawroh.

see: more, trace.

Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy[\w/]*/(v1alpha\d?|v1|v2alpha\d?|v2))|(api/envoy/type/(matcher/)?\w+.proto).
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @wbpcode
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #37361 was opened by agrawroh.

see: more, trace.

Comment on lines +66 to +74

// A per-descriptor override for the number of hits added to the matched limit by a request.
// This value takes precedence over the globally configured value. If neither this field nor
// the global value is set, the matched limit is incremented by 1 for each request.
//
// Additionally, this value can be overridden by setting the filter state value
// `envoy.ratelimit.hits_addend` to the desired number. If an invalid number (e.g., < 0) is
// provided, it will be ignored.
uint32 hits_addend = 3;
Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't change the v2 proto API.

Comment on lines +106 to +114

// A per-descriptor override for the number of hits added to the matched limit by a request.
// This value takes precedence over the globally configured value. If neither this field nor
// the global value is set, the matched limit is incremented by 1 for each request.
//
// Additionally, this value can be overridden by setting the filter state value
// `envoy.ratelimit.hits_addend` to the desired number. If an invalid number (e.g., < 0) is
// provided, it will be ignored.
uint32 hits_addend = 3;
Copy link
Member

Choose a reason for hiding this comment

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

This should be part of RateLimitDescriptor, rather than part of single Entry.

}
template <typename H>
friend H AbslHashValue(H h, // NOLINT(readability-identifier-naming)
const DescriptorEntry& entry) {
return H::combine(std::move(h), entry.key_, entry.value_);
return H::combine(std::move(h), entry.key_, entry.value_, entry.hits_addend_);
Copy link
Member

Choose a reason for hiding this comment

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

I think hits_addend shouldn't be used to compute the hash or be used to compare the entry.

@wbpcode
Copy link
Member

wbpcode commented Nov 26, 2024

Thanks for the contribution. Before going to deeper review/work, I think it would be better to let other maintainer check the requirement first to see if it's reasonable or not.

cc @mattklein123

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

Successfully merging this pull request may close these issues.

per descriptor hits_addend support
2 participants