Compare commits

...

16 Commits

Author SHA1 Message Date
GitHub Actions 6850f92e68 Update artifacts branch 3 days ago
GitHub Actions 5306e3715f Update artifacts branch 3 days ago
GitHub Actions d7a320f210 Update artifacts branch 4 days ago
GitHub Actions e299ed2084 Update artifacts branch 4 days ago
GitHub Actions 8e83673c81 Update artifacts branch 4 days ago
GitHub Actions e215205c9f Update artifacts branch 4 days ago
GitHub Actions dd70ccef8f Update artifacts branch 4 days ago
GitHub Actions d5e4d441b6 Update artifacts branch 5 days ago
GitHub Actions 3819d75176 Update artifacts branch 5 days ago
GitHub Actions ba69f0f514 Update artifacts branch 5 days ago
GitHub Actions 8615f61c8c Update artifacts branch 6 days ago
GitHub Actions fcb6d06e01 Update artifacts branch 6 days ago
GitHub Actions 1a25667628 Update artifacts branch 7 days ago
GitHub Actions f7aa6e7d32 Update artifacts branch 7 days ago
GitHub Actions b159a513dc Update artifacts branch 7 days ago
GitHub Actions 1223be0886 Update artifacts branch 7 days ago
  1. 2
      .source-revision
  2. 142
      src/core/lib/config/config_vars.cc
  3. 121
      src/core/lib/config/config_vars.h
  4. 122
      src/core/lib/config/config_vars.yaml
  5. 49
      src/core/lib/config/config_vars_non_generated.cc
  6. 112
      src/core/lib/config/core_configuration.cc
  7. 244
      src/core/lib/config/core_configuration.h
  8. 79
      src/core/lib/config/load_config.cc
  9. 55
      src/core/lib/config/load_config.h
  10. 2
      third_party/benchmark
  11. 2
      third_party/opentelemetry-cpp

@ -1 +1 @@
7f535a6b2b001107ae3337c4241995ba3315bfe2
7570d8b5450e12f6aa7cba46439d565982e911c9

@ -1,142 +0,0 @@
// Copyright 2023 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Automatically generated by tools/codegen/core/gen_config_vars.py
//
#include "src/core/lib/config/config_vars.h"
#include "absl/flags/flag.h"
#include "absl/strings/escaping.h"
#include <grpc/support/port_platform.h>
#include "src/core/lib/config/load_config.h"
#ifndef GPR_DEFAULT_LOG_VERBOSITY_STRING
#define GPR_DEFAULT_LOG_VERBOSITY_STRING ""
#endif // !GPR_DEFAULT_LOG_VERBOSITY_STRING
#ifdef GRPC_ENABLE_FORK_SUPPORT
#define GRPC_ENABLE_FORK_SUPPORT_DEFAULT true
#else
#define GRPC_ENABLE_FORK_SUPPORT_DEFAULT false
#endif // GRPC_ENABLE_FORK_SUPPORT
ABSL_FLAG(std::vector<std::string>, grpc_experiments, {},
"A comma separated list of currently active experiments. Experiments "
"may be prefixed with a '-' to disable them.");
ABSL_FLAG(absl::optional<int32_t>, grpc_client_channel_backup_poll_interval_ms,
{},
"Declares the interval in ms between two backup polls on client "
"channels. These polls are run in the timer thread so that gRPC can "
"process connection failures while there is no active polling "
"thread. They help reconnect disconnected client channels (mostly "
"due to idleness), so that the next RPC on this channel won't fail. "
"Set to 0 to turn off the backup polls.");
ABSL_FLAG(absl::optional<std::string>, grpc_dns_resolver, {},
"Declares which DNS resolver to use. The default is ares if gRPC is "
"built with c-ares support. Otherwise, the value of this environment "
"variable is ignored.");
ABSL_FLAG(std::vector<std::string>, grpc_trace, {},
"A comma separated list of tracers that provide additional insight "
"into how gRPC C core is processing requests via debug logs.");
ABSL_FLAG(absl::optional<std::string>, grpc_verbosity, {},
"Logging verbosity.");
ABSL_FLAG(absl::optional<bool>, grpc_enable_fork_support, {},
"Enable fork support");
ABSL_FLAG(absl::optional<std::string>, grpc_poll_strategy, {},
"Declares which polling engines to try when starting gRPC. This is a "
"comma-separated list of engines, which are tried in priority order "
"first -> last.");
ABSL_FLAG(absl::optional<bool>, grpc_abort_on_leaks, {},
"A debugging aid to cause a call to abort() when gRPC objects are "
"leaked past grpc_shutdown()");
ABSL_FLAG(absl::optional<std::string>, grpc_system_ssl_roots_dir, {},
"Custom directory to SSL Roots");
ABSL_FLAG(absl::optional<std::string>, grpc_default_ssl_roots_file_path, {},
"Path to the default SSL roots file.");
ABSL_FLAG(absl::optional<bool>, grpc_not_use_system_ssl_roots, {},
"Disable loading system root certificates.");
ABSL_FLAG(absl::optional<std::string>, grpc_ssl_cipher_suites, {},
"A colon separated list of cipher suites to use with OpenSSL");
namespace grpc_core {
ConfigVars::ConfigVars(const Overrides& overrides)
: client_channel_backup_poll_interval_ms_(
LoadConfig(FLAGS_grpc_client_channel_backup_poll_interval_ms,
"GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS",
overrides.client_channel_backup_poll_interval_ms, 5000)),
enable_fork_support_(LoadConfig(
FLAGS_grpc_enable_fork_support, "GRPC_ENABLE_FORK_SUPPORT",
overrides.enable_fork_support, GRPC_ENABLE_FORK_SUPPORT_DEFAULT)),
abort_on_leaks_(LoadConfig(FLAGS_grpc_abort_on_leaks,
"GRPC_ABORT_ON_LEAKS",
overrides.abort_on_leaks, false)),
not_use_system_ssl_roots_(LoadConfig(
FLAGS_grpc_not_use_system_ssl_roots, "GRPC_NOT_USE_SYSTEM_SSL_ROOTS",
overrides.not_use_system_ssl_roots, false)),
dns_resolver_(LoadConfig(FLAGS_grpc_dns_resolver, "GRPC_DNS_RESOLVER",
overrides.dns_resolver, "")),
verbosity_(LoadConfig(FLAGS_grpc_verbosity, "GRPC_VERBOSITY",
overrides.verbosity,
GPR_DEFAULT_LOG_VERBOSITY_STRING)),
poll_strategy_(LoadConfig(FLAGS_grpc_poll_strategy, "GRPC_POLL_STRATEGY",
overrides.poll_strategy, "all")),
ssl_cipher_suites_(LoadConfig(
FLAGS_grpc_ssl_cipher_suites, "GRPC_SSL_CIPHER_SUITES",
overrides.ssl_cipher_suites,
"TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_"
"SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:"
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384")),
experiments_(LoadConfig(FLAGS_grpc_experiments, "GRPC_EXPERIMENTS",
overrides.experiments, "")),
trace_(LoadConfig(FLAGS_grpc_trace, "GRPC_TRACE", overrides.trace, "")),
override_system_ssl_roots_dir_(overrides.system_ssl_roots_dir),
override_default_ssl_roots_file_path_(
overrides.default_ssl_roots_file_path) {}
std::string ConfigVars::SystemSslRootsDir() const {
return LoadConfig(FLAGS_grpc_system_ssl_roots_dir,
"GRPC_SYSTEM_SSL_ROOTS_DIR", override_system_ssl_roots_dir_,
"");
}
std::string ConfigVars::DefaultSslRootsFilePath() const {
return LoadConfig(FLAGS_grpc_default_ssl_roots_file_path,
"GRPC_DEFAULT_SSL_ROOTS_FILE_PATH",
override_default_ssl_roots_file_path_, "");
}
std::string ConfigVars::ToString() const {
return absl::StrCat(
"experiments: ", "\"", absl::CEscape(Experiments()), "\"",
", client_channel_backup_poll_interval_ms: ",
ClientChannelBackupPollIntervalMs(), ", dns_resolver: ", "\"",
absl::CEscape(DnsResolver()), "\"", ", trace: ", "\"",
absl::CEscape(Trace()), "\"", ", verbosity: ", "\"",
absl::CEscape(Verbosity()), "\"",
", enable_fork_support: ", EnableForkSupport() ? "true" : "false",
", poll_strategy: ", "\"", absl::CEscape(PollStrategy()), "\"",
", abort_on_leaks: ", AbortOnLeaks() ? "true" : "false",
", system_ssl_roots_dir: ", "\"", absl::CEscape(SystemSslRootsDir()),
"\"", ", default_ssl_roots_file_path: ", "\"",
absl::CEscape(DefaultSslRootsFilePath()), "\"",
", not_use_system_ssl_roots: ", NotUseSystemSslRoots() ? "true" : "false",
", ssl_cipher_suites: ", "\"", absl::CEscape(SslCipherSuites()), "\"");
}
} // namespace grpc_core

@ -1,121 +0,0 @@
// Copyright 2023 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Automatically generated by tools/codegen/core/gen_config_vars.py
//
#ifndef GRPC_SRC_CORE_LIB_CONFIG_CONFIG_VARS_H
#define GRPC_SRC_CORE_LIB_CONFIG_CONFIG_VARS_H
#include <stdint.h>
#include <atomic>
#include <string>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include <grpc/support/port_platform.h>
namespace grpc_core {
class GPR_DLL ConfigVars {
public:
struct Overrides {
absl::optional<int32_t> client_channel_backup_poll_interval_ms;
absl::optional<bool> enable_fork_support;
absl::optional<bool> abort_on_leaks;
absl::optional<bool> not_use_system_ssl_roots;
absl::optional<std::string> dns_resolver;
absl::optional<std::string> verbosity;
absl::optional<std::string> poll_strategy;
absl::optional<std::string> system_ssl_roots_dir;
absl::optional<std::string> default_ssl_roots_file_path;
absl::optional<std::string> ssl_cipher_suites;
absl::optional<std::string> experiments;
absl::optional<std::string> trace;
};
ConfigVars(const ConfigVars&) = delete;
ConfigVars& operator=(const ConfigVars&) = delete;
// Get the core configuration; if it does not exist, create it.
static const ConfigVars& Get() {
auto* p = config_vars_.load(std::memory_order_acquire);
if (p != nullptr) return *p;
return Load();
}
static void SetOverrides(const Overrides& overrides);
// Drop the config vars. Users must ensure no other threads are
// accessing the configuration.
static void Reset();
std::string ToString() const;
// A comma separated list of currently active experiments. Experiments may be
// prefixed with a '-' to disable them.
absl::string_view Experiments() const { return experiments_; }
// Declares the interval in ms between two backup polls on client channels.
// These polls are run in the timer thread so that gRPC can process connection
// failures while there is no active polling thread. They help reconnect
// disconnected client channels (mostly due to idleness), so that the next RPC
// on this channel won't fail. Set to 0 to turn off the backup polls.
int32_t ClientChannelBackupPollIntervalMs() const {
return client_channel_backup_poll_interval_ms_;
}
// Declares which DNS resolver to use. The default is ares if gRPC is built
// with c-ares support. Otherwise, the value of this environment variable is
// ignored.
absl::string_view DnsResolver() const { return dns_resolver_; }
// A comma separated list of tracers that provide additional insight into how
// gRPC C core is processing requests via debug logs.
absl::string_view Trace() const { return trace_; }
// Logging verbosity.
absl::string_view Verbosity() const { return verbosity_; }
// Enable fork support
bool EnableForkSupport() const { return enable_fork_support_; }
// Declares which polling engines to try when starting gRPC. This is a
// comma-separated list of engines, which are tried in priority order first ->
// last.
absl::string_view PollStrategy() const { return poll_strategy_; }
// A debugging aid to cause a call to abort() when gRPC objects are leaked
// past grpc_shutdown()
bool AbortOnLeaks() const { return abort_on_leaks_; }
// Custom directory to SSL Roots
std::string SystemSslRootsDir() const;
// Path to the default SSL roots file.
std::string DefaultSslRootsFilePath() const;
// Disable loading system root certificates.
bool NotUseSystemSslRoots() const { return not_use_system_ssl_roots_; }
// A colon separated list of cipher suites to use with OpenSSL
absl::string_view SslCipherSuites() const { return ssl_cipher_suites_; }
private:
explicit ConfigVars(const Overrides& overrides);
static const ConfigVars& Load();
static std::atomic<ConfigVars*> config_vars_;
int32_t client_channel_backup_poll_interval_ms_;
bool enable_fork_support_;
bool abort_on_leaks_;
bool not_use_system_ssl_roots_;
std::string dns_resolver_;
std::string verbosity_;
std::string poll_strategy_;
std::string ssl_cipher_suites_;
std::string experiments_;
std::string trace_;
absl::optional<std::string> override_system_ssl_roots_dir_;
absl::optional<std::string> override_default_ssl_roots_file_path_;
};
} // namespace grpc_core
#endif // GRPC_SRC_CORE_LIB_CONFIG_CONFIG_VARS_H

@ -1,122 +0,0 @@
# Copyright 2022 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# File format:
#
# Each config var gets a name, and a type (one of string, int, bool).
#
# A default value is provided. Defaults prefixed by '$' are read as expressions,
# otherwise they're assumed literals.
# A description field must be present.
#
# Optionally, a force-load-on-access: true flag can be added to force checking
# the environment variables every time the value is queried, to match legacy
# behavior for some environment variables.
#
# Optionally, fuzz: true can be added to enable fuzzers to explore variations
# in this config var with their regular fuzzing work - or fuzz: FunctionName
# can be used to specify that the config space be explored, but FunctionName should be called to pre-format/validate the value for fuzzing.
# Such functions should be listed in fuzz_config_vars_helpers.h.
- name: experiments
type: comma_separated_string
description:
A comma separated list of currently active experiments. Experiments may be
prefixed with a '-' to disable them.
default:
fuzz_type: uint64
fuzz: ValidateExperimentsStringForFuzzing
- name: client_channel_backup_poll_interval_ms
type: int
default: 5000
description:
Declares the interval in ms between two backup polls on client channels.
These polls are run in the timer thread so that gRPC can process
connection failures while there is no active polling thread.
They help reconnect disconnected client channels (mostly due to
idleness), so that the next RPC on this channel won't fail. Set to 0 to
turn off the backup polls.
- name: dns_resolver
default:
type: string
description:
Declares which DNS resolver to use. The default is ares if gRPC is built
with c-ares support. Otherwise, the value of this environment variable is
ignored.
fuzz: true
- name: trace
type: comma_separated_string
default:
description:
A comma separated list of tracers that provide additional insight into
how gRPC C core is processing requests via debug logs.
fuzz: true
- name: verbosity
type: string
prelude: |
#ifndef GPR_DEFAULT_LOG_VERBOSITY_STRING
#define GPR_DEFAULT_LOG_VERBOSITY_STRING ""
#endif // !GPR_DEFAULT_LOG_VERBOSITY_STRING
default: $GPR_DEFAULT_LOG_VERBOSITY_STRING
description:
Logging verbosity.
fuzz: true
- name: enable_fork_support
type: bool
description: Enable fork support
prelude: |
#ifdef GRPC_ENABLE_FORK_SUPPORT
#define GRPC_ENABLE_FORK_SUPPORT_DEFAULT true
#else
#define GRPC_ENABLE_FORK_SUPPORT_DEFAULT false
#endif // GRPC_ENABLE_FORK_SUPPORT
default: $GRPC_ENABLE_FORK_SUPPORT_DEFAULT
fuzz: true
- name: poll_strategy
type: string
description:
Declares which polling engines to try when starting gRPC.
This is a comma-separated list of engines, which are tried in priority
order first -> last.
default: all
- name: abort_on_leaks
type: bool
default: false
description:
A debugging aid to cause a call to abort() when gRPC objects are leaked
past grpc_shutdown()
- name: system_ssl_roots_dir
type: string
default:
description: Custom directory to SSL Roots
force-load-on-access: true
- name: default_ssl_roots_file_path
type: string
default:
description: Path to the default SSL roots file.
force-load-on-access: true
- name: not_use_system_ssl_roots
type: bool
default: false
description: Disable loading system root certificates.
- name: ssl_cipher_suites
type: string
description: A colon separated list of cipher suites to use with OpenSSL
default: "TLS_AES_128_GCM_SHA256:\
TLS_AES_256_GCM_SHA384:\
TLS_CHACHA20_POLY1305_SHA256:\
ECDHE-ECDSA-AES128-GCM-SHA256:\
ECDHE-ECDSA-AES256-GCM-SHA384:\
ECDHE-RSA-AES128-GCM-SHA256:\
ECDHE-RSA-AES256-GCM-SHA384"

@ -1,49 +0,0 @@
// Copyright 2022 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <atomic>
#include <string>
#include <grpc/support/port_platform.h>
#include "src/core/lib/config/config_vars.h"
namespace grpc_core {
std::atomic<ConfigVars*> ConfigVars::config_vars_{nullptr};
const ConfigVars& ConfigVars::Load() {
// Called from get, so we know there's no existing config vars.
// We might race for them though.
auto vars = new ConfigVars({});
ConfigVars* expected = nullptr;
if (!config_vars_.compare_exchange_strong(expected, vars,
std::memory_order_acq_rel,
std::memory_order_acquire)) {
delete vars;
return *expected;
}
return *vars;
}
void ConfigVars::Reset() {
delete config_vars_.exchange(nullptr, std::memory_order_acq_rel);
}
void ConfigVars::SetOverrides(const Overrides& overrides) {
delete config_vars_.exchange(new ConfigVars(overrides),
std::memory_order_acq_rel);
}
} // namespace grpc_core

@ -1,112 +0,0 @@
// Copyright 2021 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/core/lib/config/core_configuration.h"
#include <atomic>
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
namespace grpc_core {
std::atomic<CoreConfiguration*> CoreConfiguration::config_{nullptr};
std::atomic<CoreConfiguration::RegisteredBuilder*> CoreConfiguration::builders_{
nullptr};
void (*CoreConfiguration::default_builder_)(CoreConfiguration::Builder*);
CoreConfiguration::Builder::Builder() = default;
CoreConfiguration* CoreConfiguration::Builder::Build() {
return new CoreConfiguration(this);
}
CoreConfiguration::CoreConfiguration(Builder* builder)
: channel_args_preconditioning_(
builder->channel_args_preconditioning_.Build()),
channel_init_(builder->channel_init_.Build()),
handshaker_registry_(builder->handshaker_registry_.Build()),
channel_creds_registry_(builder->channel_creds_registry_.Build()),
service_config_parser_(builder->service_config_parser_.Build()),
resolver_registry_(builder->resolver_registry_.Build()),
lb_policy_registry_(builder->lb_policy_registry_.Build()),
proxy_mapper_registry_(builder->proxy_mapper_registry_.Build()),
certificate_provider_registry_(
builder->certificate_provider_registry_.Build()) {}
void CoreConfiguration::RegisterBuilder(
absl::AnyInvocable<void(Builder*)> builder) {
CHECK(config_.load(std::memory_order_relaxed) == nullptr)
<< "CoreConfiguration was already instantiated before builder "
"registration was completed";
RegisteredBuilder* n = new RegisteredBuilder();
n->builder = std::move(builder);
n->next = builders_.load(std::memory_order_relaxed);
while (!builders_.compare_exchange_weak(n->next, n, std::memory_order_acq_rel,
std::memory_order_relaxed)) {
}
CHECK(config_.load(std::memory_order_relaxed) == nullptr)
<< "CoreConfiguration was already instantiated before builder "
"registration was completed";
}
const CoreConfiguration& CoreConfiguration::BuildNewAndMaybeSet() {
// Construct builder, pass it up to code that knows about build configuration
Builder builder;
// The linked list of builders stores things in reverse registration order.
// To get things registered as systems relying on this expect however, we
// actually need to run things in forward registration order, so we iterate
// once over the linked list to build a vector of builders, and then iterate
// over said vector in reverse to actually run the builders.
std::vector<RegisteredBuilder*> registered_builders;
for (RegisteredBuilder* b = builders_.load(std::memory_order_acquire);
b != nullptr; b = b->next) {
registered_builders.push_back(b);
}
for (auto it = registered_builders.rbegin(); it != registered_builders.rend();
++it) {
(*it)->builder(&builder);
}
// Finally, call the built in configuration builder.
if (default_builder_ != nullptr) (*default_builder_)(&builder);
// Use builder to construct a confguration
CoreConfiguration* p = builder.Build();
// Try to set configuration global - it's possible another thread raced us
// here, in which case we drop the work we did and use the one that got set
// first
CoreConfiguration* expected = nullptr;
if (!config_.compare_exchange_strong(expected, p, std::memory_order_acq_rel,
std::memory_order_acquire)) {
delete p;
return *expected;
}
return *p;
}
void CoreConfiguration::Reset() {
delete config_.exchange(nullptr, std::memory_order_acquire);
RegisteredBuilder* builder =
builders_.exchange(nullptr, std::memory_order_acquire);
while (builder != nullptr) {
RegisteredBuilder* next = builder->next;
delete builder;
builder = next;
}
}
} // namespace grpc_core

@ -1,244 +0,0 @@
// Copyright 2021 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_SRC_CORE_LIB_CONFIG_CORE_CONFIGURATION_H
#define GRPC_SRC_CORE_LIB_CONFIG_CORE_CONFIGURATION_H
#include <atomic>
#include "absl/functional/any_invocable.h"
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include "src/core/handshaker/handshaker_registry.h"
#include "src/core/handshaker/proxy_mapper_registry.h"
#include "src/core/lib/channel/channel_args_preconditioning.h"
#include "src/core/lib/security/certificate_provider/certificate_provider_registry.h"
#include "src/core/lib/security/credentials/channel_creds_registry.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/load_balancing/lb_policy_registry.h"
#include "src/core/resolver/resolver_registry.h"
#include "src/core/service_config/service_config_parser.h"
namespace grpc_core {
// Global singleton that stores library configuration - factories, etc...
// that plugins might choose to extend.
class GRPC_DLL CoreConfiguration {
public:
CoreConfiguration(const CoreConfiguration&) = delete;
CoreConfiguration& operator=(const CoreConfiguration&) = delete;
// Builder is passed to plugins, etc... at initialization time to collect
// their configuration and assemble the published CoreConfiguration.
class Builder {
public:
ChannelArgsPreconditioning::Builder* channel_args_preconditioning() {
return &channel_args_preconditioning_;
}
ChannelInit::Builder* channel_init() { return &channel_init_; }
HandshakerRegistry::Builder* handshaker_registry() {
return &handshaker_registry_;
}
ChannelCredsRegistry<>::Builder* channel_creds_registry() {
return &channel_creds_registry_;
}
ServiceConfigParser::Builder* service_config_parser() {
return &service_config_parser_;
}
ResolverRegistry::Builder* resolver_registry() {
return &resolver_registry_;
}
LoadBalancingPolicyRegistry::Builder* lb_policy_registry() {
return &lb_policy_registry_;
}
ProxyMapperRegistry::Builder* proxy_mapper_registry() {
return &proxy_mapper_registry_;
}
CertificateProviderRegistry::Builder* certificate_provider_registry() {
return &certificate_provider_registry_;
}
private:
friend class CoreConfiguration;
ChannelArgsPreconditioning::Builder channel_args_preconditioning_;
ChannelInit::Builder channel_init_;
HandshakerRegistry::Builder handshaker_registry_;
ChannelCredsRegistry<>::Builder channel_creds_registry_;
ServiceConfigParser::Builder service_config_parser_;
ResolverRegistry::Builder resolver_registry_;
LoadBalancingPolicyRegistry::Builder lb_policy_registry_;
ProxyMapperRegistry::Builder proxy_mapper_registry_;
CertificateProviderRegistry::Builder certificate_provider_registry_;
Builder();
CoreConfiguration* Build();
};
// Stores a builder for RegisterBuilder
struct RegisteredBuilder {
absl::AnyInvocable<void(Builder*)> builder;
RegisteredBuilder* next;
};
// Temporarily replaces core configuration with what is built from the
// provided BuildFunc that takes (Builder*) and returns void.
// Requires no concurrent Get() be called. Restores current core
// configuration when this object is destroyed. The default builder
// is not backed up or restored.
//
// Useful for running multiple tests back to back in the same process
// without side effects from previous tests.
class WithSubstituteBuilder {
public:
template <typename BuildFunc>
explicit WithSubstituteBuilder(BuildFunc build) {
// Build core configuration to replace.
Builder builder;
build(&builder);
CoreConfiguration* p = builder.Build();
// Backup current core configuration and replace/reset.
config_restore_ =
CoreConfiguration::config_.exchange(p, std::memory_order_acquire);
builders_restore_ = CoreConfiguration::builders_.exchange(
nullptr, std::memory_order_acquire);
}
~WithSubstituteBuilder() {
// Reset and restore.
Reset();
CHECK(CoreConfiguration::config_.exchange(
config_restore_, std::memory_order_acquire) == nullptr);
CHECK(CoreConfiguration::builders_.exchange(
builders_restore_, std::memory_order_acquire) == nullptr);
}
private:
CoreConfiguration* config_restore_;
RegisteredBuilder* builders_restore_;
};
// Lifetime methods
// Get the core configuration; if it does not exist, create it.
static const CoreConfiguration& Get() {
CoreConfiguration* p = config_.load(std::memory_order_acquire);
if (p != nullptr) {
return *p;
}
return BuildNewAndMaybeSet();
}
// Attach a registration function globally.
// Each registration function is called *in addition to*
// BuildCoreConfiguration for the default core configuration.
static void RegisterBuilder(absl::AnyInvocable<void(Builder*)> builder);
// Drop the core configuration. Users must ensure no other threads are
// accessing the configuration.
// Clears any dynamically registered builders.
static void Reset();
// Helper for tests: Reset the configuration, build a special one, run some
// code, and then reset the configuration again.
// Templatized to be sure no codegen in normal builds.
template <typename BuildFunc, typename RunFunc>
static void RunWithSpecialConfiguration(BuildFunc build_configuration,
RunFunc code_to_run) {
WithSubstituteBuilder builder(build_configuration);
code_to_run();
}
// Accessors
const ChannelArgsPreconditioning& channel_args_preconditioning() const {
return channel_args_preconditioning_;
}
const ChannelInit& channel_init() const { return channel_init_; }
const HandshakerRegistry& handshaker_registry() const {
return handshaker_registry_;
}
const ChannelCredsRegistry<>& channel_creds_registry() const {
return channel_creds_registry_;
}
const ServiceConfigParser& service_config_parser() const {
return service_config_parser_;
}
const ResolverRegistry& resolver_registry() const {
return resolver_registry_;
}
const LoadBalancingPolicyRegistry& lb_policy_registry() const {
return lb_policy_registry_;
}
const ProxyMapperRegistry& proxy_mapper_registry() const {
return proxy_mapper_registry_;
}
const CertificateProviderRegistry& certificate_provider_registry() const {
return certificate_provider_registry_;
}
static void SetDefaultBuilder(void (*builder)(CoreConfiguration::Builder*)) {
default_builder_ = builder;
}
private:
explicit CoreConfiguration(Builder* builder);
// Create a new CoreConfiguration, and either set it or throw it away.
// We allow multiple CoreConfiguration's to be created in parallel.
static const CoreConfiguration& BuildNewAndMaybeSet();
// The configuration
static std::atomic<CoreConfiguration*> config_;
// Extra registered builders
static std::atomic<RegisteredBuilder*> builders_;
// Default builder
static void (*default_builder_)(CoreConfiguration::Builder*);
ChannelArgsPreconditioning channel_args_preconditioning_;
ChannelInit channel_init_;
HandshakerRegistry handshaker_registry_;
ChannelCredsRegistry<> channel_creds_registry_;
ServiceConfigParser service_config_parser_;
ResolverRegistry resolver_registry_;
LoadBalancingPolicyRegistry lb_policy_registry_;
ProxyMapperRegistry proxy_mapper_registry_;
CertificateProviderRegistry certificate_provider_registry_;
};
extern void BuildCoreConfiguration(CoreConfiguration::Builder* builder);
} // namespace grpc_core
#endif // GRPC_SRC_CORE_LIB_CONFIG_CORE_CONFIGURATION_H

@ -1,79 +0,0 @@
// Copyright 2022 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/core/lib/config/load_config.h"
#include <stdio.h>
#include "absl/flags/marshalling.h"
#include "absl/log/check.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_join.h"
#include "absl/types/optional.h"
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/env.h"
namespace grpc_core {
namespace {
absl::optional<std::string> LoadEnv(absl::string_view environment_variable) {
return GetEnv(std::string(environment_variable).c_str());
}
} // namespace
std::string LoadConfigFromEnv(absl::string_view environment_variable,
const char* default_value) {
CHECK(!environment_variable.empty());
return LoadEnv(environment_variable).value_or(default_value);
}
int32_t LoadConfigFromEnv(absl::string_view environment_variable,
int32_t default_value) {
auto env = LoadEnv(environment_variable);
if (env.has_value()) {
int32_t out;
if (absl::SimpleAtoi(*env, &out)) return out;
fprintf(stderr, "Error reading int from %s: '%s' is not a number",
std::string(environment_variable).c_str(), env->c_str());
}
return default_value;
}
bool LoadConfigFromEnv(absl::string_view environment_variable,
bool default_value) {
auto env = LoadEnv(environment_variable);
if (env.has_value()) {
bool out;
std::string error;
if (absl::ParseFlag(env->c_str(), &out, &error)) return out;
fprintf(stderr, "Error reading bool from %s: '%s' is not a bool: %s",
std::string(environment_variable).c_str(), env->c_str(),
error.c_str());
}
return default_value;
}
std::string LoadConfig(const absl::Flag<std::vector<std::string>>& flag,
absl::string_view environment_variable,
const absl::optional<std::string>& override,
const char* default_value) {
if (override.has_value()) return *override;
auto from_flag = absl::GetFlag(flag);
if (!from_flag.empty()) return absl::StrJoin(from_flag, ",");
return LoadConfigFromEnv(environment_variable, default_value);
}
} // namespace grpc_core

@ -1,55 +0,0 @@
// Copyright 2022 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_SRC_CORE_LIB_CONFIG_LOAD_CONFIG_H
#define GRPC_SRC_CORE_LIB_CONFIG_LOAD_CONFIG_H
#include <stdint.h>
#include <string>
#include <vector>
#include "absl/flags/flag.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include <grpc/support/port_platform.h>
namespace grpc_core {
std::string LoadConfigFromEnv(absl::string_view environment_variable,
const char* default_value);
int32_t LoadConfigFromEnv(absl::string_view environment_variable,
int32_t default_value);
bool LoadConfigFromEnv(absl::string_view environment_variable,
bool default_value);
template <typename T, typename D>
T LoadConfig(const absl::Flag<absl::optional<T>>& flag,
absl::string_view environment_variable,
const absl::optional<T>& override, D default_value) {
if (override.has_value()) return *override;
auto from_flag = absl::GetFlag(flag);
if (from_flag.has_value()) return std::move(*from_flag);
return LoadConfigFromEnv(environment_variable, default_value);
}
std::string LoadConfig(const absl::Flag<std::vector<std::string>>& flag,
absl::string_view environment_variable,
const absl::optional<std::string>& override,
const char* default_value);
} // namespace grpc_core
#endif // GRPC_SRC_CORE_LIB_CONFIG_LOAD_CONFIG_H

@ -1 +1 @@
Subproject commit 344117638c8ff7e239044fd0fa7085839fc03021
Subproject commit 12235e24652fc7f809373e7c11a5f73c5763fc4c

@ -1 +1 @@
Subproject commit 4bd64c9a336fd438d6c4c9dad2e6b61b0585311f
Subproject commit a388e87d72b8321c189c8d41edb746ffa687ce3c
Loading…
Cancel
Save