From 53608408d2a57eff6a68ad847701dc3e3f04f936 Mon Sep 17 00:00:00 2001 From: James Forcier Date: Wed, 11 Sep 2019 21:54:25 +0000 Subject: [PATCH 1/2] upstream: use named constants for outlier detection config defaults Signed-off-by: James Forcier --- .../common/upstream/outlier_detection_impl.cc | 55 ++++++++++--------- .../common/upstream/outlier_detection_impl.h | 15 +++++ 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/source/common/upstream/outlier_detection_impl.cc b/source/common/upstream/outlier_detection_impl.cc index 0d0efa147366..5fdfddcaaf15 100644 --- a/source/common/upstream/outlier_detection_impl.cc +++ b/source/common/upstream/outlier_detection_impl.cc @@ -207,35 +207,38 @@ void DetectorHostMonitorImpl::localOriginNoFailure() { } DetectorConfig::DetectorConfig(const envoy::api::v2::cluster::OutlierDetection& config) - : interval_ms_(static_cast(PROTOBUF_GET_MS_OR_DEFAULT(config, interval, 10000))), - base_ejection_time_ms_( - static_cast(PROTOBUF_GET_MS_OR_DEFAULT(config, base_ejection_time, 30000))), - consecutive_5xx_( - static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, consecutive_5xx, 5))), - consecutive_gateway_failure_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, consecutive_gateway_failure, 5))), - max_ejection_percent_( - static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, max_ejection_percent, 10))), - success_rate_minimum_hosts_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, success_rate_minimum_hosts, 5))), - success_rate_request_volume_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, success_rate_request_volume, 100))), - success_rate_stdev_factor_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, success_rate_stdev_factor, 1900))), - enforcing_consecutive_5xx_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, enforcing_consecutive_5xx, 100))), + : interval_ms_( + static_cast(PROTOBUF_GET_MS_OR_DEFAULT(config, interval, DEFAULT_INTERVAL_MS))), + base_ejection_time_ms_(static_cast( + PROTOBUF_GET_MS_OR_DEFAULT(config, base_ejection_time, DEFAULT_BASE_EJECTION_TIME_MS))), + consecutive_5xx_(static_cast( + PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, consecutive_5xx, DEFAULT_CONSECUTIVE_5XX))), + consecutive_gateway_failure_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, consecutive_gateway_failure, DEFAULT_CONSECUTIVE_GATEWAY_FAILURE))), + max_ejection_percent_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, max_ejection_percent, DEFAULT_MAX_EJECTION_PERCENT))), + success_rate_minimum_hosts_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, success_rate_minimum_hosts, DEFAULT_SUCCESS_RATE_MINIMUM_HOSTS))), + success_rate_request_volume_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, success_rate_request_volume, DEFAULT_SUCCESS_RATE_REQUEST_VOLUME))), + success_rate_stdev_factor_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, success_rate_stdev_factor, DEFAULT_SUCCESS_RATE_STDEV_FACTOR))), + enforcing_consecutive_5xx_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, enforcing_consecutive_5xx, DEFAULT_ENFORCING_CONSECUTIVE_5XX))), enforcing_consecutive_gateway_failure_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, enforcing_consecutive_gateway_failure, 0))), - enforcing_success_rate_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, enforcing_success_rate, 100))), + PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, enforcing_consecutive_gateway_failure, + DEFAULT_ENFORCING_CONSECUTIVE_GATEWAY_FAILURE))), + enforcing_success_rate_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, enforcing_success_rate, DEFAULT_ENFORCING_SUCCESS_RATE))), split_external_local_origin_errors_(config.split_external_local_origin_errors()), - consecutive_local_origin_failure_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, consecutive_local_origin_failure, 5))), - enforcing_consecutive_local_origin_failure_( - static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( - config, enforcing_consecutive_local_origin_failure, 100))), + consecutive_local_origin_failure_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, consecutive_local_origin_failure, DEFAULT_CONSECUTIVE_LOCAL_ORIGIN_FAILURE))), + enforcing_consecutive_local_origin_failure_(static_cast( + PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, enforcing_consecutive_local_origin_failure, + DEFAULT_ENFORCING_CONSECUTIVE_LOCAL_ORIGIN_FAILURE))), enforcing_local_origin_success_rate_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, enforcing_local_origin_success_rate, 100))) {} + PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, enforcing_local_origin_success_rate, + DEFAULT_ENFORCING_LOCAL_ORIGIN_SUCCESS_RATE))) {} DetectorImpl::DetectorImpl(const Cluster& cluster, const envoy::api::v2::cluster::OutlierDetection& config, diff --git a/source/common/upstream/outlier_detection_impl.h b/source/common/upstream/outlier_detection_impl.h index 2b703c2adba4..491f01259b2e 100644 --- a/source/common/upstream/outlier_detection_impl.h +++ b/source/common/upstream/outlier_detection_impl.h @@ -277,6 +277,21 @@ class DetectorConfig { const uint64_t consecutive_local_origin_failure_; const uint64_t enforcing_consecutive_local_origin_failure_; const uint64_t enforcing_local_origin_success_rate_; + + static const uint64_t DEFAULT_INTERVAL_MS = 10000; + static const uint64_t DEFAULT_BASE_EJECTION_TIME_MS = 30000; + static const uint64_t DEFAULT_CONSECUTIVE_5XX = 5; + static const uint64_t DEFAULT_CONSECUTIVE_GATEWAY_FAILURE = 5; + static const uint64_t DEFAULT_MAX_EJECTION_PERCENT = 10; + static const uint64_t DEFAULT_SUCCESS_RATE_MINIMUM_HOSTS = 5; + static const uint64_t DEFAULT_SUCCESS_RATE_REQUEST_VOLUME = 100; + static const uint64_t DEFAULT_SUCCESS_RATE_STDEV_FACTOR = 1900; + static const uint64_t DEFAULT_ENFORCING_CONSECUTIVE_5XX = 100; + static const uint64_t DEFAULT_ENFORCING_CONSECUTIVE_GATEWAY_FAILURE = 0; + static const uint64_t DEFAULT_ENFORCING_SUCCESS_RATE = 100; + static const uint64_t DEFAULT_CONSECUTIVE_LOCAL_ORIGIN_FAILURE = 5; + static const uint64_t DEFAULT_ENFORCING_CONSECUTIVE_LOCAL_ORIGIN_FAILURE = 100; + static const uint64_t DEFAULT_ENFORCING_LOCAL_ORIGIN_SUCCESS_RATE = 100; }; /** From 2d7dc2d3903273692a97800ec64dcf1fd8557f86 Mon Sep 17 00:00:00 2001 From: James Forcier Date: Thu, 12 Sep 2019 19:17:00 +0000 Subject: [PATCH 2/2] Use named constants for new failure percentage fields Signed-off-by: James Forcier --- .../common/upstream/outlier_detection_impl.cc | 19 ++++++++++--------- .../common/upstream/outlier_detection_impl.h | 5 +++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/source/common/upstream/outlier_detection_impl.cc b/source/common/upstream/outlier_detection_impl.cc index 4709dbfc57c8..428e5ad9c72f 100644 --- a/source/common/upstream/outlier_detection_impl.cc +++ b/source/common/upstream/outlier_detection_impl.cc @@ -223,12 +223,12 @@ DetectorConfig::DetectorConfig(const envoy::api::v2::cluster::OutlierDetection& config, success_rate_request_volume, DEFAULT_SUCCESS_RATE_REQUEST_VOLUME))), success_rate_stdev_factor_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( config, success_rate_stdev_factor, DEFAULT_SUCCESS_RATE_STDEV_FACTOR))), - failure_percentage_threshold_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, failure_percentage_threshold, 85))), - failure_percentage_minimum_hosts_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, failure_percentage_minimum_hosts, 5))), - failure_percentage_request_volume_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, failure_percentage_request_volume, 50))), + failure_percentage_threshold_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, failure_percentage_threshold, DEFAULT_FAILURE_PERCENTAGE_THRESHOLD))), + failure_percentage_minimum_hosts_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, failure_percentage_minimum_hosts, DEFAULT_FAILURE_PERCENTAGE_MINIMUM_HOSTS))), + failure_percentage_request_volume_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, failure_percentage_request_volume, DEFAULT_FAILURE_PERCENTAGE_REQUEST_VOLUME))), enforcing_consecutive_5xx_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( config, enforcing_consecutive_5xx, DEFAULT_ENFORCING_CONSECUTIVE_5XX))), enforcing_consecutive_gateway_failure_(static_cast( @@ -236,10 +236,11 @@ DetectorConfig::DetectorConfig(const envoy::api::v2::cluster::OutlierDetection& DEFAULT_ENFORCING_CONSECUTIVE_GATEWAY_FAILURE))), enforcing_success_rate_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( config, enforcing_success_rate, DEFAULT_ENFORCING_SUCCESS_RATE))), - enforcing_failure_percentage_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, enforcing_failure_percentage, 0))), + enforcing_failure_percentage_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( + config, enforcing_failure_percentage, DEFAULT_ENFORCING_FAILURE_PERCENTAGE))), enforcing_failure_percentage_local_origin_(static_cast( - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, enforcing_failure_percentage_local_origin, 0))), + PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, enforcing_failure_percentage_local_origin, + DEFAULT_ENFORCING_FAILURE_PERCENTAGE_LOCAL_ORIGIN))), split_external_local_origin_errors_(config.split_external_local_origin_errors()), consecutive_local_origin_failure_(static_cast(PROTOBUF_GET_WRAPPED_OR_DEFAULT( config, consecutive_local_origin_failure, DEFAULT_CONSECUTIVE_LOCAL_ORIGIN_FAILURE))), diff --git a/source/common/upstream/outlier_detection_impl.h b/source/common/upstream/outlier_detection_impl.h index 6cee5f8a5f58..609df03355a0 100644 --- a/source/common/upstream/outlier_detection_impl.h +++ b/source/common/upstream/outlier_detection_impl.h @@ -302,9 +302,14 @@ class DetectorConfig { static const uint64_t DEFAULT_SUCCESS_RATE_MINIMUM_HOSTS = 5; static const uint64_t DEFAULT_SUCCESS_RATE_REQUEST_VOLUME = 100; static const uint64_t DEFAULT_SUCCESS_RATE_STDEV_FACTOR = 1900; + static const uint64_t DEFAULT_FAILURE_PERCENTAGE_THRESHOLD = 85; + static const uint64_t DEFAULT_FAILURE_PERCENTAGE_MINIMUM_HOSTS = 5; + static const uint64_t DEFAULT_FAILURE_PERCENTAGE_REQUEST_VOLUME = 50; static const uint64_t DEFAULT_ENFORCING_CONSECUTIVE_5XX = 100; static const uint64_t DEFAULT_ENFORCING_CONSECUTIVE_GATEWAY_FAILURE = 0; static const uint64_t DEFAULT_ENFORCING_SUCCESS_RATE = 100; + static const uint64_t DEFAULT_ENFORCING_FAILURE_PERCENTAGE = 0; + static const uint64_t DEFAULT_ENFORCING_FAILURE_PERCENTAGE_LOCAL_ORIGIN = 0; static const uint64_t DEFAULT_CONSECUTIVE_LOCAL_ORIGIN_FAILURE = 5; static const uint64_t DEFAULT_ENFORCING_CONSECUTIVE_LOCAL_ORIGIN_FAILURE = 100; static const uint64_t DEFAULT_ENFORCING_LOCAL_ORIGIN_SUCCESS_RATE = 100;