1 // 2 // Copyright 2018 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_CORE_EXT_FILTERS_CLIENT_CHANNEL_RETRY_SERVICE_CONFIG_H 18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RETRY_SERVICE_CONFIG_H 19 20 #include <grpc/support/port_platform.h> 21 22 #include <memory> 23 24 #include "src/core/ext/filters/client_channel/retry_throttle.h" 25 #include "src/core/ext/filters/client_channel/service_config_parser.h" 26 #include "src/core/lib/channel/status_util.h" 27 #include "src/core/lib/iomgr/exec_ctx.h" // for grpc_millis 28 29 namespace grpc_core { 30 namespace internal { 31 32 class RetryGlobalConfig : public ServiceConfigParser::ParsedConfig { 33 public: RetryGlobalConfig(intptr_t max_milli_tokens,intptr_t milli_token_ratio)34 RetryGlobalConfig(intptr_t max_milli_tokens, intptr_t milli_token_ratio) 35 : max_milli_tokens_(max_milli_tokens), 36 milli_token_ratio_(milli_token_ratio) {} 37 max_milli_tokens()38 intptr_t max_milli_tokens() const { return max_milli_tokens_; } milli_token_ratio()39 intptr_t milli_token_ratio() const { return milli_token_ratio_; } 40 41 private: 42 intptr_t max_milli_tokens_ = 0; 43 intptr_t milli_token_ratio_ = 0; 44 }; 45 46 class RetryMethodConfig : public ServiceConfigParser::ParsedConfig { 47 public: RetryMethodConfig(int max_attempts,grpc_millis initial_backoff,grpc_millis max_backoff,float backoff_multiplier,StatusCodeSet retryable_status_codes)48 RetryMethodConfig(int max_attempts, grpc_millis initial_backoff, 49 grpc_millis max_backoff, float backoff_multiplier, 50 StatusCodeSet retryable_status_codes) 51 : max_attempts_(max_attempts), 52 initial_backoff_(initial_backoff), 53 max_backoff_(max_backoff), 54 backoff_multiplier_(backoff_multiplier), 55 retryable_status_codes_(retryable_status_codes) {} 56 max_attempts()57 int max_attempts() const { return max_attempts_; } initial_backoff()58 grpc_millis initial_backoff() const { return initial_backoff_; } max_backoff()59 grpc_millis max_backoff() const { return max_backoff_; } backoff_multiplier()60 float backoff_multiplier() const { return backoff_multiplier_; } retryable_status_codes()61 StatusCodeSet retryable_status_codes() const { 62 return retryable_status_codes_; 63 } 64 65 private: 66 int max_attempts_ = 0; 67 grpc_millis initial_backoff_ = 0; 68 grpc_millis max_backoff_ = 0; 69 float backoff_multiplier_ = 0; 70 StatusCodeSet retryable_status_codes_; 71 }; 72 73 class RetryServiceConfigParser : public ServiceConfigParser::Parser { 74 public: 75 std::unique_ptr<ServiceConfigParser::ParsedConfig> ParseGlobalParams( 76 const grpc_channel_args* /*args*/, const Json& json, 77 grpc_error_handle* error) override; 78 79 std::unique_ptr<ServiceConfigParser::ParsedConfig> ParsePerMethodParams( 80 const grpc_channel_args* /*args*/, const Json& json, 81 grpc_error_handle* error) override; 82 83 static size_t ParserIndex(); 84 static void Register(); 85 }; 86 87 } // namespace internal 88 } // namespace grpc_core 89 90 #endif // GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RETRY_SERVICE_CONFIG_H 91