-
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
Request Header rate limiting Support #94
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1c7063d
Squashed commit of the following:
ccaraman 8567fdf
Address prr comments
ccaraman 29076df
rebase master
ccaraman ee45228
rename to route_key
ccaraman 2b39fc6
update docs
ccaraman c286768
update name
ccaraman 2df67c7
update comment
ccaraman d83a754
Spacing
ccaraman 24cadb0
clarify comment
ccaraman f2216f1
Update route.rst
mattklein123 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 |
---|---|---|
|
@@ -16,7 +16,7 @@ const Http::HeaderMapImpl Filter::TOO_MANY_REQUESTS_HEADER{ | |
|
||
void ServiceToServiceAction::populateDescriptors(const Router::RouteEntry& route, | ||
std::vector<::RateLimit::Descriptor>& descriptors, | ||
FilterConfig& config) { | ||
FilterConfig& config, const HeaderMap&) { | ||
// We limit on 2 dimensions. | ||
// 1) All calls to the given cluster. | ||
// 2) Calls to the given cluster and from this cluster. | ||
|
@@ -26,6 +26,24 @@ void ServiceToServiceAction::populateDescriptors(const Router::RouteEntry& route | |
{{{"to_cluster", route.clusterName()}, {"from_cluster", config.localServiceCluster()}}}); | ||
} | ||
|
||
void RequestHeadersAction::populateDescriptors(const Router::RouteEntry& route, | ||
std::vector<::RateLimit::Descriptor>& descriptors, | ||
FilterConfig&, const HeaderMap& headers) { | ||
std::string header_value = headers.get(header_name_); | ||
if (header_value.empty()) { | ||
return; | ||
} | ||
|
||
descriptors.push_back({{{descriptor_key_, header_value}}}); | ||
|
||
std::string route_key = route.rateLimitPolicy().routeKey(); | ||
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. this does a copy, so do const std::string& or leave it the way you had it before. 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. updated. |
||
if (route_key.empty()) { | ||
return; | ||
} | ||
|
||
descriptors.push_back({{{"route_key", route_key}, {descriptor_key_, header_value}}}); | ||
} | ||
|
||
FilterConfig::FilterConfig(const Json::Object& config, const std::string& local_service_cluster, | ||
Stats::Store& stats_store, Runtime::Loader& runtime) | ||
: domain_(config.getString("domain")), local_service_cluster_(local_service_cluster), | ||
|
@@ -34,6 +52,8 @@ FilterConfig::FilterConfig(const Json::Object& config, const std::string& local_ | |
std::string type = action.getString("type"); | ||
if (type == "service_to_service") { | ||
actions_.emplace_back(new ServiceToServiceAction()); | ||
} else if (type == "request_headers") { | ||
actions_.emplace_back(new RequestHeadersAction(action)); | ||
} else { | ||
throw EnvoyException(fmt::format("unknown http rate limit filter action '{}'", type)); | ||
} | ||
|
@@ -49,7 +69,7 @@ FilterHeadersStatus Filter::decodeHeaders(HeaderMap& headers, bool) { | |
if (route && route->rateLimitPolicy().doGlobalLimiting()) { | ||
std::vector<::RateLimit::Descriptor> descriptors; | ||
for (const ActionPtr& action : config_->actions()) { | ||
action->populateDescriptors(*route, descriptors, *config_); | ||
action->populateDescriptors(*route, descriptors, *config_, headers); | ||
} | ||
|
||
if (!descriptors.empty()) { | ||
|
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
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.
nit: return the route key, if it exists.