Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DEPRECATED.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ A logged warning is expected for each deprecated item that is in deprecation win
is deprecated. Please use the new `upgrade_configs` in the
[HttpConnectionManager](https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.proto)
instead.
* Use of the integer `percent` field in [FaultDelay](https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/fault/v2/fault.proto)
and in [FaultAbort](https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/http/fault/v2/fault.proto) is deprecated in favor
of the new `FractionalPercent` based `percentage` field.
* Setting hosts via `hosts` field in `Cluster` is deprecated. Use `load_assignment` instead.

## Version 1.7.0
Expand Down
1 change: 1 addition & 0 deletions api/envoy/config/filter/fault/v2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ api_proto_library_internal(
"//envoy/config/filter/http/fault/v2:__pkg__",
"//envoy/config/filter/network/mongo_proxy/v2:__pkg__",
],
deps = ["//envoy/type:percent"],
)
11 changes: 10 additions & 1 deletion api/envoy/config/filter/fault/v2/fault.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ syntax = "proto3";
package envoy.config.filter.fault.v2;
option go_package = "v2";

import "envoy/type/percent.proto";

import "google/protobuf/duration.proto";

import "validate/validate.proto";
Expand All @@ -24,7 +26,11 @@ message FaultDelay {

// An integer between 0-100 indicating the percentage of operations/connection requests
// on which the delay will be injected.
uint32 percent = 2 [(validate.rules).uint32.lte = 100];
//
// .. attention::
//
// Use of integer `percent` value is deprecated. Use fractional `percentage` field instead.
uint32 percent = 2 [(validate.rules).uint32.lte = 100, deprecated = true];

oneof fault_delay_secifier {
option (validate.required) = true;
Expand All @@ -37,4 +43,7 @@ message FaultDelay {
google.protobuf.Duration fixed_delay = 3
[(validate.rules).duration.gt = {}, (gogoproto.stdduration) = true];
}

// The percentage of operations/connection requests on which the delay will be injected.
envoy.type.FractionalPercent percentage = 4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do the same for aborts as well ?

}
1 change: 1 addition & 0 deletions api/envoy/config/filter/http/fault/v2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ api_proto_library_internal(
deps = [
"//envoy/api/v2/route",
"//envoy/config/filter/fault/v2:fault",
"//envoy/type:percent",
],
)
13 changes: 11 additions & 2 deletions api/envoy/config/filter/http/fault/v2/fault.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ syntax = "proto3";
package envoy.config.filter.http.fault.v2;
option go_package = "v2";

import "envoy/config/filter/fault/v2/fault.proto";
import "envoy/api/v2/route/route.proto";
import "envoy/config/filter/fault/v2/fault.proto";
import "envoy/type/percent.proto";

import "validate/validate.proto";

Expand All @@ -14,14 +15,22 @@ import "validate/validate.proto";
message FaultAbort {
// An integer between 0-100 indicating the percentage of requests/operations/connections
// that will be aborted with the error code provided.
uint32 percent = 1 [(validate.rules).uint32.lte = 100];
//
// .. attention::
//
// Use of integer `percent` value is deprecated. Use fractional `percentage` field instead.
uint32 percent = 1 [(validate.rules).uint32.lte = 100, deprecated = true];

oneof error_type {
option (validate.required) = true;

// HTTP status code to use to abort the HTTP request.
uint32 http_status = 2 [(validate.rules).uint32 = {gte: 200, lt: 600}];
}

// The percentage of requests/operations/connections that will be aborted with the error code
// provided.
envoy.type.FractionalPercent percentage = 3;
}

message HTTPFault {
Expand Down
2 changes: 2 additions & 0 deletions docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Version history
`google.api.HttpBody <https://github.com/googleapis/googleapis/blob/master/google/api/httpbody.proto>`_.
* config: v1 disabled by default. v1 support remains available until October via flipping --v2-config-only=false.
* config: v1 disabled by default. v1 support remains available until October via setting :option:`--allow-deprecated-v1-api`.
* fault: added support for fractional percentages in :ref:`FaultDelay <envoy_api_field_config.filter.fault.v2.FaultDelay.percentage>`
and in :ref:`FaultAbort <envoy_api_field_config.filter.http.fault.v2.FaultAbort.percentage>`.
* health check: added support for :ref:`custom health check <envoy_api_field_core.HealthCheck.custom_health_check>`.
* health check: added support for :ref:`specifying jitter as a percentage <envoy_api_field_core.HealthCheck.interval_jitter_percent>`.
* health_check: added support for :ref:`health check event logging <arch_overview_health_check_logging>`.
Expand Down
4 changes: 2 additions & 2 deletions include/envoy/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class Snapshot {
* does not exist or it is not an integer.
* @param random_value supplies the stable random value to use for determining whether the feature
* is enabled.
* @param control max number of buckets for sampling. Sampled value will be in a range of
* [0, num_buckets).
* @param num_buckets control max number of buckets for sampling. Sampled value will be in a range
* of [0, num_buckets).
* @return true if the feature is enabled.
*/
virtual bool featureEnabled(const std::string& key, uint64_t default_value, uint64_t random_value,
Expand Down
10 changes: 10 additions & 0 deletions source/common/protobuf/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
((message).has_##field_name() ? DurationUtil::durationToSeconds((message).field_name()) \
: throw MissingFieldException(#field_name, (message)))

// Set the value of a FractionalPercent field with the value from a protobuf message if present.
// Otherwise, convert the default field value into FractionalPercent and set it.
#define PROTOBUF_SET_FRACTIONAL_PERCENT_OR_DEFAULT(field, message, field_name, default_field_name) \
if ((message).has_##field_name()) { \
field = (message).field_name(); \
} else { \
field.set_numerator((message).default_field_name()); \
field.set_denominator(envoy::type::FractionalPercent::HUNDRED); \
}

namespace Envoy {
namespace ProtobufPercentHelper {

Expand Down
4 changes: 2 additions & 2 deletions source/extensions/filters/http/fault/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace Fault {
Http::FilterFactoryCb FaultFilterFactory::createFilterFactoryFromProtoTyped(
const envoy::config::filter::http::fault::v2::HTTPFault& config,
const std::string& stats_prefix, Server::Configuration::FactoryContext& context) {
FaultFilterConfigSharedPtr filter_config(
new FaultFilterConfig(config, context.runtime(), stats_prefix, context.scope()));
FaultFilterConfigSharedPtr filter_config(new FaultFilterConfig(
config, context.runtime(), stats_prefix, context.scope(), context.random()));
return [filter_config](Http::FilterChainFactoryCallbacks& callbacks) -> void {
callbacks.addStreamDecoderFilter(std::make_shared<FaultFilter>(filter_config));
};
Expand Down
40 changes: 24 additions & 16 deletions source/extensions/filters/http/fault/fault_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ const std::string FaultFilter::ABORT_HTTP_STATUS_KEY = "fault.http.abort.http_st
FaultSettings::FaultSettings(const envoy::config::filter::http::fault::v2::HTTPFault& fault) {

if (fault.has_abort()) {
abort_percent_ = fault.abort().percent();
PROTOBUF_SET_FRACTIONAL_PERCENT_OR_DEFAULT(abort_percentage_, fault.abort(), percentage,
percent);
http_status_ = fault.abort().http_status();
}

if (fault.has_delay()) {
fixed_delay_percent_ = fault.delay().percent();
PROTOBUF_SET_FRACTIONAL_PERCENT_OR_DEFAULT(fixed_delay_percentage_, fault.delay(), percentage,
percent);
const auto& delay = fault.delay();
fixed_duration_ms_ = PROTOBUF_GET_MS_OR_DEFAULT(delay, fixed_delay, 0);
}
Expand All @@ -57,9 +59,9 @@ FaultSettings::FaultSettings(const envoy::config::filter::http::fault::v2::HTTPF

FaultFilterConfig::FaultFilterConfig(const envoy::config::filter::http::fault::v2::HTTPFault& fault,
Runtime::Loader& runtime, const std::string& stats_prefix,
Stats::Scope& scope)
Stats::Scope& scope, Runtime::RandomGenerator& generator)
: settings_(fault), runtime_(runtime), stats_(generateStats(stats_prefix, scope)),
stats_prefix_(stats_prefix), scope_(scope) {}
stats_prefix_(stats_prefix), scope_(scope), generator_(generator) {}

FaultFilter::FaultFilter(FaultFilterConfigSharedPtr config) : config_(config) {}

Expand Down Expand Up @@ -129,26 +131,32 @@ Http::FilterHeadersStatus FaultFilter::decodeHeaders(Http::HeaderMap& headers, b
}

bool FaultFilter::isDelayEnabled() {
bool enabled = config_->runtime().snapshot().featureEnabled(DELAY_PERCENT_KEY,
fault_settings_->delayPercent());

bool enabled = config_->runtime().snapshot().featureEnabled(
DELAY_PERCENT_KEY, fault_settings_->delayPercentage().numerator(),
config_->randomGenerator().random(),
ProtobufPercentHelper::fractionalPercentDenominatorToInt(fault_settings_->delayPercentage()));
if (!downstream_cluster_delay_percent_key_.empty()) {
enabled |= config_->runtime().snapshot().featureEnabled(downstream_cluster_delay_percent_key_,
fault_settings_->delayPercent());
enabled |= config_->runtime().snapshot().featureEnabled(
downstream_cluster_delay_percent_key_, fault_settings_->delayPercentage().numerator(),
config_->randomGenerator().random(),
ProtobufPercentHelper::fractionalPercentDenominatorToInt(
fault_settings_->delayPercentage()));
}

return enabled;
}

bool FaultFilter::isAbortEnabled() {
bool enabled = config_->runtime().snapshot().featureEnabled(ABORT_PERCENT_KEY,
fault_settings_->abortPercent());

bool enabled = config_->runtime().snapshot().featureEnabled(
ABORT_PERCENT_KEY, fault_settings_->abortPercentage().numerator(),
config_->randomGenerator().random(),
ProtobufPercentHelper::fractionalPercentDenominatorToInt(fault_settings_->abortPercentage()));
if (!downstream_cluster_abort_percent_key_.empty()) {
enabled |= config_->runtime().snapshot().featureEnabled(downstream_cluster_abort_percent_key_,
fault_settings_->abortPercent());
enabled |= config_->runtime().snapshot().featureEnabled(
downstream_cluster_abort_percent_key_, fault_settings_->abortPercentage().numerator(),
config_->randomGenerator().random(),
ProtobufPercentHelper::fractionalPercentDenominatorToInt(
fault_settings_->abortPercentage()));
}

return enabled;
}

Expand Down
19 changes: 11 additions & 8 deletions source/extensions/filters/http/fault/fault_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ class FaultSettings : public Router::RouteSpecificFilterConfig {
const std::vector<Http::HeaderUtility::HeaderData>& filterHeaders() const {
return fault_filter_headers_;
}
uint64_t abortPercent() const { return abort_percent_; }
uint64_t delayPercent() const { return fixed_delay_percent_; }
envoy::type::FractionalPercent abortPercentage() const { return abort_percentage_; }
envoy::type::FractionalPercent delayPercentage() const { return fixed_delay_percentage_; }
uint64_t delayDuration() const { return fixed_duration_ms_; }
uint64_t abortCode() const { return http_status_; }
const std::string& upstreamCluster() const { return upstream_cluster_; }
const std::unordered_set<std::string>& downstreamNodes() const { return downstream_nodes_; }

private:
uint64_t abort_percent_{}; // 0-100
uint64_t http_status_{}; // HTTP or gRPC return codes
uint64_t fixed_delay_percent_{}; // 0-100
uint64_t fixed_duration_ms_{}; // in milliseconds
std::string upstream_cluster_; // restrict faults to specific upstream cluster
envoy::type::FractionalPercent abort_percentage_;
uint64_t http_status_{}; // HTTP or gRPC return codes
envoy::type::FractionalPercent fixed_delay_percentage_;
uint64_t fixed_duration_ms_{}; // in milliseconds
std::string upstream_cluster_; // restrict faults to specific upstream cluster
std::vector<Http::HeaderUtility::HeaderData> fault_filter_headers_;
std::unordered_set<std::string> downstream_nodes_{}; // Inject failures for specific downstream
};
Expand All @@ -68,13 +68,15 @@ class FaultSettings : public Router::RouteSpecificFilterConfig {
class FaultFilterConfig {
public:
FaultFilterConfig(const envoy::config::filter::http::fault::v2::HTTPFault& fault,
Runtime::Loader& runtime, const std::string& stats_prefix, Stats::Scope& scope);
Runtime::Loader& runtime, const std::string& stats_prefix, Stats::Scope& scope,
Runtime::RandomGenerator& generator);

Runtime::Loader& runtime() { return runtime_; }
FaultFilterStats& stats() { return stats_; }
const std::string& statsPrefix() { return stats_prefix_; }
Stats::Scope& scope() { return scope_; }
const FaultSettings* settings() { return &settings_; }
Runtime::RandomGenerator& randomGenerator() { return generator_; }

private:
static FaultFilterStats generateStats(const std::string& prefix, Stats::Scope& scope);
Expand All @@ -84,6 +86,7 @@ class FaultFilterConfig {
FaultFilterStats stats_;
const std::string stats_prefix_;
Stats::Scope& scope_;
Runtime::RandomGenerator& generator_;
};

typedef std::shared_ptr<FaultFilterConfig> FaultFilterConfigSharedPtr;
Expand Down
6 changes: 3 additions & 3 deletions source/extensions/filters/network/mongo_proxy/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Network::FilterFactoryCb MongoProxyFilterConfigFactory::createFilterFactoryFromP

return [stat_prefix, &context, access_log,
fault_config](Network::FilterManager& filter_manager) -> void {
filter_manager.addFilter(
std::make_shared<ProdProxyFilter>(stat_prefix, context.scope(), context.runtime(),
access_log, fault_config, context.drainDecision()));
filter_manager.addFilter(std::make_shared<ProdProxyFilter>(
stat_prefix, context.scope(), context.runtime(), access_log, fault_config,
context.drainDecision(), context.random()));
};
}

Expand Down
12 changes: 8 additions & 4 deletions source/extensions/filters/network/mongo_proxy/proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ void AccessLog::logMessage(const Message& message, bool full,
ProxyFilter::ProxyFilter(const std::string& stat_prefix, Stats::Scope& scope,
Runtime::Loader& runtime, AccessLogSharedPtr access_log,
const FaultConfigSharedPtr& fault_config,
const Network::DrainDecision& drain_decision)
const Network::DrainDecision& drain_decision,
Runtime::RandomGenerator& generator)
: stat_prefix_(stat_prefix), scope_(scope), stats_(generateStats(stat_prefix, scope)),
runtime_(runtime), drain_decision_(drain_decision), access_log_(access_log),
fault_config_(fault_config) {
runtime_(runtime), drain_decision_(drain_decision), generator_(generator),
access_log_(access_log), fault_config_(fault_config) {
if (!runtime_.snapshot().featureEnabled(MongoRuntimeConfig::get().ConnectionLoggingEnabled,
100)) {
// If we are not logging at the connection level, just release the shared pointer so that we
Expand Down Expand Up @@ -320,7 +321,10 @@ absl::optional<uint64_t> ProxyFilter::delayDuration() {
}

if (!runtime_.snapshot().featureEnabled(MongoRuntimeConfig::get().FixedDelayPercent,
fault_config_->delayPercent())) {
fault_config_->delayPercentage().numerator(),
generator_.random(),
ProtobufPercentHelper::fractionalPercentDenominatorToInt(
fault_config_->delayPercentage()))) {
return result;
}

Expand Down
13 changes: 8 additions & 5 deletions source/extensions/filters/network/mongo_proxy/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ typedef std::shared_ptr<AccessLog> AccessLogSharedPtr;
class FaultConfig {
public:
FaultConfig(const envoy::config::filter::fault::v2::FaultDelay& fault_config)
: delay_percent_(fault_config.percent()),
duration_ms_(PROTOBUF_GET_MS_REQUIRED(fault_config, fixed_delay)) {}
uint32_t delayPercent() const { return delay_percent_; }
: duration_ms_(PROTOBUF_GET_MS_REQUIRED(fault_config, fixed_delay)) {
PROTOBUF_SET_FRACTIONAL_PERCENT_OR_DEFAULT(delay_percentage_, fault_config, percentage,
percent);
}
envoy::type::FractionalPercent delayPercentage() const { return delay_percentage_; }
uint64_t delayDuration() const { return duration_ms_; }

private:
const uint32_t delay_percent_;
envoy::type::FractionalPercent delay_percentage_;
const uint64_t duration_ms_;
};

Expand All @@ -125,7 +127,7 @@ class ProxyFilter : public Network::Filter,
public:
ProxyFilter(const std::string& stat_prefix, Stats::Scope& scope, Runtime::Loader& runtime,
AccessLogSharedPtr access_log, const FaultConfigSharedPtr& fault_config,
const Network::DrainDecision& drain_decision);
const Network::DrainDecision& drain_decision, Runtime::RandomGenerator& generator);
~ProxyFilter();

virtual DecoderPtr createDecoder(DecoderCallbacks& callbacks) PURE;
Expand Down Expand Up @@ -193,6 +195,7 @@ class ProxyFilter : public Network::Filter,
MongoProxyStats stats_;
Runtime::Loader& runtime_;
const Network::DrainDecision& drain_decision_;
Runtime::RandomGenerator& generator_;
Buffer::OwnedImpl read_buffer_;
Buffer::OwnedImpl write_buffer_;
bool sniffing_{true};
Expand Down
Loading