config_selector.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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_CONFIG_SELECTOR_H
18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONFIG_SELECTOR_H
19 
21 
22 #include <string.h>
23 
24 #include <utility>
25 #include <vector>
26 
28 #include <grpc/slice.h>
29 #include <grpc/support/log.h>
30 
40 
41 // Channel arg key for ConfigSelector.
42 #define GRPC_ARG_CONFIG_SELECTOR "grpc.internal.config_selector"
43 
44 namespace grpc_core {
45 
46 // Internal API used to allow resolver implementations to override
47 // MethodConfig and provide input to LB policies on a per-call basis.
48 class ConfigSelector : public RefCounted<ConfigSelector> {
49  public:
50  // An interface to be used by the channel when dispatching calls.
52  public:
53  virtual ~CallDispatchController() = default;
54 
55  // Called by the channel to decide if it should retry the call upon a
56  // failure.
57  virtual bool ShouldRetry() = 0;
58 
59  // Called by the channel when no more LB picks will be performed for
60  // the call.
61  virtual void Commit() = 0;
62  };
63 
68  };
69 
70  struct CallConfig {
71  // Can be set to indicate the call should be failed.
73  // The per-method parsed configs that will be passed to
74  // ServiceConfigCallData.
76  // A ref to the service config that contains method_configs, held by
77  // the call to ensure that method_configs lives long enough.
79  // Call attributes that will be accessible to LB policy implementations.
81  // Call dispatch controller.
83  };
84 
85  ~ConfigSelector() override = default;
86 
87  virtual const char* name() const = 0;
88 
89  // Will be called only if the two objects have the same name, so
90  // subclasses can be free to safely down-cast the argument.
91  virtual bool Equals(const ConfigSelector* other) const = 0;
92 
93  static bool Equals(const ConfigSelector* cs1, const ConfigSelector* cs2) {
94  if (cs1 == nullptr) return cs2 == nullptr;
95  if (cs2 == nullptr) return false;
96  if (strcmp(cs1->name(), cs2->name()) != 0) return false;
97  return cs1->Equals(cs2);
98  }
99 
100  // The channel will call this when the resolver returns a new ConfigSelector
101  // to determine what set of dynamic filters will be configured.
102  virtual std::vector<const grpc_channel_filter*> GetFilters() { return {}; }
103  // Modifies channel args to be passed to the dynamic filter stack.
104  // Takes ownership of argument. Caller takes ownership of result.
106  return args;
107  }
108 
109  virtual CallConfig GetCallConfig(GetCallConfigArgs args) = 0;
110 
111  grpc_arg MakeChannelArg() const;
113  const grpc_channel_args& args);
114 };
115 
116 // Default ConfigSelector that gets the MethodConfig from the service config.
118  public:
120  : service_config_(std::move(service_config)) {
121  // The client channel code ensures that this will never be null.
122  // If neither the resolver nor the client application provide a
123  // config, a default empty config will be used.
124  GPR_DEBUG_ASSERT(service_config_ != nullptr);
125  }
126 
127  const char* name() const override { return "default"; }
128 
129  // Only comparing the ConfigSelector itself, not the underlying
130  // service config, so we always return true.
131  bool Equals(const ConfigSelector* /*other*/) const override { return true; }
132 
134  CallConfig call_config;
135  call_config.method_configs =
136  service_config_->GetMethodParsedConfigVector(*args.path);
137  call_config.service_config = service_config_;
138  return call_config;
139  }
140 
141  private:
143 };
144 
145 } // namespace grpc_core
146 
147 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONFIG_SELECTOR_H */
grpc_core::ConfigSelector::Equals
static bool Equals(const ConfigSelector *cs1, const ConfigSelector *cs2)
Definition: config_selector.h:93
grpc_arg
Definition: grpc_types.h:103
grpc_core::ConfigSelector::MakeChannelArg
grpc_arg MakeChannelArg() const
Definition: config_selector.cc:46
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
Definition: error.h:234
log.h
metadata_batch.h
channel_fwd.h
GPR_DEBUG_ASSERT
#define GPR_DEBUG_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:103
grpc_core::ConfigSelector::CallDispatchController::ShouldRetry
virtual bool ShouldRetry()=0
grpc_core::DefaultConfigSelector
Definition: config_selector.h:117
grpc_core::ConfigSelector::GetCallConfig
virtual CallConfig GetCallConfig(GetCallConfigArgs args)=0
slice.h
grpc_core::ConfigSelector::CallConfig::call_dispatch_controller
CallDispatchController * call_dispatch_controller
Definition: config_selector.h:82
grpc_core::ConfigSelector::GetCallConfigArgs::initial_metadata
grpc_metadata_batch * initial_metadata
Definition: config_selector.h:66
grpc_core
Definition: call_metric_recorder.h:31
string.h
grpc_core::DefaultConfigSelector::DefaultConfigSelector
DefaultConfigSelector(RefCountedPtr< ServiceConfig > service_config)
Definition: config_selector.h:119
arena.h
grpc_core::ServiceConfigParser::ParsedConfigVector
std::vector< std::unique_ptr< ParsedConfig > > ParsedConfigVector
Definition: lib/service_config/service_config_parser.h:77
grpc_core::ConfigSelector::name
virtual const char * name() const =0
grpc_core::ConfigSelector::~ConfigSelector
~ConfigSelector() override=default
grpc_core::Arena
Definition: src/core/lib/resource_quota/arena.h:45
grpc_channel_args
Definition: grpc_types.h:132
grpc_types.h
grpc_core::ConfigSelector::GetFromChannelArgs
static RefCountedPtr< ConfigSelector > GetFromChannelArgs(const grpc_channel_args &args)
Definition: config_selector.cc:52
grpc_core::ConfigSelector::CallConfig::method_configs
const ServiceConfigParser::ParsedConfigVector * method_configs
Definition: config_selector.h:75
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::ConfigSelector::CallDispatchController::~CallDispatchController
virtual ~CallDispatchController()=default
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_core::ConfigSelector::CallDispatchController::Commit
virtual void Commit()=0
grpc_core::DefaultConfigSelector::service_config_
RefCountedPtr< ServiceConfig > service_config_
Definition: config_selector.h:142
grpc_core::ConfigSelector::CallConfig::call_attributes
ServiceConfigCallData::CallAttributes call_attributes
Definition: config_selector.h:80
grpc_core::ConfigSelector::Equals
virtual bool Equals(const ConfigSelector *other) const =0
grpc_core::ConfigSelector::GetCallConfigArgs::path
grpc_slice * path
Definition: config_selector.h:65
service_config_call_data.h
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
error.h
grpc_core::RefCounted
Definition: ref_counted.h:280
grpc_core::ConfigSelector::CallConfig
Definition: config_selector.h:70
grpc_core::ServiceConfigCallData::CallAttributes
std::map< UniqueTypeName, absl::string_view > CallAttributes
Definition: service_config_call_data.h:43
service_config_parser.h
grpc_core::ConfigSelector::CallDispatchController
Definition: config_selector.h:51
ref_counted.h
grpc_core::ConfigSelector::GetCallConfigArgs
Definition: config_selector.h:64
grpc_core::ConfigSelector
Definition: config_selector.h:48
grpc_core::DefaultConfigSelector::name
const char * name() const override
Definition: config_selector.h:127
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc_core::ConfigSelector::ModifyChannelArgs
virtual grpc_channel_args * ModifyChannelArgs(grpc_channel_args *args)
Definition: config_selector.h:105
grpc_core::ConfigSelector::CallConfig::error
grpc_error_handle error
Definition: config_selector.h:72
ref_counted_ptr.h
grpc_core::DefaultConfigSelector::GetCallConfig
CallConfig GetCallConfig(GetCallConfigArgs args) override
Definition: config_selector.h:133
service_config.h
grpc_core::ConfigSelector::CallConfig::service_config
RefCountedPtr< ServiceConfig > service_config
Definition: config_selector.h:78
grpc_error
Definition: error_internal.h:42
grpc_metadata_batch
Definition: metadata_batch.h:1259
grpc_core::ConfigSelector::GetFilters
virtual std::vector< const grpc_channel_filter * > GetFilters()
Definition: config_selector.h:102
grpc_core::DefaultConfigSelector::Equals
bool Equals(const ConfigSelector *) const override
Definition: config_selector.h:131
grpc_core::ConfigSelector::GetCallConfigArgs::arena
Arena * arena
Definition: config_selector.h:67
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:52