-
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
network: Enable the Kill Request filter to honor Route-level configur… #14944
Changes from 4 commits
e4584fa
acfcf75
f7c1716
1322b31
bc7c9ae
22c62c3
c424229
f9c674e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
#include "extensions/filters/http/kill_request/kill_request_filter.h" | ||
|
||
#include <csignal> | ||
#include <string> | ||
|
||
#include "common/protobuf/utility.h" | ||
|
||
#include "extensions/filters/http/well_known_names.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace HttpFilters { | ||
namespace KillRequest { | ||
|
||
using ::envoy::extensions::filters::http::kill_request::v3::KillRequest; | ||
|
||
KillSettings::KillSettings(const KillRequest& kill_request) | ||
: kill_probability_(kill_request.probability()) {} | ||
|
||
bool KillRequestFilter::isKillRequestEnabled() { | ||
return ProtobufPercentHelper::evaluateFractionalPercent(kill_request_.probability(), | ||
random_generator_.random()); | ||
|
@@ -29,6 +37,20 @@ Http::FilterHeadersStatus KillRequestFilter::decodeHeaders(Http::RequestHeaderMa | |
return Http::FilterHeadersStatus::Continue; | ||
} | ||
|
||
// Route-level configuration overrides filter-level configuration. | ||
if (decoder_callbacks_->route() && decoder_callbacks_->route()->routeEntry()) { | ||
const std::string& name = Extensions::HttpFilters::HttpFilterNames::get().KillRequest; | ||
const auto* route_entry = decoder_callbacks_->route()->routeEntry(); | ||
|
||
const auto* per_route_kill_settings = | ||
route_entry->mostSpecificPerFilterConfigTyped<KillSettings>(name); | ||
|
||
if (per_route_kill_settings) { | ||
envoy::type::v3::FractionalPercent probability = per_route_kill_settings->getProbability(); | ||
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. Nit: 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. Done |
||
kill_request_.set_allocated_probability(&probability); | ||
} | ||
} | ||
|
||
if (is_kill_request && isKillRequestEnabled()) { | ||
// Crash Envoy. | ||
raise(SIGABRT); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#include "envoy/http/filter.h" | ||
#include "envoy/http/header_map.h" | ||
|
||
#include "common/http/header_utility.h" | ||
#include "common/http/headers.h" | ||
|
||
namespace Envoy { | ||
|
@@ -52,7 +53,9 @@ class KillRequestFilter : public Http::StreamFilter, Logger::Loggable<Logger::Id | |
return Http::FilterTrailersStatus::Continue; | ||
} | ||
|
||
void setDecoderFilterCallbacks(Http::StreamDecoderFilterCallbacks&) override {} | ||
void setDecoderFilterCallbacks(Http::StreamDecoderFilterCallbacks& callbacks) override { | ||
decoder_callbacks_ = &callbacks; | ||
} | ||
|
||
// Http::StreamEncoderFilter | ||
Http::FilterHeadersStatus encode100ContinueHeaders(Http::ResponseHeaderMap&) override { | ||
|
@@ -82,8 +85,29 @@ class KillRequestFilter : public Http::StreamFilter, Logger::Loggable<Logger::Id | |
// equaling true. | ||
bool isKillRequestEnabled(); | ||
|
||
const envoy::extensions::filters::http::kill_request::v3::KillRequest kill_request_; | ||
envoy::extensions::filters::http::kill_request::v3::KillRequest kill_request_; | ||
Random::RandomGenerator& random_generator_; | ||
Http::StreamDecoderFilterCallbacks* decoder_callbacks_{}; | ||
}; | ||
|
||
/** | ||
* Configuration for fault injection. | ||
*/ | ||
class KillSettings : public Router::RouteSpecificFilterConfig { | ||
public: | ||
KillSettings(const envoy::extensions::filters::http::kill_request::v3::KillRequest& kill_request); | ||
|
||
const std::vector<Http::HeaderUtility::HeaderDataPtr>& filterHeaders() const { | ||
return kill_request_filter_headers_; | ||
} | ||
|
||
const envoy::type::v3::FractionalPercent getProbability() const { | ||
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 is a bit weird. Why not just make return type 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. Done |
||
return std::move(kill_probability_); | ||
} | ||
|
||
private: | ||
envoy::type::v3::FractionalPercent kill_probability_; | ||
const std::vector<Http::HeaderUtility::HeaderDataPtr> kill_request_filter_headers_; | ||
}; | ||
|
||
} // namespace KillRequest | ||
|
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 think we eventually want to match with the actual name used in the filter instantiation, but this hasn't been fixed Envoy-wide to my knowledge (#12575).