-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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: new per descriptor hits-addend support and dynamic hits addend #37567
base: main
Are you sure you want to change the base?
ratelimit: new per descriptor hits-addend support and dynamic hits addend #37567
Conversation
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
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.
@wbpcode should we add the implementation using this API to the PR so we can see how it'll be used?
// For example, the ``%BYTES_RECEIVED%`` format string will be replaced with the number of bytes | ||
// received in the request. | ||
// | ||
// Only one of the ``number`` or ``format`` fields can be set. |
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.
what will happen if both are set?
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.
This is oneof semantics. (although oneof is not recommend according to our style).
If both are set, the configuration will be rejected.
// Optional hits_addend for the rate limit descriptor. If set the value will override the | ||
// request level hits_addend. | ||
// [#not-implemented-hide:] | ||
google.protobuf.UInt32Value hits_addend = 3; |
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.
In the request level, it can be an integer or a format string. How come here it is only an integer?
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.
The format string is used to extract a number based on the request and stream info. See the comments of format
string comment
// Substitution format string to extract the number of hits to add to the rate limit descriptor.
// The same :ref:`format specifier <config_access_log_format>` as used for
// :ref:`HTTP access logging <config_access_log>` applies here.
//
// .. note::
// The format string must contain only single valid substitution field that will be replaced
// with a non-negative number.
//
// For example, the ``%BYTES_RECEIVED%`` format string will be replaced with the number of bytes
// received in the request.
SGTM. |
cc @abeyad I complete the local ratelimit version of the per descriptor custom hits addend support. When the request is coming, we will generated a list of descriptors based on the configuration. If the When a descriptor matchs a rule, in the previous implementation, the fixed value 1 will be used as hits addend. Now, in the new implementation, the custom |
envoy/ratelimit/ratelimit.h
Outdated
/** | ||
* A single rate limit request descriptor. See ratelimit.proto. | ||
* This is generated from the request based on the configured rate limit actions. | ||
*/ | ||
struct Descriptor : public DescriptorBase { | ||
absl::optional<RateLimitOverride> limit_ = absl::nullopt; | ||
absl::optional<uint32_t> hits_addend_ = absl::nullopt; | ||
}; | ||
|
||
using LocalDescriptor = DescriptorBase; |
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.
In the previous implementation, the class LocalDescriptor
has two usages:
- as the key of rate limit rules that every descriptor is related to a token bucket.
- as the output of the descriptor populating of local rate limt filter. It will be used to find a matched rate limit rule.
But now, to support per descriptor hits_addend
, we need a new class to represent the output of the descriptor populating. Finally, we choose to enhance and re-use the Descriptor
class. (The Descriptor
class is used as the output of global rate limit filter. Re-using it could also simplify future development when we want to add similar support for global rate limit filter in the future.)
2e2b2c3
to
dc93699
Compare
/retest |
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.
/lgtm api
Override limit = 4; | ||
|
||
// An optional hits addend to be appended to the descriptor produced by this rate limit |
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.
instead of appending to the descriptor, it should be used to populate the hits_addend
field in the RLS request
https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/ratelimit/v3/rls.proto#service-ratelimit-v3-ratelimitrequest
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.
Single RateLimit
message is used to generate a single descriptor. The RateLimit.hits_addend
field here is also a descriptor level configuration. So, the generated value of RateLimit.hits_addend
field here should also be populated to the per-descriptor Descriptor.hits_addend
rather than request level RateLimitRequest.hits_addend
.
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.
shouldnt this be one level up, under https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#config-route-v3-ratelimit ? so it can set the hits_addend
field of https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/ratelimit/v3/rls.proto#service-ratelimit-v3-ratelimitrequest ?
The ratelimit request holds a list of descriptors
@@ -2168,16 +2169,47 @@ message RateLimit { | |||
} | |||
} | |||
|
|||
message HitsAddend { |
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.
should this look more like https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/base.proto#config-core-v3-datasource ?
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.
sorry, but I didn't get what you mean. 🤣 This HitsAddend is only used to configure single fixed number of a dynamic formatter provider.
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.
yeah what I was getting at, is there any anything existing thats reusable ?
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.
for e.g. the style used here https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/http/custom_response/local_response_policy/v3/local_response_policy.proto#extensions-http-custom-response-local-response-policy-v3-localresponsepolicy is body
and body_format
Hi, @mattklein123 , could you take a look when you get some free time? Thansk. This PR only contain local-ratelimit related change. And I will create a new PR to support global rate limit after this is done. |
Signed-off-by: wangbaiping(wbpcode) <[email protected]>
18489a3
to
774066d
Compare
Finally, reduced 50% code changes. I have tried my best to reduce the complexity of review. orz. |
Commit Message: api: new per descriptor hits-addend support and dynamic hits addend
Additional Description:
Now, we could get custom hits_addend from the
envoy.ratelimit.hits_addend
. But if there are multiple rate limit filters that requrie custom hits_addend, theenvoy.ratelimit.hits_addend
couldn't meet the requirement.And we cann't also to support different hits_addend for diffferent descriptots in same request.
This API changes try to meet above two requirements.
Risk Level: low.
Testing: n/a.
Docs Changes: n/a.
Release Notes: n/a.
Platform Specific Features: n/a.