GRPC C++  1.39.1
service_config_parser.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 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_FAULT_INJECTION_SERVICE_CONFIG_PARSER_H
18 #define GRPC_CORE_EXT_FILTERS_FAULT_INJECTION_SERVICE_CONFIG_PARSER_H
19 
21 
22 #include <vector>
23 
26 
27 namespace grpc_core {
28 
31  public:
34  std::string abort_message;
35  std::string abort_code_header;
39 
41  std::string delay_header;
45 
46  // By default, the max allowed active faults are unlimited.
47  uint32_t max_faults = std::numeric_limits<uint32_t>::max();
48  };
49 
51  std::vector<FaultInjectionPolicy> fault_injection_policies)
52  : fault_injection_policies_(std::move(fault_injection_policies)) {}
53 
54  // Returns the fault injection policy at certain index.
55  // There might be multiple fault injection policies functioning at the same
56  // time. The order between the policies are stable, and an index is used to
57  // keep track of their relative positions. The FaultInjectionFilter uses this
58  // method to access the parsed fault injection policy in service config,
59  // whether it came from xDS resolver or directly from service config
60  const FaultInjectionPolicy* fault_injection_policy(int index) const {
61  if (static_cast<size_t>(index) >= fault_injection_policies_.size()) {
62  return nullptr;
63  }
64  return &fault_injection_policies_[index];
65  }
66 
67  private:
68  std::vector<FaultInjectionPolicy> fault_injection_policies_;
69 };
70 
72  public:
73  // Parses the per-method service config for fault injection filter.
74  std::unique_ptr<ServiceConfigParser::ParsedConfig> ParsePerMethodParams(
75  const grpc_channel_args* args, const Json& json,
76  grpc_error_handle* error) override;
77  // Returns the parser index for FaultInjectionServiceConfigParser.
78  static size_t ParserIndex();
79  // Registers FaultInjectionServiceConfigParser to ServiceConfigParser.
80  static void Register();
81 };
82 
83 } // namespace grpc_core
84 
85 #endif // GRPC_CORE_EXT_FILTERS_FAULT_INJECTION_SERVICE_CONFIG_PARSER_H
Definition: service_config_parser.h:30
FaultInjectionMethodParsedConfig(std::vector< FaultInjectionPolicy > fault_injection_policies)
Definition: service_config_parser.h:50
const FaultInjectionPolicy * fault_injection_policy(int index) const
Definition: service_config_parser.h:60
Definition: service_config_parser.h:71
std::unique_ptr< ServiceConfigParser::ParsedConfig > ParsePerMethodParams(const grpc_channel_args *args, const Json &json, grpc_error_handle *error) override
Definition: service_config_parser.cc:154
static size_t ParserIndex()
Definition: service_config_parser.cc:185
static void Register()
Definition: service_config_parser.cc:180
Definition: json.h:38
This is the base class that all service config parsers MUST use to store parsed service config data.
Definition: service_config_parser.h:39
This is the base class that all service config parsers should derive from.
Definition: service_config_parser.h:45
int64_t grpc_millis
Definition: exec_ctx.h:37
grpc_status_code
Definition: status.h:26
@ GRPC_STATUS_OK
Not an error; returned on success.
Definition: status.h:28
grpc_error_handle error
Definition: lame_client.cc:54
Round Robin Policy.
Definition: backend_metric.cc:26
Definition: async_unary_call.h:398
An array of arguments that can be passed around.
Definition: grpc_types.h:132
grpc_millis delay
Definition: service_config_parser.h:40
std::string delay_percentage_header
Definition: service_config_parser.h:42
std::string abort_message
Definition: service_config_parser.h:34
uint32_t abort_percentage_denominator
Definition: service_config_parser.h:38
std::string abort_code_header
Definition: service_config_parser.h:35
uint32_t abort_percentage_numerator
Definition: service_config_parser.h:37
std::string abort_percentage_header
Definition: service_config_parser.h:36
std::string delay_header
Definition: service_config_parser.h:41
uint32_t max_faults
Definition: service_config_parser.h:47
uint32_t delay_percentage_numerator
Definition: service_config_parser.h:43
uint32_t delay_percentage_denominator
Definition: service_config_parser.h:44
grpc_status_code abort_code
Definition: service_config_parser.h:33
Definition: error_internal.h:41