Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service config parser to core configuration #28883

Merged
merged 28 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
90cae9c
Service config parser to core configuration
ctiller Feb 15, 2022
8acedaa
x
ctiller Feb 15, 2022
9fe96bb
Automated change: Fix sanity tests
ctiller Feb 15, 2022
08d27ef
Merge pull request #444 from ctiller/create-pull-request/patch-8aceda…
ctiller Feb 15, 2022
f5189dd
Merge github.com:grpc/grpc into parserconfig
ctiller Feb 15, 2022
7c0be93
finish
ctiller Feb 15, 2022
7e0911b
Automated change: Fix sanity tests
ctiller Feb 15, 2022
2793e49
oops
ctiller Feb 15, 2022
da08716
fix race
ctiller Feb 15, 2022
bc429b8
Automated change: Fix sanity tests
ctiller Feb 15, 2022
807c260
Merge pull request #450 from ctiller/create-pull-request/patch-da0871…
ctiller Feb 15, 2022
8dca475
Merge pull request #446 from ctiller/create-pull-request/patch-7c0be9…
ctiller Feb 16, 2022
bb72aa9
Merge github.com:grpc/grpc into parserconfig
ctiller Feb 16, 2022
b9ab1c8
Merge github.com:grpc/grpc into parserconfig
ctiller Feb 22, 2022
033ddf0
Merge github.com:grpc/grpc into parserconfig
ctiller Feb 22, 2022
1abfebc
back out mutex
ctiller Feb 22, 2022
c150254
refactor
ctiller Feb 23, 2022
71d24af
optimize
ctiller Feb 23, 2022
98cfe19
Automated change: Fix sanity tests
ctiller Feb 23, 2022
964e475
Merge pull request #461 from ctiller/create-pull-request/patch-71d24a…
ctiller Feb 23, 2022
33238cb
fix
ctiller Feb 23, 2022
e8783a1
Merge branch 'parserconfig' of github.com:ctiller/grpc into parserconfig
ctiller Feb 23, 2022
707ce1b
fix
ctiller Feb 23, 2022
a532e21
Merge github.com:grpc/grpc into parserconfig
ctiller Feb 23, 2022
5d1055e
split out interface
ctiller Feb 23, 2022
d79852c
review feedback
ctiller Feb 23, 2022
934a9f8
x
ctiller Feb 23, 2022
cbe78b7
fixes
ctiller Feb 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
optimize
  • Loading branch information
ctiller committed Feb 23, 2022
commit 71d24af0f9def09062970124f66abfabdef6bb34
7 changes: 5 additions & 2 deletions src/core/ext/filters/client_channel/client_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "resolver_result_parsing.h"

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
Expand Down Expand Up @@ -1036,6 +1037,8 @@ ClientChannel::ClientChannel(grpc_channel_element_args* args,
ClientChannelFactory::GetFromChannelArgs(args->channel_args)),
channelz_node_(GetChannelzNode(args->channel_args)),
interested_parties_(grpc_pollset_set_create()),
service_config_parser_index_(
internal::ClientChannelServiceConfigParser::ParserIndex()),
work_serializer_(std::make_shared<WorkSerializer>()),
state_tracker_("client_channel", GRPC_CHANNEL_IDLE),
subchannel_pool_(GetSubchannelPool(args->channel_args)) {
Expand Down Expand Up @@ -1275,7 +1278,7 @@ void ClientChannel::OnResolverResultChangedLocked(Resolver::Result result) {
const internal::ClientChannelGlobalParsedConfig* parsed_service_config =
static_cast<const internal::ClientChannelGlobalParsedConfig*>(
service_config->GetGlobalParsedConfig(
internal::ClientChannelServiceConfigParser::ParserIndex()));
service_config_parser_index_));
// Choose LB policy config.
RefCountedPtr<LoadBalancingPolicy::Config> lb_policy_config =
ChooseLbPolicy(result, parsed_service_config);
Expand Down Expand Up @@ -2220,7 +2223,7 @@ grpc_error_handle ClientChannel::CallData::ApplyServiceConfigToCallLocked(
// Apply our own method params to the call.
auto* method_params = static_cast<ClientChannelMethodParsedConfig*>(
service_config_call_data->GetMethodParsedConfig(
internal::ClientChannelServiceConfigParser::ParserIndex()));
chand->service_config_parser_index_));
if (method_params != nullptr) {
// If the deadline from the service config is shorter than the one
// from the client API, reset the deadline timer.
Expand Down
1 change: 1 addition & 0 deletions src/core/ext/filters/client_channel/client_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class ClientChannel {
std::string default_authority_;
channelz::ChannelNode* channelz_node_;
grpc_pollset_set* interested_parties_;
const size_t service_config_parser_index_;

//
// Fields related to name resolution. Guarded by resolution_mu_.
Expand Down
16 changes: 11 additions & 5 deletions src/core/ext/filters/client_channel/retry_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "absl/container/inlined_vector.h"
#include "absl/status/statusor.h"
#include "absl/strings/strip.h"
#include "retry_service_config.h"

#include <grpc/status.h>
#include <grpc/support/log.h>
Expand Down Expand Up @@ -145,7 +146,9 @@ class RetryFilter {
RetryFilter(const grpc_channel_args* args, grpc_error_handle* error)
: client_channel_(grpc_channel_args_find_pointer<ClientChannel>(
args, GRPC_ARG_CLIENT_CHANNEL)),
per_rpc_retry_buffer_size_(GetMaxPerRpcRetryBufferSize(args)) {
per_rpc_retry_buffer_size_(GetMaxPerRpcRetryBufferSize(args)),
service_config_parser_index_(
internal::RetryServiceConfigParser::ParserIndex()) {
// Get retry throttling parameters from service config.
auto* service_config = grpc_channel_args_find_pointer<ServiceConfig>(
args, GRPC_ARG_SERVICE_CONFIG_OBJ);
Expand Down Expand Up @@ -175,9 +178,13 @@ class RetryFilter {
server_name, config->max_milli_tokens(), config->milli_token_ratio());
}

const RetryMethodConfig* GetRetryPolicy(
const grpc_call_context_element* context);

ClientChannel* client_channel_;
size_t per_rpc_retry_buffer_size_;
RefCountedPtr<ServerRetryThrottleData> retry_throttle_data_;
const size_t service_config_parser_index_;
};

//
Expand Down Expand Up @@ -2049,22 +2056,21 @@ void RetryFilter::CallData::SetPollent(grpc_call_element* elem,
// CallData implementation
//

const RetryMethodConfig* GetRetryPolicy(
const RetryMethodConfig* RetryFilter::GetRetryPolicy(
const grpc_call_context_element* context) {
if (context == nullptr) return nullptr;
auto* svc_cfg_call_data = static_cast<ServiceConfigCallData*>(
context[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value);
if (svc_cfg_call_data == nullptr) return nullptr;
return static_cast<const RetryMethodConfig*>(
svc_cfg_call_data->GetMethodParsedConfig(
RetryServiceConfigParser::ParserIndex()));
svc_cfg_call_data->GetMethodParsedConfig(service_config_parser_index_));
}

RetryFilter::CallData::CallData(RetryFilter* chand,
const grpc_call_element_args& args)
: chand_(chand),
retry_throttle_data_(chand->retry_throttle_data_),
retry_policy_(GetRetryPolicy(args.context)),
retry_policy_(chand->GetRetryPolicy(args.context)),
retry_backoff_(
BackOff::Options()
.set_initial_backoff(retry_policy_ == nullptr
Expand Down
13 changes: 10 additions & 3 deletions src/core/ext/filters/fault_injection/fault_injection_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <atomic>

#include "absl/strings/numbers.h"
#include "service_config_parser.h"

#include <grpc/status.h>
#include <grpc/support/alloc.h>
Expand Down Expand Up @@ -69,13 +70,17 @@ class ChannelData {
static void Destroy(grpc_channel_element* elem);

int index() const { return index_; }
size_t service_config_parser_index() const {
return service_config_parser_index_;
}

private:
ChannelData(grpc_channel_element* elem, grpc_channel_element_args* args);
~ChannelData() = default;

// The relative index of instances of the same filter.
int index_;
const size_t service_config_parser_index_;
};

class CallData {
Expand Down Expand Up @@ -170,8 +175,10 @@ void ChannelData::Destroy(grpc_channel_element* elem) {

ChannelData::ChannelData(grpc_channel_element* elem,
grpc_channel_element_args* args)
: index_(grpc_channel_stack_filter_instance_number(args->channel_stack,
elem)) {}
: index_(
grpc_channel_stack_filter_instance_number(args->channel_stack, elem)),
service_config_parser_index_(
FaultInjectionServiceConfigParser::ParserIndex()) {}

// CallData::ResumeBatchCanceller

Expand Down Expand Up @@ -294,7 +301,7 @@ CallData::CallData(grpc_call_element* elem, const grpc_call_element_args* args)
args->context[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value);
auto* method_params = static_cast<FaultInjectionMethodParsedConfig*>(
service_config_call_data->GetMethodParsedConfig(
FaultInjectionServiceConfigParser::ParserIndex()));
chand->service_config_parser_index()));
if (method_params != nullptr) {
fi_policy_ = method_params->fault_injection_policy(chand->index());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ namespace {
class ChannelData {
public:
explicit ChannelData(const grpc_channel_element_args* args)
: max_recv_size_(GetMaxRecvSizeFromChannelArgs(args->channel_args)) {}
: max_recv_size_(GetMaxRecvSizeFromChannelArgs(args->channel_args)),
message_size_service_config_parser_index_(
MessageSizeParser::ParserIndex()) {}

int max_recv_size() const { return max_recv_size_; }
size_t message_size_service_config_parser_index() const {
return message_size_service_config_parser_index_;
}

private:
int max_recv_size_;
const size_t message_size_service_config_parser_index_;
};

class CallData {
Expand All @@ -73,7 +79,8 @@ class CallData {
OnRecvTrailingMetadataReady, this,
grpc_schedule_on_exec_ctx);
const MessageSizeParsedConfig* limits =
MessageSizeParsedConfig::GetFromCallContext(args.context);
MessageSizeParsedConfig::GetFromCallContext(
args.context, chand->message_size_service_config_parser_index());
if (limits != nullptr && limits->limits().max_recv_size >= 0 &&
(limits->limits().max_recv_size < max_recv_message_length_ ||
max_recv_message_length_ < 0)) {
Expand Down
12 changes: 8 additions & 4 deletions src/core/ext/filters/message_size/message_size_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string.h>

#include "absl/strings/str_format.h"
#include "message_size_filter.h"

#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/support/alloc.h>
Expand All @@ -47,14 +48,14 @@ namespace grpc_core {
//

const MessageSizeParsedConfig* MessageSizeParsedConfig::GetFromCallContext(
const grpc_call_context_element* context) {
const grpc_call_context_element* context,
size_t service_config_parser_index) {
if (context == nullptr) return nullptr;
auto* svc_cfg_call_data = static_cast<ServiceConfigCallData*>(
context[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value);
if (svc_cfg_call_data == nullptr) return nullptr;
return static_cast<const MessageSizeParsedConfig*>(
svc_cfg_call_data->GetMethodParsedConfig(
MessageSizeParser::ParserIndex()));
svc_cfg_call_data->GetMethodParsedConfig(service_config_parser_index));
}

//
Expand Down Expand Up @@ -138,6 +139,8 @@ int GetMaxSendSizeFromChannelArgs(const grpc_channel_args* args) {
namespace {
struct channel_data {
grpc_core::MessageSizeParsedConfig::message_size_limits limits;
const size_t service_config_parser_index{
grpc_core::MessageSizeParser::ParserIndex()};
};

struct call_data {
Expand All @@ -154,7 +157,8 @@ struct call_data {
// apply the max request size to the send limit and the max response
// size to the receive limit.
const grpc_core::MessageSizeParsedConfig* limits =
grpc_core::MessageSizeParsedConfig::GetFromCallContext(args.context);
grpc_core::MessageSizeParsedConfig::GetFromCallContext(
args.context, chand.service_config_parser_index);
if (limits != nullptr) {
if (limits->limits().max_send_size >= 0 &&
(limits->limits().max_send_size < this->limits.max_send_size ||
Expand Down
3 changes: 2 additions & 1 deletion src/core/ext/filters/message_size/message_size_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class MessageSizeParsedConfig : public ServiceConfigParser::ParsedConfig {
const message_size_limits& limits() const { return limits_; }

static const MessageSizeParsedConfig* GetFromCallContext(
const grpc_call_context_element* context);
const grpc_call_context_element* context,
size_t service_config_parser_index);

private:
message_size_limits limits_;
Expand Down
3 changes: 3 additions & 0 deletions src/core/ext/filters/rbac/rbac_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "src/core/ext/filters/rbac/rbac_filter.h"

#include "rbac_service_config_parser.h"

#include "src/core/ext/filters/rbac/rbac_service_config_parser.h"
#include "src/core/lib/security/authorization/grpc_authorization_engine.h"
#include "src/core/lib/service_config/service_config_call_data.h"
Expand Down Expand Up @@ -125,6 +127,7 @@ const grpc_channel_filter RbacFilter::kFilterVtable = {
RbacFilter::RbacFilter(size_t index,
EvaluateArgs::PerChannelArgs per_channel_evaluate_args)
: index_(index),
service_config_parser_index_(RbacServiceConfigParser::ParserIndex()),
markdroth marked this conversation as resolved.
Show resolved Hide resolved
per_channel_evaluate_args_(std::move(per_channel_evaluate_args)) {}

grpc_error_handle RbacFilter::Init(grpc_channel_element* elem,
Expand Down
2 changes: 2 additions & 0 deletions src/core/ext/filters/rbac/rbac_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class RbacFilter {

// The index of this filter instance among instances of the same filter.
size_t index_;
// Assigned index for service config data from the parser.
const size_t service_config_parser_index_;
// Per channel args used for authorization.
EvaluateArgs::PerChannelArgs per_channel_evaluate_args_;
};
Expand Down