-
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
Add the ability to set the hits_addend for a given rate_limit request via a hardcoded dynamic metadata field #34184
Merged
wbpcode
merged 26 commits into
envoyproxy:main
from
EItanya:hits_addend_dynamic_metadata
Aug 1, 2024
Merged
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
673a527
hits_addend_dynamic_metadata
EItanya 79b6103
clang-format
EItanya 560bbd1
docs
EItanya 5c123a2
merge commit
EItanya b93fed1
Merge branch 'main' of https://github.com/envoyproxy/envoy into hits_…
EItanya 5c357aa
formatting in changelog
EItanya 77c211f
docs
EItanya 41ea807
changelog merge
EItanya 1eb1b1c
add IS_ENVOY_BUG when hits_addens is not a number value
EItanya 8afebc2
PR comments
EItanya 581d9ab
swap impl to filter_state from dynamic metadata
EItanya de668ad
update docs
EItanya a28f00d
Merge branch 'main' into hits_addend_dynamic_metadata
EItanya e254738
Merge branch 'main' of https://github.com/envoyproxy/envoy into hits_…
EItanya 95ca05b
clang-formatting
EItanya 339234b
Merge branch 'main' into hits_addend_dynamic_metadata
EItanya 449822d
yaml formatting
EItanya 224db24
Merge branch 'hits_addend_dynamic_metadata' of github.com:eitanya/env…
EItanya 4131e40
add well known filter state doc
EItanya c56320a
test was incorrect
EItanya 9288df9
rename from earlier copy/paste
EItanya e4d8c8e
Merge branch 'main' of https://github.com/envoyproxy/envoy into hits_…
EItanya 73b73e3
PR comments for coverage, testing, and formatting
EItanya 9e7bc55
move test into anonymous NS
EItanya 20a2109
double backticks
EItanya 19f5e43
Merge branch 'main' into hits_addend_dynamic_metadata
wbpcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ message RateLimitRequest { | |
|
||
// Rate limit requests can optionally specify the number of hits a request adds to the matched | ||
// limit. If the value is not set in the message, a request increases the matched limit by 1. | ||
// This value can be modified by setting "envoy.ratelimit:hits_addend" in the dynamic metadata | ||
// for a given request. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
uint32 hits_addend = 3; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,6 +226,10 @@ new_features: | |
change: | | ||
Added :ref:`bypass_overload_manager <envoy_v3_api_field_config.listener.v3.Listener.bypass_overload_manager>` | ||
to bypass the overload manager for a listener. When set to true, the listener will not be subject to overload protection. | ||
- area: ratelimit | ||
change: | | ||
Added the ability to modify :ref:`hits_addend <envoy_v3_api_field_service.ratelimit.v3.RateLimitRequest.hits_addend>` | ||
by setting ``envoy.ratelimit.hits_addend`` to the desired value. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
deprecated: | ||
- area: tracing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 most of cases, we prefer do similar things in the
FilterState
rather than dynamic metadata (like various sock options in the filter state and other dynamic configuration from filter state)? Is there any reason prefer the dynamic metadata?cc @mattklein123
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.
I based this off of
envoy_lb
style decisions which can be made viaDynamicMetadata
. I don't have super strong feelings either way, but there are more easier ways to setDynamicMetadata
via other filters so I slightly prefer this method.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.
envoy.lb
use the metadata because the subset lb construct the match structure from the endpoint metadata.Then, in this scenario, I think filter state should be preferred for these typed options.
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 this case we use dynamic metadata as it allows to feed data in without the source filter being aware that it is for rate limit.
For example, we can use ext-auth server to add the metadata for the rate limit filter.
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.
As far as I know, the ext_authz could only inject the dynamic metadata with namespace
envoy.filters.http.ext_authz
?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 use-case is that we want to dynamically increment the
hits_addend
value based on the contents of the body. We have a filter to process the body and then write the value to thedynamic_metadata
. Maybe I'm not understanding the distinction betweendynamic_metadata
andfilter_state
. Typically I've useddynamic_metadata
to internally pass data between multiple filters, but it seems like there's nuance here I'm missing.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.
Here are some discussion about the filter state and dynamic metadata #25130
Basically, we prefer to use filter state for non-proto/JSON-like data.
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.
Alright, I plan to use the
UInt32Accessor
class. Does that make sense?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 does that sound correct?
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.
Would this also allow forwarding the call to the downstream service and e.g. taking something off the response header for
hits_addend
before getting to the rate limiter filter, as described here? envoyproxy/ratelimit#636 (comment)