• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_RESULT_PARSING_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_RESULT_PARSING_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include "absl/types/optional.h"
25 
26 #include "src/core/ext/filters/client_channel/lb_policy.h"
27 #include "src/core/ext/filters/client_channel/lb_policy_factory.h"
28 #include "src/core/ext/filters/client_channel/resolver.h"
29 #include "src/core/ext/filters/client_channel/retry_throttle.h"
30 #include "src/core/ext/filters/client_channel/service_config.h"
31 #include "src/core/lib/channel/status_util.h"
32 #include "src/core/lib/gprpp/ref_counted.h"
33 #include "src/core/lib/gprpp/ref_counted_ptr.h"
34 #include "src/core/lib/iomgr/exec_ctx.h"  // for grpc_millis
35 #include "src/core/lib/json/json.h"
36 
37 namespace grpc_core {
38 namespace internal {
39 
40 class ClientChannelGlobalParsedConfig
41     : public ServiceConfigParser::ParsedConfig {
42  public:
43   struct RetryThrottling {
44     intptr_t max_milli_tokens = 0;
45     intptr_t milli_token_ratio = 0;
46   };
47 
ClientChannelGlobalParsedConfig(RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config,std::string parsed_deprecated_lb_policy,const absl::optional<RetryThrottling> & retry_throttling,absl::optional<std::string> health_check_service_name)48   ClientChannelGlobalParsedConfig(
49       RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config,
50       std::string parsed_deprecated_lb_policy,
51       const absl::optional<RetryThrottling>& retry_throttling,
52       absl::optional<std::string> health_check_service_name)
53       : parsed_lb_config_(std::move(parsed_lb_config)),
54         parsed_deprecated_lb_policy_(std::move(parsed_deprecated_lb_policy)),
55         retry_throttling_(retry_throttling),
56         health_check_service_name_(std::move(health_check_service_name)) {}
57 
parsed_lb_config()58   RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config() const {
59     return parsed_lb_config_;
60   }
61 
parsed_deprecated_lb_policy()62   const std::string& parsed_deprecated_lb_policy() const {
63     return parsed_deprecated_lb_policy_;
64   }
65 
retry_throttling()66   absl::optional<RetryThrottling> retry_throttling() const {
67     return retry_throttling_;
68   }
69 
health_check_service_name()70   const absl::optional<std::string>& health_check_service_name() const {
71     return health_check_service_name_;
72   }
73 
74  private:
75   RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config_;
76   std::string parsed_deprecated_lb_policy_;
77   absl::optional<RetryThrottling> retry_throttling_;
78   absl::optional<std::string> health_check_service_name_;
79 };
80 
81 class ClientChannelMethodParsedConfig
82     : public ServiceConfigParser::ParsedConfig {
83  public:
84   struct RetryPolicy {
85     int max_attempts = 0;
86     grpc_millis initial_backoff = 0;
87     grpc_millis max_backoff = 0;
88     float backoff_multiplier = 0;
89     StatusCodeSet retryable_status_codes;
90   };
91 
ClientChannelMethodParsedConfig(grpc_millis timeout,const absl::optional<bool> & wait_for_ready,std::unique_ptr<RetryPolicy> retry_policy)92   ClientChannelMethodParsedConfig(grpc_millis timeout,
93                                   const absl::optional<bool>& wait_for_ready,
94                                   std::unique_ptr<RetryPolicy> retry_policy)
95       : timeout_(timeout),
96         wait_for_ready_(wait_for_ready),
97         retry_policy_(std::move(retry_policy)) {}
98 
timeout()99   grpc_millis timeout() const { return timeout_; }
100 
wait_for_ready()101   absl::optional<bool> wait_for_ready() const { return wait_for_ready_; }
102 
retry_policy()103   const RetryPolicy* retry_policy() const { return retry_policy_.get(); }
104 
105  private:
106   grpc_millis timeout_ = 0;
107   absl::optional<bool> wait_for_ready_;
108   std::unique_ptr<RetryPolicy> retry_policy_;
109 };
110 
111 class ClientChannelServiceConfigParser : public ServiceConfigParser::Parser {
112  public:
113   std::unique_ptr<ServiceConfigParser::ParsedConfig> ParseGlobalParams(
114       const grpc_channel_args* /*args*/, const Json& json,
115       grpc_error** error) override;
116 
117   std::unique_ptr<ServiceConfigParser::ParsedConfig> ParsePerMethodParams(
118       const grpc_channel_args* /*args*/, const Json& json,
119       grpc_error** error) override;
120 
121   static size_t ParserIndex();
122   static void Register();
123 };
124 
125 }  // namespace internal
126 }  // namespace grpc_core
127 
128 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_RESULT_PARSING_H */
129