-
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 24 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,42 @@ | |
#include <vector> | ||
|
||
#include "envoy/http/codes.h" | ||
#include "envoy/stream_info/stream_info.h" | ||
|
||
#include "source/common/common/assert.h" | ||
#include "source/common/common/enum_to_int.h" | ||
#include "source/common/common/fmt.h" | ||
#include "source/common/http/codes.h" | ||
#include "source/common/http/header_utility.h" | ||
#include "source/common/router/config_impl.h" | ||
#include "source/common/stream_info/uint32_accessor_impl.h" | ||
#include "source/extensions/filters/http/ratelimit/ratelimit_headers.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace HttpFilters { | ||
namespace RateLimitFilter { | ||
|
||
namespace { | ||
constexpr absl::string_view HitsAddendFilterStateKey = "envoy.ratelimit.hits_addend"; | ||
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. @mattklein123 can we make this key configurable per filter? |
||
|
||
class HitsAddendObjectFactory : public StreamInfo::FilterState::ObjectFactory { | ||
public: | ||
std::string name() const override { return std::string(HitsAddendFilterStateKey); } | ||
std::unique_ptr<StreamInfo::FilterState::Object> | ||
createFromBytes(absl::string_view data) const override { | ||
uint32_t hits_addend = 0; | ||
if (absl::SimpleAtoi(data, &hits_addend)) { | ||
return std::make_unique<StreamInfo::UInt32AccessorImpl>(hits_addend); | ||
} | ||
return nullptr; | ||
} | ||
}; | ||
|
||
REGISTER_FACTORY(HitsAddendObjectFactory, StreamInfo::FilterState::ObjectFactory); | ||
|
||
} // namespace | ||
EItanya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
struct RcDetailsValues { | ||
// This request went above the configured limits for the rate limit filter. | ||
const std::string RateLimited = "request_rate_limited"; | ||
|
@@ -64,11 +86,19 @@ void Filter::initiateCall(const Http::RequestHeaderMap& headers) { | |
break; | ||
} | ||
|
||
const StreamInfo::UInt32Accessor* hits_addend_filter_state = | ||
callbacks_->streamInfo().filterState()->getDataReadOnly<StreamInfo::UInt32Accessor>( | ||
HitsAddendFilterStateKey); | ||
double hits_addend = 0; | ||
EItanya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (hits_addend_filter_state != nullptr) { | ||
hits_addend = hits_addend_filter_state->value(); | ||
} | ||
|
||
if (!descriptors.empty()) { | ||
state_ = State::Calling; | ||
initiating_call_ = true; | ||
client_->limit(*this, getDomain(), descriptors, callbacks_->activeSpan(), | ||
callbacks_->streamInfo(), 0); | ||
callbacks_->streamInfo(), hits_addend); | ||
initiating_call_ = false; | ||
} | ||
} | ||
|
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
Oops, something went wrong.
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.
Please fix the CI, these is a issue that I know. Double backticks should be used.