Clean up some names in the service config code.

pull/19028/head
Mark D. Roth 6 years ago
parent 0df4cb1bdc
commit 356e7c2107
  1. 26
      src/core/ext/filters/client_channel/client_channel.cc
  2. 14
      src/core/ext/filters/client_channel/resolver_result_parsing.cc
  3. 8
      src/core/ext/filters/client_channel/resolver_result_parsing.h
  4. 42
      src/core/ext/filters/client_channel/service_config.cc
  5. 54
      src/core/ext/filters/client_channel/service_config.h
  6. 24
      src/core/ext/filters/message_size/message_size_filter.cc
  7. 4
      src/core/ext/filters/message_size/message_size_filter.h
  8. 2
      src/core/lib/channel/context.h
  9. 144
      test/core/client_channel/service_config_test.cc

@ -66,7 +66,7 @@
#include "src/core/lib/transport/static_metadata.h"
#include "src/core/lib/transport/status_metadata.h"
using grpc_core::internal::ClientChannelMethodParsedObject;
using grpc_core::internal::ClientChannelMethodParsedConfig;
using grpc_core::internal::ServerRetryThrottleData;
//
@ -234,7 +234,7 @@ class ChannelData {
void ProcessLbPolicy(
const Resolver::Result& resolver_result,
const internal::ClientChannelGlobalParsedObject* parsed_service_config,
const internal::ClientChannelGlobalParsedConfig* parsed_service_config,
UniquePtr<char>* lb_policy_name,
RefCountedPtr<ParsedLoadBalancingConfig>* lb_policy_config);
@ -629,7 +629,7 @@ class CallData {
RefCountedPtr<ServerRetryThrottleData> retry_throttle_data_;
ServiceConfig::CallData service_config_call_data_;
const ClientChannelMethodParsedObject* method_params_ = nullptr;
const ClientChannelMethodParsedConfig* method_params_ = nullptr;
RefCountedPtr<SubchannelCall> subchannel_call_;
@ -772,7 +772,7 @@ class ChannelData::ServiceConfigSetter {
public:
ServiceConfigSetter(
ChannelData* chand,
Optional<internal::ClientChannelGlobalParsedObject::RetryThrottling>
Optional<internal::ClientChannelGlobalParsedConfig::RetryThrottling>
retry_throttle_data,
RefCountedPtr<ServiceConfig> service_config)
: chand_(chand),
@ -811,7 +811,7 @@ class ChannelData::ServiceConfigSetter {
}
ChannelData* chand_;
Optional<internal::ClientChannelGlobalParsedObject::RetryThrottling>
Optional<internal::ClientChannelGlobalParsedConfig::RetryThrottling>
retry_throttle_data_;
RefCountedPtr<ServiceConfig> service_config_;
grpc_closure closure_;
@ -1141,7 +1141,7 @@ ChannelData::~ChannelData() {
void ChannelData::ProcessLbPolicy(
const Resolver::Result& resolver_result,
const internal::ClientChannelGlobalParsedObject* parsed_service_config,
const internal::ClientChannelGlobalParsedConfig* parsed_service_config,
UniquePtr<char>* lb_policy_name,
RefCountedPtr<ParsedLoadBalancingConfig>* lb_policy_config) {
// Prefer the LB policy name found in the service config.
@ -1238,12 +1238,12 @@ bool ChannelData::ProcessResolverResultLocked(
}
// Process service config.
UniquePtr<char> service_config_json;
const internal::ClientChannelGlobalParsedObject* parsed_service_config =
const internal::ClientChannelGlobalParsedConfig* parsed_service_config =
nullptr;
if (service_config != nullptr) {
parsed_service_config =
static_cast<const internal::ClientChannelGlobalParsedObject*>(
service_config->GetParsedGlobalServiceConfigObject(
static_cast<const internal::ClientChannelGlobalParsedConfig*>(
service_config->GetGlobalParsedConfig(
internal::ClientChannelServiceConfigParser::ParserIndex()));
}
// TODO(roth): Eliminate this hack as part of hiding health check
@ -1282,7 +1282,7 @@ bool ChannelData::ProcessResolverResultLocked(
// if we feel it is unnecessary.
if (service_config_changed || !chand->received_first_resolver_result_) {
chand->received_first_resolver_result_ = true;
Optional<internal::ClientChannelGlobalParsedObject::RetryThrottling>
Optional<internal::ClientChannelGlobalParsedConfig::RetryThrottling>
retry_throttle_data;
if (parsed_service_config != nullptr) {
retry_throttle_data = parsed_service_config->retry_throttling();
@ -3245,10 +3245,10 @@ void CallData::ApplyServiceConfigToCallLocked(grpc_call_element* elem) {
service_config_call_data_ =
ServiceConfig::CallData(chand->service_config(), path_);
if (service_config_call_data_.service_config() != nullptr) {
call_context_[GRPC_SERVICE_CONFIG_CALL_DATA].value =
call_context_[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value =
&service_config_call_data_;
method_params_ = static_cast<ClientChannelMethodParsedObject*>(
service_config_call_data_.GetMethodParsedObject(
method_params_ = static_cast<ClientChannelMethodParsedConfig*>(
service_config_call_data_.GetMethodParsedConfig(
internal::ClientChannelServiceConfigParser::ParserIndex()));
}
retry_throttle_data_ = chand->retry_throttle_data();

@ -92,11 +92,11 @@ bool ParseDuration(grpc_json* field, grpc_millis* duration) {
return true;
}
UniquePtr<ClientChannelMethodParsedObject::RetryPolicy> ParseRetryPolicy(
UniquePtr<ClientChannelMethodParsedConfig::RetryPolicy> ParseRetryPolicy(
grpc_json* field, grpc_error** error) {
GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
auto retry_policy =
MakeUnique<ClientChannelMethodParsedObject::RetryPolicy>();
MakeUnique<ClientChannelMethodParsedConfig::RetryPolicy>();
if (field->type != GRPC_JSON_OBJECT) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"field:retryPolicy error:should be of type object");
@ -270,7 +270,7 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const grpc_json* json,
InlinedVector<grpc_error*, 4> error_list;
RefCountedPtr<ParsedLoadBalancingConfig> parsed_lb_config;
UniquePtr<char> lb_policy_name;
Optional<ClientChannelGlobalParsedObject::RetryThrottling> retry_throttling;
Optional<ClientChannelGlobalParsedConfig::RetryThrottling> retry_throttling;
const char* health_check_service_name = nullptr;
for (grpc_json* field = json->child; field != nullptr; field = field->next) {
if (field->key == nullptr) {
@ -409,7 +409,7 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const grpc_json* json,
}
}
}
ClientChannelGlobalParsedObject::RetryThrottling data;
ClientChannelGlobalParsedConfig::RetryThrottling data;
if (!max_milli_tokens.has_value()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"field:retryThrottling field:maxTokens error:Not found"));
@ -440,7 +440,7 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const grpc_json* json,
&error_list);
if (*error == GRPC_ERROR_NONE) {
return UniquePtr<ServiceConfig::ParsedConfig>(
New<ClientChannelGlobalParsedObject>(
New<ClientChannelGlobalParsedConfig>(
std::move(parsed_lb_config), std::move(lb_policy_name),
retry_throttling, health_check_service_name));
}
@ -454,7 +454,7 @@ ClientChannelServiceConfigParser::ParsePerMethodParams(const grpc_json* json,
InlinedVector<grpc_error*, 4> error_list;
Optional<bool> wait_for_ready;
grpc_millis timeout = 0;
UniquePtr<ClientChannelMethodParsedObject::RetryPolicy> retry_policy;
UniquePtr<ClientChannelMethodParsedConfig::RetryPolicy> retry_policy;
for (grpc_json* field = json->child; field != nullptr; field = field->next) {
if (field->key == nullptr) continue;
if (strcmp(field->key, "waitForReady") == 0) {
@ -494,7 +494,7 @@ ClientChannelServiceConfigParser::ParsePerMethodParams(const grpc_json* json,
*error = GRPC_ERROR_CREATE_FROM_VECTOR("Client channel parser", &error_list);
if (*error == GRPC_ERROR_NONE) {
return UniquePtr<ServiceConfig::ParsedConfig>(
New<ClientChannelMethodParsedObject>(timeout, wait_for_ready,
New<ClientChannelMethodParsedConfig>(timeout, wait_for_ready,
std::move(retry_policy)));
}
return nullptr;

@ -37,14 +37,14 @@
namespace grpc_core {
namespace internal {
class ClientChannelGlobalParsedObject : public ServiceConfig::ParsedConfig {
class ClientChannelGlobalParsedConfig : public ServiceConfig::ParsedConfig {
public:
struct RetryThrottling {
intptr_t max_milli_tokens = 0;
intptr_t milli_token_ratio = 0;
};
ClientChannelGlobalParsedObject(
ClientChannelGlobalParsedConfig(
RefCountedPtr<ParsedLoadBalancingConfig> parsed_lb_config,
UniquePtr<char> parsed_deprecated_lb_policy,
const Optional<RetryThrottling>& retry_throttling,
@ -77,7 +77,7 @@ class ClientChannelGlobalParsedObject : public ServiceConfig::ParsedConfig {
const char* health_check_service_name_;
};
class ClientChannelMethodParsedObject : public ServiceConfig::ParsedConfig {
class ClientChannelMethodParsedConfig : public ServiceConfig::ParsedConfig {
public:
struct RetryPolicy {
int max_attempts = 0;
@ -87,7 +87,7 @@ class ClientChannelMethodParsedObject : public ServiceConfig::ParsedConfig {
StatusCodeSet retryable_status_codes;
};
ClientChannelMethodParsedObject(grpc_millis timeout,
ClientChannelMethodParsedConfig(grpc_millis timeout,
const Optional<bool>& wait_for_ready,
UniquePtr<RetryPolicy> retry_policy)
: timeout_(timeout),

@ -96,16 +96,15 @@ grpc_error* ServiceConfig::ParseGlobalParams(const grpc_json* json_tree) {
if (parser_error != GRPC_ERROR_NONE) {
error_list.push_back(parser_error);
}
parsed_global_service_config_objects_.push_back(std::move(parsed_obj));
parsed_global_configs_.push_back(std::move(parsed_obj));
}
return GRPC_ERROR_CREATE_FROM_VECTOR("Global Params", &error_list);
}
grpc_error* ServiceConfig::ParseJsonMethodConfigToServiceConfigObjectsTable(
grpc_error* ServiceConfig::ParseJsonMethodConfigToServiceConfigVectorTable(
const grpc_json* json,
SliceHashTable<const ServiceConfigObjectsVector*>::Entry* entries,
size_t* idx) {
auto objs_vector = MakeUnique<ServiceConfigObjectsVector>();
SliceHashTable<const ParsedConfigVector*>::Entry* entries, size_t* idx) {
auto objs_vector = MakeUnique<ParsedConfigVector>();
InlinedVector<grpc_error*, 4> error_list;
for (size_t i = 0; i < g_registered_parsers->size(); i++) {
grpc_error* parser_error = GRPC_ERROR_NONE;
@ -116,10 +115,10 @@ grpc_error* ServiceConfig::ParseJsonMethodConfigToServiceConfigObjectsTable(
}
objs_vector->push_back(std::move(parsed_obj));
}
service_config_objects_vectors_storage_.push_back(std::move(objs_vector));
parsed_method_config_vectors_storage_.push_back(std::move(objs_vector));
const auto* vector_ptr =
service_config_objects_vectors_storage_
[service_config_objects_vectors_storage_.size() - 1]
parsed_method_config_vectors_storage_
[parsed_method_config_vectors_storage_.size() - 1]
.get();
// Construct list of paths.
InlinedVector<UniquePtr<char>, 10> paths;
@ -160,7 +159,7 @@ wrap_error:
grpc_error* ServiceConfig::ParsePerMethodParams(const grpc_json* json_tree) {
GPR_DEBUG_ASSERT(json_tree_->type == GRPC_JSON_OBJECT);
GPR_DEBUG_ASSERT(json_tree_->key == nullptr);
SliceHashTable<const ServiceConfigObjectsVector*>::Entry* entries = nullptr;
SliceHashTable<const ParsedConfigVector*>::Entry* entries = nullptr;
size_t num_entries = 0;
InlinedVector<grpc_error*, 4> error_list;
for (grpc_json* field = json_tree->child; field != nullptr;
@ -187,14 +186,13 @@ grpc_error* ServiceConfig::ParsePerMethodParams(const grpc_json* json_tree) {
}
num_entries += static_cast<size_t>(count);
}
entries = static_cast<
SliceHashTable<const ServiceConfigObjectsVector*>::Entry*>(gpr_zalloc(
num_entries *
sizeof(SliceHashTable<const ServiceConfigObjectsVector*>::Entry)));
entries = static_cast<SliceHashTable<const ParsedConfigVector*>::Entry*>(
gpr_zalloc(num_entries *
sizeof(SliceHashTable<const ParsedConfigVector*>::Entry)));
size_t idx = 0;
for (grpc_json* method = field->child; method != nullptr;
method = method->next) {
grpc_error* error = ParseJsonMethodConfigToServiceConfigObjectsTable(
grpc_error* error = ParseJsonMethodConfigToServiceConfigVectorTable(
method, entries, &idx);
if (error != GRPC_ERROR_NONE) {
error_list.push_back(error);
@ -206,9 +204,9 @@ grpc_error* ServiceConfig::ParsePerMethodParams(const grpc_json* json_tree) {
}
}
if (entries != nullptr) {
parsed_method_service_config_objects_table_ =
SliceHashTable<const ServiceConfigObjectsVector*>::Create(
num_entries, entries, nullptr);
parsed_method_configs_table_ =
SliceHashTable<const ParsedConfigVector*>::Create(num_entries, entries,
nullptr);
gpr_free(entries);
}
return GRPC_ERROR_CREATE_FROM_VECTOR("Method Params", &error_list);
@ -287,12 +285,12 @@ UniquePtr<char> ServiceConfig::ParseJsonMethodName(grpc_json* json,
return UniquePtr<char>(path);
}
const ServiceConfig::ServiceConfigObjectsVector*
ServiceConfig::GetMethodServiceConfigObjectsVector(const grpc_slice& path) {
if (parsed_method_service_config_objects_table_.get() == nullptr) {
const ServiceConfig::ParsedConfigVector*
ServiceConfig::GetMethodParsedConfigVector(const grpc_slice& path) {
if (parsed_method_configs_table_.get() == nullptr) {
return nullptr;
}
const auto* value = parsed_method_service_config_objects_table_->Get(path);
const auto* value = parsed_method_configs_table_->Get(path);
// If we didn't find a match for the path, try looking for a wildcard
// entry (i.e., change "/service/method" to "/service/*").
if (value == nullptr) {
@ -305,7 +303,7 @@ ServiceConfig::GetMethodServiceConfigObjectsVector(const grpc_slice& path) {
buf[len + 1] = '\0';
grpc_slice wildcard_path = grpc_slice_from_copied_string(buf);
gpr_free(buf);
value = parsed_method_service_config_objects_table_->Get(wildcard_path);
value = parsed_method_configs_table_->Get(wildcard_path);
grpc_slice_unref_internal(wildcard_path);
gpr_free(path_str);
if (value == nullptr) return nullptr;

@ -88,7 +88,7 @@ class ServiceConfig : public RefCounted<ServiceConfig> {
static constexpr int kNumPreallocatedParsers = 4;
typedef InlinedVector<UniquePtr<ParsedConfig>, kNumPreallocatedParsers>
ServiceConfigObjectsVector;
ParsedConfigVector;
/// When a service config is applied to a call in the client_channel_filter,
/// we create an instance of this object and store it in the call_data for
@ -102,25 +102,25 @@ class ServiceConfig : public RefCounted<ServiceConfig> {
: service_config_(std::move(svc_cfg)) {
if (service_config_ != nullptr) {
method_params_vector_ =
service_config_->GetMethodServiceConfigObjectsVector(path);
service_config_->GetMethodParsedConfigVector(path);
}
}
ServiceConfig* service_config() { return service_config_.get(); }
ParsedConfig* GetMethodParsedObject(size_t index) const {
ParsedConfig* GetMethodParsedConfig(size_t index) const {
return method_params_vector_ != nullptr
? (*method_params_vector_)[index].get()
: nullptr;
}
ParsedConfig* GetGlobalParsedObject(size_t index) const {
return service_config_->GetParsedGlobalServiceConfigObject(index);
ParsedConfig* GetGlobalParsedConfig(size_t index) const {
return service_config_->GetGlobalParsedConfig(index);
}
private:
RefCountedPtr<ServiceConfig> service_config_;
const ServiceConfigObjectsVector* method_params_vector_ = nullptr;
const ParsedConfigVector* method_params_vector_ = nullptr;
};
/// Creates a new service config from parsing \a json_string.
@ -132,25 +132,24 @@ class ServiceConfig : public RefCounted<ServiceConfig> {
const char* service_config_json() const { return service_config_json_.get(); }
/// Retrieves the parsed global service config object at index \a index. The
/// Retrieves the global parsed config at index \a index. The
/// lifetime of the returned object is tied to the lifetime of the
/// ServiceConfig object.
ParsedConfig* GetParsedGlobalServiceConfigObject(size_t index) {
GPR_DEBUG_ASSERT(index < parsed_global_service_config_objects_.size());
return parsed_global_service_config_objects_[index].get();
ParsedConfig* GetGlobalParsedConfig(size_t index) {
GPR_DEBUG_ASSERT(index < parsed_global_configs_.size());
return parsed_global_configs_[index].get();
}
/// Retrieves the vector of method service config objects for a given path \a
/// path. The lifetime of the returned vector and contained objects is tied to
/// the lifetime of the ServiceConfig object.
const ServiceConfigObjectsVector* GetMethodServiceConfigObjectsVector(
const grpc_slice& path);
/// Retrieves the vector of parsed configs for the method identified
/// by \a path. The lifetime of the returned vector and contained objects
/// is tied to the lifetime of the ServiceConfig object.
const ParsedConfigVector* GetMethodParsedConfigVector(const grpc_slice& path);
/// Globally register a service config parser. On successful registration, it
/// returns the index at which the parser was registered. On failure, -1 is
/// returned. Each new service config update will go through all the
/// registered parser. Each parser is responsible for reading the service
/// config json and returning a parsed object. This parsed object can later be
/// config json and returning a parsed config. This parsed config can later be
/// retrieved using the same index that was returned at registration time.
static size_t RegisterParser(UniquePtr<Parser> parser);
@ -180,26 +179,25 @@ class ServiceConfig : public RefCounted<ServiceConfig> {
static UniquePtr<char> ParseJsonMethodName(grpc_json* json,
grpc_error** error);
grpc_error* ParseJsonMethodConfigToServiceConfigObjectsTable(
grpc_error* ParseJsonMethodConfigToServiceConfigVectorTable(
const grpc_json* json,
SliceHashTable<const ServiceConfigObjectsVector*>::Entry* entries,
size_t* idx);
SliceHashTable<const ParsedConfigVector*>::Entry* entries, size_t* idx);
UniquePtr<char> service_config_json_;
UniquePtr<char> json_string_; // Underlying storage for json_tree.
grpc_json* json_tree_;
InlinedVector<UniquePtr<ParsedConfig>, kNumPreallocatedParsers>
parsed_global_service_config_objects_;
// A map from the method name to the service config objects vector. Note that
// we are using a raw pointer and not a unique pointer so that we can use the
// same vector for multiple names.
RefCountedPtr<SliceHashTable<const ServiceConfigObjectsVector*>>
parsed_method_service_config_objects_table_;
parsed_global_configs_;
// A map from the method name to the parsed config vector. Note that we are
// using a raw pointer and not a unique pointer so that we can use the same
// vector for multiple names.
RefCountedPtr<SliceHashTable<const ParsedConfigVector*>>
parsed_method_configs_table_;
// Storage for all the vectors that are being used in
// parsed_method_service_config_objects_table_.
InlinedVector<UniquePtr<ServiceConfigObjectsVector>, 32>
service_config_objects_vectors_storage_;
// parsed_method_configs_table_.
InlinedVector<UniquePtr<ParsedConfigVector>, 32>
parsed_method_config_vectors_storage_;
};
} // namespace grpc_core

@ -88,7 +88,7 @@ UniquePtr<ServiceConfig::ParsedConfig> MessageSizeParser::ParsePerMethodParams(
*error = GRPC_ERROR_CREATE_FROM_VECTOR("Message size parser", &error_list);
return nullptr;
}
return UniquePtr<ServiceConfig::ParsedConfig>(New<MessageSizeParsedObject>(
return UniquePtr<ServiceConfig::ParsedConfig>(New<MessageSizeParsedConfig>(
max_request_message_bytes, max_response_message_bytes));
}
@ -102,7 +102,7 @@ size_t MessageSizeParser::ParserIndex() { return g_message_size_parser_index; }
namespace {
struct channel_data {
grpc_core::MessageSizeParsedObject::message_size_limits limits;
grpc_core::MessageSizeParsedConfig::message_size_limits limits;
grpc_core::RefCountedPtr<grpc_core::ServiceConfig> svc_cfg;
};
@ -119,21 +119,21 @@ struct call_data {
// Note: Per-method config is only available on the client, so we
// apply the max request size to the send limit and the max response
// size to the receive limit.
const grpc_core::MessageSizeParsedObject* limits = nullptr;
const grpc_core::MessageSizeParsedConfig* limits = nullptr;
grpc_core::ServiceConfig::CallData* svc_cfg_call_data = nullptr;
if (args.context != nullptr) {
svc_cfg_call_data = static_cast<grpc_core::ServiceConfig::CallData*>(
args.context[GRPC_SERVICE_CONFIG_CALL_DATA].value);
args.context[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value);
}
if (svc_cfg_call_data != nullptr) {
limits = static_cast<const grpc_core::MessageSizeParsedObject*>(
svc_cfg_call_data->GetMethodParsedObject(
limits = static_cast<const grpc_core::MessageSizeParsedConfig*>(
svc_cfg_call_data->GetMethodParsedConfig(
grpc_core::MessageSizeParser::ParserIndex()));
} else if (chand.svc_cfg != nullptr) {
const auto* objs_vector =
chand.svc_cfg->GetMethodServiceConfigObjectsVector(args.path);
chand.svc_cfg->GetMethodParsedConfigVector(args.path);
if (objs_vector != nullptr) {
limits = static_cast<const grpc_core::MessageSizeParsedObject*>(
limits = static_cast<const grpc_core::MessageSizeParsedConfig*>(
(*objs_vector)[grpc_core::MessageSizeParser::ParserIndex()].get());
}
}
@ -154,7 +154,7 @@ struct call_data {
~call_data() { GRPC_ERROR_UNREF(error); }
grpc_core::CallCombiner* call_combiner;
grpc_core::MessageSizeParsedObject::message_size_limits limits;
grpc_core::MessageSizeParsedConfig::message_size_limits limits;
// Receive closures are chained: we inject this closure as the
// recv_message_ready up-call on transport_stream_op, and remember to
// call our next_recv_message_ready member after handling it.
@ -300,9 +300,9 @@ static int default_size(const grpc_channel_args* args,
return without_minimal_stack;
}
grpc_core::MessageSizeParsedObject::message_size_limits get_message_size_limits(
grpc_core::MessageSizeParsedConfig::message_size_limits get_message_size_limits(
const grpc_channel_args* channel_args) {
grpc_core::MessageSizeParsedObject::message_size_limits lim;
grpc_core::MessageSizeParsedConfig::message_size_limits lim;
lim.max_send_size =
default_size(channel_args, GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH);
lim.max_recv_size =
@ -392,7 +392,7 @@ static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder,
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
bool enable = false;
grpc_core::MessageSizeParsedObject::message_size_limits lim =
grpc_core::MessageSizeParsedConfig::message_size_limits lim =
get_message_size_limits(channel_args);
if (lim.max_send_size != -1 || lim.max_recv_size != -1) {
enable = true;

@ -26,14 +26,14 @@ extern const grpc_channel_filter grpc_message_size_filter;
namespace grpc_core {
class MessageSizeParsedObject : public ServiceConfig::ParsedConfig {
class MessageSizeParsedConfig : public ServiceConfig::ParsedConfig {
public:
struct message_size_limits {
int max_send_size;
int max_recv_size;
};
MessageSizeParsedObject(int max_send_size, int max_recv_size) {
MessageSizeParsedConfig(int max_send_size, int max_recv_size) {
limits_.max_send_size = max_send_size;
limits_.max_recv_size = max_recv_size;
}

@ -36,7 +36,7 @@ typedef enum {
GRPC_CONTEXT_TRAFFIC,
/// Holds a pointer to ServiceConfig::CallData associated with this call.
GRPC_SERVICE_CONFIG_CALL_DATA,
GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA,
GRPC_CONTEXT_COUNT
} grpc_context_index;

@ -31,9 +31,9 @@
namespace grpc_core {
namespace testing {
class TestParsedObject1 : public ServiceConfig::ParsedConfig {
class TestParsedConfig1 : public ServiceConfig::ParsedConfig {
public:
TestParsedObject1(int value) : value_(value) {}
TestParsedConfig1(int value) : value_(value) {}
int value() const { return value_; }
@ -61,7 +61,7 @@ class TestParser1 : public ServiceConfig::Parser {
return nullptr;
}
return UniquePtr<ServiceConfig::ParsedConfig>(
New<TestParsedObject1>(value));
New<TestParsedConfig1>(value));
}
}
return nullptr;
@ -99,7 +99,7 @@ class TestParser2 : public ServiceConfig::Parser {
return nullptr;
}
return UniquePtr<ServiceConfig::ParsedConfig>(
New<TestParsedObject1>(value));
New<TestParsedConfig1>(value));
}
}
return nullptr;
@ -216,10 +216,10 @@ TEST_F(ServiceConfigTest, Parser1BasicTest1) {
grpc_error* error = GRPC_ERROR_NONE;
auto svc_cfg = ServiceConfig::Create(test_json, &error);
ASSERT_TRUE(error == GRPC_ERROR_NONE);
EXPECT_TRUE((static_cast<TestParsedObject1*>(
svc_cfg->GetParsedGlobalServiceConfigObject(0)))
->value() == 5);
EXPECT_TRUE(svc_cfg->GetMethodServiceConfigObjectsVector(
EXPECT_TRUE(
(static_cast<TestParsedConfig1*>(svc_cfg->GetGlobalParsedConfig(0)))
->value() == 5);
EXPECT_TRUE(svc_cfg->GetMethodParsedConfigVector(
grpc_slice_from_static_string("/TestServ/TestMethod")) ==
nullptr);
}
@ -229,9 +229,9 @@ TEST_F(ServiceConfigTest, Parser1BasicTest2) {
grpc_error* error = GRPC_ERROR_NONE;
auto svc_cfg = ServiceConfig::Create(test_json, &error);
ASSERT_TRUE(error == GRPC_ERROR_NONE);
EXPECT_TRUE((static_cast<TestParsedObject1*>(
svc_cfg->GetParsedGlobalServiceConfigObject(0)))
->value() == 1000);
EXPECT_TRUE(
(static_cast<TestParsedConfig1*>(svc_cfg->GetGlobalParsedConfig(0)))
->value() == 1000);
}
TEST_F(ServiceConfigTest, Parser1ErrorInvalidType) {
@ -267,11 +267,11 @@ TEST_F(ServiceConfigTest, Parser2BasicTest) {
grpc_error* error = GRPC_ERROR_NONE;
auto svc_cfg = ServiceConfig::Create(test_json, &error);
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* vector_ptr = svc_cfg->GetMethodServiceConfigObjectsVector(
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector(
grpc_slice_from_static_string("/TestServ/TestMethod"));
EXPECT_TRUE(vector_ptr != nullptr);
auto parsed_object = ((*vector_ptr)[1]).get();
EXPECT_TRUE(static_cast<TestParsedObject1*>(parsed_object)->value() == 5);
auto parsed_config = ((*vector_ptr)[1]).get();
EXPECT_TRUE(static_cast<TestParsedConfig1*>(parsed_config)->value() == 5);
}
TEST_F(ServiceConfigTest, Parser2ErrorInvalidType) {
@ -371,10 +371,10 @@ TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigPickFirst) {
grpc_error* error = GRPC_ERROR_NONE;
auto svc_cfg = ServiceConfig::Create(test_json, &error);
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* parsed_object =
static_cast<grpc_core::internal::ClientChannelGlobalParsedObject*>(
svc_cfg->GetParsedGlobalServiceConfigObject(0));
auto lb_config = parsed_object->parsed_lb_config();
const auto* parsed_config =
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>(
svc_cfg->GetGlobalParsedConfig(0));
auto lb_config = parsed_config->parsed_lb_config();
EXPECT_TRUE(strcmp(lb_config->name(), "pick_first") == 0);
}
@ -384,10 +384,10 @@ TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigRoundRobin) {
grpc_error* error = GRPC_ERROR_NONE;
auto svc_cfg = ServiceConfig::Create(test_json, &error);
ASSERT_TRUE(error == GRPC_ERROR_NONE);
auto parsed_object =
static_cast<grpc_core::internal::ClientChannelGlobalParsedObject*>(
svc_cfg->GetParsedGlobalServiceConfigObject(0));
auto lb_config = parsed_object->parsed_lb_config();
auto parsed_config =
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>(
svc_cfg->GetGlobalParsedConfig(0));
auto lb_config = parsed_config->parsed_lb_config();
EXPECT_TRUE(strcmp(lb_config->name(), "round_robin") == 0);
}
@ -398,10 +398,10 @@ TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigGrpclb) {
grpc_error* error = GRPC_ERROR_NONE;
auto svc_cfg = ServiceConfig::Create(test_json, &error);
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* parsed_object =
static_cast<grpc_core::internal::ClientChannelGlobalParsedObject*>(
svc_cfg->GetParsedGlobalServiceConfigObject(0));
auto lb_config = parsed_object->parsed_lb_config();
const auto* parsed_config =
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>(
svc_cfg->GetGlobalParsedConfig(0));
auto lb_config = parsed_config->parsed_lb_config();
EXPECT_TRUE(strcmp(lb_config->name(), "grpclb") == 0);
}
@ -417,10 +417,10 @@ TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigXds) {
auto svc_cfg = ServiceConfig::Create(test_json, &error);
gpr_log(GPR_ERROR, "%s", grpc_error_string(error));
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* parsed_object =
static_cast<grpc_core::internal::ClientChannelGlobalParsedObject*>(
svc_cfg->GetParsedGlobalServiceConfigObject(0));
auto lb_config = parsed_object->parsed_lb_config();
const auto* parsed_config =
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>(
svc_cfg->GetGlobalParsedConfig(0));
auto lb_config = parsed_config->parsed_lb_config();
EXPECT_TRUE(strcmp(lb_config->name(), "xds_experimental") == 0);
}
@ -484,10 +484,10 @@ TEST_F(ClientChannelParserTest, ValidLoadBalancingPolicy) {
grpc_error* error = GRPC_ERROR_NONE;
auto svc_cfg = ServiceConfig::Create(test_json, &error);
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* parsed_object =
static_cast<grpc_core::internal::ClientChannelGlobalParsedObject*>(
svc_cfg->GetParsedGlobalServiceConfigObject(0));
const auto* lb_policy = parsed_object->parsed_deprecated_lb_policy();
const auto* parsed_config =
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>(
svc_cfg->GetGlobalParsedConfig(0));
const auto* lb_policy = parsed_config->parsed_deprecated_lb_policy();
ASSERT_TRUE(lb_policy != nullptr);
EXPECT_TRUE(strcmp(lb_policy, "pick_first") == 0);
}
@ -498,10 +498,10 @@ TEST_F(ClientChannelParserTest, ValidLoadBalancingPolicyAllCaps) {
auto svc_cfg = ServiceConfig::Create(test_json, &error);
gpr_log(GPR_ERROR, "%s", grpc_error_string(error));
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* parsed_object =
static_cast<grpc_core::internal::ClientChannelGlobalParsedObject*>(
svc_cfg->GetParsedGlobalServiceConfigObject(0));
const auto* lb_policy = parsed_object->parsed_deprecated_lb_policy();
const auto* parsed_config =
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>(
svc_cfg->GetGlobalParsedConfig(0));
const auto* lb_policy = parsed_config->parsed_deprecated_lb_policy();
ASSERT_TRUE(lb_policy != nullptr);
EXPECT_TRUE(strcmp(lb_policy, "pick_first") == 0);
}
@ -549,10 +549,10 @@ TEST_F(ClientChannelParserTest, ValidRetryThrottling) {
auto svc_cfg = ServiceConfig::Create(test_json, &error);
gpr_log(GPR_ERROR, "%s", grpc_error_string(error));
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* parsed_object =
static_cast<grpc_core::internal::ClientChannelGlobalParsedObject*>(
svc_cfg->GetParsedGlobalServiceConfigObject(0));
const auto retryThrottling = parsed_object->retry_throttling();
const auto* parsed_config =
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>(
svc_cfg->GetGlobalParsedConfig(0));
const auto retryThrottling = parsed_config->retry_throttling();
ASSERT_TRUE(retryThrottling.has_value());
EXPECT_EQ(retryThrottling.value().max_milli_tokens, 2000);
EXPECT_EQ(retryThrottling.value().milli_token_ratio, 1000);
@ -633,12 +633,12 @@ TEST_F(ClientChannelParserTest, ValidTimeout) {
grpc_error* error = GRPC_ERROR_NONE;
auto svc_cfg = ServiceConfig::Create(test_json, &error);
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* vector_ptr = svc_cfg->GetMethodServiceConfigObjectsVector(
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector(
grpc_slice_from_static_string("/TestServ/TestMethod"));
EXPECT_TRUE(vector_ptr != nullptr);
auto parsed_object = ((*vector_ptr)[0]).get();
EXPECT_EQ((static_cast<grpc_core::internal::ClientChannelMethodParsedObject*>(
parsed_object))
auto parsed_config = ((*vector_ptr)[0]).get();
EXPECT_EQ((static_cast<grpc_core::internal::ClientChannelMethodParsedConfig*>(
parsed_config))
->timeout(),
5000);
}
@ -680,18 +680,18 @@ TEST_F(ClientChannelParserTest, ValidWaitForReady) {
grpc_error* error = GRPC_ERROR_NONE;
auto svc_cfg = ServiceConfig::Create(test_json, &error);
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* vector_ptr = svc_cfg->GetMethodServiceConfigObjectsVector(
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector(
grpc_slice_from_static_string("/TestServ/TestMethod"));
EXPECT_TRUE(vector_ptr != nullptr);
auto parsed_object = ((*vector_ptr)[0]).get();
auto parsed_config = ((*vector_ptr)[0]).get();
EXPECT_TRUE(
(static_cast<grpc_core::internal::ClientChannelMethodParsedObject*>(
parsed_object))
(static_cast<grpc_core::internal::ClientChannelMethodParsedConfig*>(
parsed_config))
->wait_for_ready()
.has_value());
EXPECT_TRUE(
(static_cast<grpc_core::internal::ClientChannelMethodParsedObject*>(
parsed_object))
(static_cast<grpc_core::internal::ClientChannelMethodParsedConfig*>(
parsed_config))
->wait_for_ready()
.value());
}
@ -740,18 +740,18 @@ TEST_F(ClientChannelParserTest, ValidRetryPolicy) {
auto svc_cfg = ServiceConfig::Create(test_json, &error);
gpr_log(GPR_ERROR, "%s", grpc_error_string(error));
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* vector_ptr = svc_cfg->GetMethodServiceConfigObjectsVector(
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector(
grpc_slice_from_static_string("/TestServ/TestMethod"));
EXPECT_TRUE(vector_ptr != nullptr);
const auto* parsed_object =
static_cast<grpc_core::internal::ClientChannelMethodParsedObject*>(
const auto* parsed_config =
static_cast<grpc_core::internal::ClientChannelMethodParsedConfig*>(
((*vector_ptr)[0]).get());
EXPECT_TRUE(parsed_object->retry_policy() != nullptr);
EXPECT_EQ(parsed_object->retry_policy()->max_attempts, 3);
EXPECT_EQ(parsed_object->retry_policy()->initial_backoff, 1000);
EXPECT_EQ(parsed_object->retry_policy()->max_backoff, 120000);
EXPECT_EQ(parsed_object->retry_policy()->backoff_multiplier, 1.6f);
EXPECT_TRUE(parsed_object->retry_policy()->retryable_status_codes.Contains(
EXPECT_TRUE(parsed_config->retry_policy() != nullptr);
EXPECT_EQ(parsed_config->retry_policy()->max_attempts, 3);
EXPECT_EQ(parsed_config->retry_policy()->initial_backoff, 1000);
EXPECT_EQ(parsed_config->retry_policy()->max_backoff, 120000);
EXPECT_EQ(parsed_config->retry_policy()->backoff_multiplier, 1.6f);
EXPECT_TRUE(parsed_config->retry_policy()->retryable_status_codes.Contains(
GRPC_STATUS_ABORTED));
}
@ -915,11 +915,11 @@ TEST_F(ClientChannelParserTest, ValidHealthCheck) {
grpc_error* error = GRPC_ERROR_NONE;
auto svc_cfg = ServiceConfig::Create(test_json, &error);
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* parsed_object =
static_cast<grpc_core::internal::ClientChannelGlobalParsedObject*>(
svc_cfg->GetParsedGlobalServiceConfigObject(0));
ASSERT_TRUE(parsed_object != nullptr);
EXPECT_EQ(strcmp(parsed_object->health_check_service_name(),
const auto* parsed_config =
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>(
svc_cfg->GetGlobalParsedConfig(0));
ASSERT_TRUE(parsed_config != nullptr);
EXPECT_EQ(strcmp(parsed_config->health_check_service_name(),
"health_check_service_name"),
0);
}
@ -974,14 +974,14 @@ TEST_F(MessageSizeParserTest, Valid) {
auto svc_cfg = ServiceConfig::Create(test_json, &error);
gpr_log(GPR_ERROR, "%s", grpc_error_string(error));
ASSERT_TRUE(error == GRPC_ERROR_NONE);
const auto* vector_ptr = svc_cfg->GetMethodServiceConfigObjectsVector(
const auto* vector_ptr = svc_cfg->GetMethodParsedConfigVector(
grpc_slice_from_static_string("/TestServ/TestMethod"));
EXPECT_TRUE(vector_ptr != nullptr);
auto parsed_object =
static_cast<MessageSizeParsedObject*>(((*vector_ptr)[0]).get());
ASSERT_TRUE(parsed_object != nullptr);
EXPECT_EQ(parsed_object->limits().max_send_size, 1024);
EXPECT_EQ(parsed_object->limits().max_recv_size, 1024);
auto parsed_config =
static_cast<MessageSizeParsedConfig*>(((*vector_ptr)[0]).get());
ASSERT_TRUE(parsed_config != nullptr);
EXPECT_EQ(parsed_config->limits().max_send_size, 1024);
EXPECT_EQ(parsed_config->limits().max_recv_size, 1024);
}
TEST_F(MessageSizeParserTest, InvalidMaxRequestMessageBytes) {

Loading…
Cancel
Save