Skip to content

Commit f197fe2

Browse files
committed
Update docs, fix minor code issues, extract util
* 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>
1 parent 3d56b3f commit f197fe2

6 files changed

Lines changed: 25 additions & 23 deletions

File tree

DEPRECATED.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ A logged warning is expected for each deprecated item that is in deprecation win
2424
[HttpConnectionManager](https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.proto)
2525
instead.
2626
* Setting hosts via `hosts` field in `Cluster` is deprecated. Use `load_assignment` instead.
27+
* Use of the integer `percent` field in [FaultDelay](https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/fault/v2/fault.proto)
28+
and in [FaultAbort](https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/http/fault/v2/fault.proto) is deprecated in favor
29+
of the new `FractionalPercent` based `percentage` field.
2730

2831
## Version 1.7.0
2932

docs/root/intro/version_history.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Version history
1111
`google.api.HttpBody <https://github.com/googleapis/googleapis/blob/master/google/api/httpbody.proto>`_.
1212
* config: v1 disabled by default. v1 support remains available until October via flipping --v2-config-only=false.
1313
* config: v1 disabled by default. v1 support remains available until October via setting :option:`--allow-deprecated-v1-api`.
14-
* fault: added support for :ref:`fractional percentages <envoy_api_field_config.filter.fault.v2.FaultDelay.percentage>`.
14+
* fault: added support for fractional percentages in :ref:`FaultDelay <envoy_api_field_config.filter.fault.v2.FaultDelay.percentage>`
15+
and in :ref:`FaultAbort <envoy_api_field_config.filter.http.fault.v2.FaultAbort.percentage>`.
1516
* health check: added support for :ref:`custom health check <envoy_api_field_core.HealthCheck.custom_health_check>`.
1617
* health check: added support for :ref:`specifying jitter as a percentage <envoy_api_field_core.HealthCheck.interval_jitter_percent>`.
1718
* health_check: added support for :ref:`health check event logging <arch_overview_health_check_logging>`.

source/common/protobuf/utility.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
((message).has_##field_name() ? DurationUtil::durationToSeconds((message).field_name()) \
4949
: throw MissingFieldException(#field_name, (message)))
5050

51+
// Set the value of a FractionalPercent field with the value from a protobuf message if present.
52+
// Otherwise, convert the default field value into FractionalPercent and set it.
53+
#define PROTOBUF_SET_FRACTIONAL_PERCENT_OR_DEFAULT(field, message, field_name, default_field_name) \
54+
if ((message).has_##field_name()) { \
55+
field = (message).field_name(); \
56+
} else { \
57+
field.set_numerator((message).default_field_name()); \
58+
field.set_denominator(envoy::type::FractionalPercent::HUNDRED); \
59+
}
60+
5161
namespace Envoy {
5262
namespace ProtobufPercentHelper {
5363

source/extensions/filters/http/fault/fault_filter.cc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,14 @@ const std::string FaultFilter::ABORT_HTTP_STATUS_KEY = "fault.http.abort.http_st
3434
FaultSettings::FaultSettings(const envoy::config::filter::http::fault::v2::HTTPFault& fault) {
3535

3636
if (fault.has_abort()) {
37-
if (fault.abort().has_percentage()) {
38-
abort_percentage_ = fault.abort().percentage();
39-
} else {
40-
abort_percentage_.set_numerator(fault.abort().percent());
41-
abort_percentage_.set_denominator(envoy::type::FractionalPercent::HUNDRED);
42-
}
37+
PROTOBUF_SET_FRACTIONAL_PERCENT_OR_DEFAULT(abort_percentage_, fault.abort(), percentage,
38+
percent);
4339
http_status_ = fault.abort().http_status();
4440
}
4541

4642
if (fault.has_delay()) {
47-
if (fault.delay().has_percentage()) {
48-
fixed_delay_percentage_ = fault.delay().percentage();
49-
} else {
50-
fixed_delay_percentage_.set_numerator(fault.delay().percent());
51-
fixed_delay_percentage_.set_denominator(envoy::type::FractionalPercent::HUNDRED);
52-
}
43+
PROTOBUF_SET_FRACTIONAL_PERCENT_OR_DEFAULT(fixed_delay_percentage_, fault.delay(), percentage,
44+
percent);
5345
const auto& delay = fault.delay();
5446
fixed_duration_ms_ = PROTOBUF_GET_MS_OR_DEFAULT(delay, fixed_delay, 0);
5547
}

source/extensions/filters/http/fault/fault_filter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class FaultSettings : public Router::RouteSpecificFilterConfig {
5353
const std::unordered_set<std::string>& downstreamNodes() const { return downstream_nodes_; }
5454

5555
private:
56-
envoy::type::FractionalPercent abort_percentage_{}; // 0.0-100.0
57-
uint64_t http_status_{}; // HTTP or gRPC return codes
58-
envoy::type::FractionalPercent fixed_delay_percentage_{}; // 0.0-100.0
59-
uint64_t fixed_duration_ms_{}; // in milliseconds
56+
envoy::type::FractionalPercent abort_percentage_;
57+
uint64_t http_status_{}; // HTTP or gRPC return codes
58+
envoy::type::FractionalPercent fixed_delay_percentage_;
59+
uint64_t fixed_duration_ms_{}; // in milliseconds
6060
std::string upstream_cluster_; // restrict faults to specific upstream cluster
6161
std::vector<Http::HeaderUtility::HeaderData> fault_filter_headers_;
6262
std::unordered_set<std::string> downstream_nodes_{}; // Inject failures for specific downstream

source/extensions/filters/network/mongo_proxy/proxy.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,8 @@ class FaultConfig {
103103
public:
104104
FaultConfig(const envoy::config::filter::fault::v2::FaultDelay& fault_config)
105105
: duration_ms_(PROTOBUF_GET_MS_REQUIRED(fault_config, fixed_delay)) {
106-
if (fault_config.has_percentage()) {
107-
delay_percentage_ = fault_config.percentage();
108-
} else {
109-
delay_percentage_.set_numerator(static_cast<uint32_t>(fault_config.percent()));
110-
delay_percentage_.set_denominator(envoy::type::FractionalPercent::HUNDRED);
111-
}
106+
PROTOBUF_SET_FRACTIONAL_PERCENT_OR_DEFAULT(delay_percentage_, fault_config, percentage,
107+
percent);
112108
}
113109
envoy::type::FractionalPercent delayPercentage() const { return delay_percentage_; }
114110
uint64_t delayDuration() const { return duration_ms_; }

0 commit comments

Comments
 (0)