Skip to content

Commit

Permalink
Update docs, fix minor code issues, extract util
Browse files Browse the repository at this point in the history
* Update DEPRECATED and version_history docs
* Fix FractionalPercent variable declaration issue
* Extract repeating logic into a macro

Signed-off-by: Venil Noronha <veniln@vmware.com>
  • Loading branch information
venilnoronha committed Aug 8, 2018
1 parent 3d56b3f commit f197fe2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
3 changes: 3 additions & 0 deletions DEPRECATED.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ A logged warning is expected for each deprecated item that is in deprecation win
[HttpConnectionManager](https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.proto)
instead.
* Setting hosts via `hosts` field in `Cluster` is deprecated. Use `load_assignment` 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.

## Version 1.7.0

Expand Down
3 changes: 2 additions & 1 deletion docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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 :ref:`fractional percentages <envoy_api_field_config.filter.fault.v2.FaultDelay.percentage>`.
* 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
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
16 changes: 4 additions & 12 deletions source/extensions/filters/http/fault/fault_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +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()) {
if (fault.abort().has_percentage()) {
abort_percentage_ = fault.abort().percentage();
} else {
abort_percentage_.set_numerator(fault.abort().percent());
abort_percentage_.set_denominator(envoy::type::FractionalPercent::HUNDRED);
}
PROTOBUF_SET_FRACTIONAL_PERCENT_OR_DEFAULT(abort_percentage_, fault.abort(), percentage,
percent);
http_status_ = fault.abort().http_status();
}

if (fault.has_delay()) {
if (fault.delay().has_percentage()) {
fixed_delay_percentage_ = fault.delay().percentage();
} else {
fixed_delay_percentage_.set_numerator(fault.delay().percent());
fixed_delay_percentage_.set_denominator(envoy::type::FractionalPercent::HUNDRED);
}
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 Down
8 changes: 4 additions & 4 deletions source/extensions/filters/http/fault/fault_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class FaultSettings : public Router::RouteSpecificFilterConfig {
const std::unordered_set<std::string>& downstreamNodes() const { return downstream_nodes_; }

private:
envoy::type::FractionalPercent abort_percentage_{}; // 0.0-100.0
uint64_t http_status_{}; // HTTP or gRPC return codes
envoy::type::FractionalPercent fixed_delay_percentage_{}; // 0.0-100.0
uint64_t fixed_duration_ms_{}; // in milliseconds
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 Down
8 changes: 2 additions & 6 deletions source/extensions/filters/network/mongo_proxy/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,8 @@ class FaultConfig {
public:
FaultConfig(const envoy::config::filter::fault::v2::FaultDelay& fault_config)
: duration_ms_(PROTOBUF_GET_MS_REQUIRED(fault_config, fixed_delay)) {
if (fault_config.has_percentage()) {
delay_percentage_ = fault_config.percentage();
} else {
delay_percentage_.set_numerator(static_cast<uint32_t>(fault_config.percent()));
delay_percentage_.set_denominator(envoy::type::FractionalPercent::HUNDRED);
}
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_; }
Expand Down

0 comments on commit f197fe2

Please sign in to comment.