1 // 2 // Copyright 2022 gRPC authors. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef GRPC_SRC_CORE_LOAD_BALANCING_OUTLIER_DETECTION_OUTLIER_DETECTION_H 18 #define GRPC_SRC_CORE_LOAD_BALANCING_OUTLIER_DETECTION_OUTLIER_DETECTION_H 19 20 #include <grpc/support/port_platform.h> 21 #include <stdint.h> // for uint32_t 22 23 #include "absl/types/optional.h" 24 #include "src/core/util/json/json.h" 25 #include "src/core/util/json/json_args.h" 26 #include "src/core/util/json/json_object_loader.h" 27 #include "src/core/util/time.h" 28 #include "src/core/util/validation_errors.h" 29 30 namespace grpc_core { 31 32 struct OutlierDetectionConfig { 33 Duration interval = Duration::Seconds(10); 34 Duration base_ejection_time = Duration::Milliseconds(30000); 35 Duration max_ejection_time = Duration::Milliseconds(30000); 36 uint32_t max_ejection_percent = 10; 37 struct SuccessRateEjection { 38 uint32_t stdev_factor = 1900; 39 uint32_t enforcement_percentage = 100; 40 uint32_t minimum_hosts = 5; 41 uint32_t request_volume = 100; 42 SuccessRateEjectionOutlierDetectionConfig::SuccessRateEjection43 SuccessRateEjection() {} 44 45 bool operator==(const SuccessRateEjection& other) const { 46 return stdev_factor == other.stdev_factor && 47 enforcement_percentage == other.enforcement_percentage && 48 minimum_hosts == other.minimum_hosts && 49 request_volume == other.request_volume; 50 } 51 52 static const JsonLoaderInterface* JsonLoader(const JsonArgs&); 53 void JsonPostLoad(const Json&, const JsonArgs&, ValidationErrors* errors); 54 }; 55 struct FailurePercentageEjection { 56 uint32_t threshold = 85; 57 uint32_t enforcement_percentage = 100; 58 uint32_t minimum_hosts = 5; 59 uint32_t request_volume = 50; 60 FailurePercentageEjectionOutlierDetectionConfig::FailurePercentageEjection61 FailurePercentageEjection() {} 62 63 bool operator==(const FailurePercentageEjection& other) const { 64 return threshold == other.threshold && 65 enforcement_percentage == other.enforcement_percentage && 66 minimum_hosts == other.minimum_hosts && 67 request_volume == other.request_volume; 68 } 69 70 static const JsonLoaderInterface* JsonLoader(const JsonArgs&); 71 void JsonPostLoad(const Json&, const JsonArgs&, ValidationErrors* errors); 72 }; 73 absl::optional<SuccessRateEjection> success_rate_ejection; 74 absl::optional<FailurePercentageEjection> failure_percentage_ejection; 75 76 bool operator==(const OutlierDetectionConfig& other) const { 77 return interval == other.interval && 78 base_ejection_time == other.base_ejection_time && 79 max_ejection_time == other.max_ejection_time && 80 max_ejection_percent == other.max_ejection_percent && 81 success_rate_ejection == other.success_rate_ejection && 82 failure_percentage_ejection == other.failure_percentage_ejection; 83 } 84 85 static const JsonLoaderInterface* JsonLoader(const JsonArgs&); 86 void JsonPostLoad(const Json& json, const JsonArgs&, 87 ValidationErrors* errors); 88 }; 89 90 } // namespace grpc_core 91 92 #endif // GRPC_SRC_CORE_LOAD_BALANCING_OUTLIER_DETECTION_OUTLIER_DETECTION_H 93