mirror of https://github.com/grpc/grpc.git
Reland global config changes (#32661)
<!-- If you know who should review your pull request, please assign it to that person, otherwise the pull request would get assigned randomly. If your pull request is for a specific language, please add the appropriate lang label. --> --------- Co-authored-by: ctiller <ctiller@users.noreply.github.com>pull/32732/head
parent
a363b6c001
commit
175ccc3a90
107 changed files with 1421 additions and 1447 deletions
@ -1,30 +0,0 @@ |
|||||||
//
|
|
||||||
// Copyright 2019 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.
|
|
||||||
//
|
|
||||||
|
|
||||||
// This is similar to the sockaddr resolver, except that it supports a
|
|
||||||
// bunch of query args that are useful for dependency injection in tests.
|
|
||||||
|
|
||||||
#include <grpc/support/port_platform.h> |
|
||||||
|
|
||||||
#include "src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h" |
|
||||||
|
|
||||||
#include "src/core/lib/gprpp/global_config.h" |
|
||||||
|
|
||||||
GPR_GLOBAL_CONFIG_DEFINE_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.") |
|
@ -1,29 +0,0 @@ |
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright 2019 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_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_DNS_RESOLVER_SELECTION_H |
|
||||||
#define GRPC_SRC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_DNS_RESOLVER_SELECTION_H |
|
||||||
|
|
||||||
#include <grpc/support/port_platform.h> |
|
||||||
|
|
||||||
#include "src/core/lib/gprpp/global_config_generic.h" |
|
||||||
#include "src/core/lib/gprpp/memory.h" |
|
||||||
|
|
||||||
GPR_GLOBAL_CONFIG_DECLARE_STRING(grpc_dns_resolver); |
|
||||||
|
|
||||||
#endif // GRPC_SRC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_DNS_RESOLVER_SELECTION_H
|
|
@ -0,0 +1,151 @@ |
|||||||
|
// 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 <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
#include "src/core/lib/config/config_vars.h" |
||||||
|
|
||||||
|
#include "absl/flags/flag.h" |
||||||
|
#include "absl/strings/escaping.h" |
||||||
|
#include "absl/strings/str_cat.h" |
||||||
|
|
||||||
|
#include "src/core/lib/config/load_config.h" |
||||||
|
|
||||||
|
#ifndef GPR_DEFAULT_LOG_VERBOSITY_STRING |
||||||
|
#define GPR_DEFAULT_LOG_VERBOSITY_STRING "ERROR" |
||||||
|
#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(absl::optional<std::string>, grpc_experiments, absl::nullopt, |
||||||
|
"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, |
||||||
|
absl::nullopt, |
||||||
|
"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, absl::nullopt, |
||||||
|
"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(absl::optional<std::string>, grpc_trace, absl::nullopt, |
||||||
|
"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, absl::nullopt, |
||||||
|
"Default gRPC logging verbosity"); |
||||||
|
ABSL_FLAG(absl::optional<std::string>, grpc_stacktrace_minloglevel, |
||||||
|
absl::nullopt, |
||||||
|
"Messages logged at the same or higher level than this will print " |
||||||
|
"stacktrace"); |
||||||
|
ABSL_FLAG(absl::optional<bool>, grpc_enable_fork_support, absl::nullopt, |
||||||
|
"Enable fork support"); |
||||||
|
ABSL_FLAG(absl::optional<std::string>, grpc_poll_strategy, absl::nullopt, |
||||||
|
"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, absl::nullopt, |
||||||
|
"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, absl::nullopt, |
||||||
|
"Custom directory to SSL Roots"); |
||||||
|
ABSL_FLAG(absl::optional<std::string>, grpc_default_ssl_roots_file_path, |
||||||
|
absl::nullopt, "Path to the default SSL roots file."); |
||||||
|
ABSL_FLAG(absl::optional<bool>, grpc_not_use_system_ssl_roots, absl::nullopt, |
||||||
|
"Disable loading system root certificates."); |
||||||
|
ABSL_FLAG(absl::optional<std::string>, grpc_ssl_cipher_suites, absl::nullopt, |
||||||
|
"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)), |
||||||
|
experiments_(LoadConfig(FLAGS_grpc_experiments, "GRPC_EXPERIMENTS", |
||||||
|
overrides.experiments, "")), |
||||||
|
dns_resolver_(LoadConfig(FLAGS_grpc_dns_resolver, "GRPC_DNS_RESOLVER", |
||||||
|
overrides.dns_resolver, "")), |
||||||
|
trace_(LoadConfig(FLAGS_grpc_trace, "GRPC_TRACE", overrides.trace, "")), |
||||||
|
verbosity_(LoadConfig(FLAGS_grpc_verbosity, "GRPC_VERBOSITY", |
||||||
|
overrides.verbosity, |
||||||
|
GPR_DEFAULT_LOG_VERBOSITY_STRING)), |
||||||
|
stacktrace_minloglevel_(LoadConfig(FLAGS_grpc_stacktrace_minloglevel, |
||||||
|
"GRPC_STACKTRACE_MINLOGLEVEL", |
||||||
|
overrides.stacktrace_minloglevel, "")), |
||||||
|
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")), |
||||||
|
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()), "\"", ", stacktrace_minloglevel: ", "\"", |
||||||
|
absl::CEscape(StacktraceMinloglevel()), "\"", |
||||||
|
", 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
|
@ -0,0 +1,127 @@ |
|||||||
|
// 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 <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
#include <stdint.h> |
||||||
|
|
||||||
|
#include <atomic> |
||||||
|
#include <string> |
||||||
|
|
||||||
|
#include "absl/strings/string_view.h" |
||||||
|
#include "absl/types/optional.h" |
||||||
|
|
||||||
|
namespace grpc_core { |
||||||
|
|
||||||
|
class 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> experiments; |
||||||
|
absl::optional<std::string> dns_resolver; |
||||||
|
absl::optional<std::string> trace; |
||||||
|
absl::optional<std::string> verbosity; |
||||||
|
absl::optional<std::string> stacktrace_minloglevel; |
||||||
|
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; |
||||||
|
}; |
||||||
|
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_; } |
||||||
|
// Default gRPC logging verbosity
|
||||||
|
absl::string_view Verbosity() const { return verbosity_; } |
||||||
|
// Messages logged at the same or higher level than this will print stacktrace
|
||||||
|
absl::string_view StacktraceMinloglevel() const { |
||||||
|
return stacktrace_minloglevel_; |
||||||
|
} |
||||||
|
// 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 experiments_; |
||||||
|
std::string dns_resolver_; |
||||||
|
std::string trace_; |
||||||
|
std::string verbosity_; |
||||||
|
std::string stacktrace_minloglevel_; |
||||||
|
std::string poll_strategy_; |
||||||
|
std::string ssl_cipher_suites_; |
||||||
|
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
|
@ -0,0 +1,113 @@ |
|||||||
|
# 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. |
||||||
|
|
||||||
|
- name: experiments |
||||||
|
type: string |
||||||
|
description: |
||||||
|
A comma separated list of currently active experiments. Experiments may be |
||||||
|
prefixed with a '-' to disable them. |
||||||
|
default: |
||||||
|
- 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. |
||||||
|
- name: trace |
||||||
|
type: string |
||||||
|
default: |
||||||
|
description: |
||||||
|
A comma separated list of tracers that provide additional insight into |
||||||
|
how gRPC C core is processing requests via debug logs. |
||||||
|
- name: verbosity |
||||||
|
type: string |
||||||
|
prelude: | |
||||||
|
#ifndef GPR_DEFAULT_LOG_VERBOSITY_STRING |
||||||
|
#define GPR_DEFAULT_LOG_VERBOSITY_STRING "ERROR" |
||||||
|
#endif // !GPR_DEFAULT_LOG_VERBOSITY_STRING |
||||||
|
default: $GPR_DEFAULT_LOG_VERBOSITY_STRING |
||||||
|
description: |
||||||
|
Default gRPC logging verbosity |
||||||
|
- name: stacktrace_minloglevel |
||||||
|
type: string |
||||||
|
default: |
||||||
|
description: |
||||||
|
Messages logged at the same or higher level than this will print stacktrace |
||||||
|
- 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 |
||||||
|
- 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" |
@ -0,0 +1,51 @@ |
|||||||
|
// 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 <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
#include <stdint.h> |
||||||
|
|
||||||
|
#include <atomic> |
||||||
|
#include <string> |
||||||
|
|
||||||
|
#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
|
@ -0,0 +1,66 @@ |
|||||||
|
// 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 <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
#include "src/core/lib/config/load_config.h" |
||||||
|
|
||||||
|
#include <stdio.h> |
||||||
|
|
||||||
|
#include "absl/flags/marshalling.h" |
||||||
|
#include "absl/strings/numbers.h" |
||||||
|
#include "absl/types/optional.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) { |
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace grpc_core
|
@ -0,0 +1,49 @@ |
|||||||
|
// 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 <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
#include <stdint.h> |
||||||
|
|
||||||
|
#include <string> |
||||||
|
|
||||||
|
#include "absl/flags/flag.h" |
||||||
|
#include "absl/strings/string_view.h" |
||||||
|
#include "absl/types/optional.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); |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace grpc_core
|
||||||
|
|
||||||
|
#endif // GRPC_SRC_CORE_LIB_CONFIG_LOAD_CONFIG_H
|
@ -1,93 +0,0 @@ |
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright 2019 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_GPRPP_GLOBAL_CONFIG_H |
|
||||||
#define GRPC_SRC_CORE_LIB_GPRPP_GLOBAL_CONFIG_H |
|
||||||
|
|
||||||
#include <grpc/support/port_platform.h> |
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
|
||||||
// How to use global configuration variables:
|
|
||||||
//
|
|
||||||
// Defining config variables of a specified type:
|
|
||||||
// GPR_GLOBAL_CONFIG_DEFINE_*TYPE*(name, default_value, help);
|
|
||||||
//
|
|
||||||
// Supported TYPEs: BOOL, INT32, STRING
|
|
||||||
//
|
|
||||||
// It's recommended to use lowercase letters for 'name' like
|
|
||||||
// regular variables. The builtin configuration system uses
|
|
||||||
// environment variable and the name is converted to uppercase
|
|
||||||
// when looking up the value. For example,
|
|
||||||
// GPR_GLOBAL_CONFIG_DEFINE(grpc_latency) looks up the value with the
|
|
||||||
// name, "GRPC_LATENCY".
|
|
||||||
//
|
|
||||||
// The variable initially has the specified 'default_value'
|
|
||||||
// which must be an expression convertible to 'Type'.
|
|
||||||
// 'default_value' may be evaluated 0 or more times,
|
|
||||||
// and at an unspecified time; keep it
|
|
||||||
// simple and usually free of side-effects.
|
|
||||||
//
|
|
||||||
// GPR_GLOBAL_CONFIG_DEFINE_*TYPE* should not be called in a C++ header.
|
|
||||||
// It should be called at the top-level (outside any namespaces)
|
|
||||||
// in a .cc file.
|
|
||||||
//
|
|
||||||
// Getting the variables:
|
|
||||||
// GPR_GLOBAL_CONFIG_GET(name)
|
|
||||||
//
|
|
||||||
// If error happens during getting variables, error messages will
|
|
||||||
// be logged and default value will be returned.
|
|
||||||
//
|
|
||||||
// Setting the variables with new value:
|
|
||||||
// GPR_GLOBAL_CONFIG_SET(name, new_value)
|
|
||||||
//
|
|
||||||
// Declaring config variables for other modules to access:
|
|
||||||
// GPR_GLOBAL_CONFIG_DECLARE_*TYPE*(name)
|
|
||||||
//
|
|
||||||
// * Caveat for setting global configs at runtime
|
|
||||||
//
|
|
||||||
// Setting global configs at runtime multiple times is safe but it doesn't
|
|
||||||
// mean that it will have a valid effect on the module depending configs.
|
|
||||||
// In unit tests, it may be unpredictable to set different global configs
|
|
||||||
// between test cases because grpc init and shutdown can ignore changes.
|
|
||||||
// It's considered safe to set global configs before the first call to
|
|
||||||
// grpc_init().
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
|
||||||
// How to customize the global configuration system:
|
|
||||||
//
|
|
||||||
// How to read and write configuration value can be customized.
|
|
||||||
// Builtin system uses environment variables but it can be extended to
|
|
||||||
// support command-line flag, file, etc.
|
|
||||||
//
|
|
||||||
// To customize it, following macros should be redefined.
|
|
||||||
//
|
|
||||||
// GPR_GLOBAL_CONFIG_DEFINE_BOOL
|
|
||||||
// GPR_GLOBAL_CONFIG_DEFINE_INT32
|
|
||||||
// GPR_GLOBAL_CONFIG_DEFINE_STRING
|
|
||||||
//
|
|
||||||
// These macros should define functions for getting and setting variable.
|
|
||||||
// For example, GPR_GLOBAL_CONFIG_DEFINE_BOOL(test, ...) would define two
|
|
||||||
// functions.
|
|
||||||
//
|
|
||||||
// bool gpr_global_config_get_test();
|
|
||||||
// void gpr_global_config_set_test(bool value);
|
|
||||||
|
|
||||||
#include "src/core/lib/gprpp/global_config_custom.h" // IWYU pragma: export |
|
||||||
#include "src/core/lib/gprpp/global_config_env.h" // IWYU pragma: export |
|
||||||
|
|
||||||
#endif // GRPC_SRC_CORE_LIB_GPRPP_GLOBAL_CONFIG_H
|
|
@ -1,29 +0,0 @@ |
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright 2019 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_GPRPP_GLOBAL_CONFIG_CUSTOM_H |
|
||||||
#define GRPC_SRC_CORE_LIB_GPRPP_GLOBAL_CONFIG_CUSTOM_H |
|
||||||
|
|
||||||
// This is a placeholder for custom global configuration implementation.
|
|
||||||
// To use the custom one, please define following macros here.
|
|
||||||
//
|
|
||||||
// GPR_GLOBAL_CONFIG_DEFINE_BOOL
|
|
||||||
// GPR_GLOBAL_CONFIG_DEFINE_INT32
|
|
||||||
// GPR_GLOBAL_CONFIG_DEFINE_STRING
|
|
||||||
|
|
||||||
#endif // GRPC_SRC_CORE_LIB_GPRPP_GLOBAL_CONFIG_CUSTOM_H
|
|
@ -1,140 +0,0 @@ |
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright 2019 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 <grpc/support/port_platform.h> |
|
||||||
|
|
||||||
#include "src/core/lib/gprpp/global_config_env.h" |
|
||||||
|
|
||||||
#include <ctype.h> |
|
||||||
#include <stdlib.h> |
|
||||||
|
|
||||||
#include <initializer_list> |
|
||||||
#include <memory> |
|
||||||
#include <string> |
|
||||||
#include <type_traits> |
|
||||||
|
|
||||||
#include "absl/strings/str_format.h" |
|
||||||
#include "absl/types/optional.h" |
|
||||||
|
|
||||||
#include <grpc/support/log.h> |
|
||||||
#include <grpc/support/string_util.h> |
|
||||||
|
|
||||||
#include "src/core/lib/gpr/string.h" |
|
||||||
#include "src/core/lib/gprpp/env.h" |
|
||||||
|
|
||||||
namespace grpc_core { |
|
||||||
|
|
||||||
namespace { |
|
||||||
|
|
||||||
void DefaultGlobalConfigEnvErrorFunction(const char* error_message) { |
|
||||||
gpr_log(GPR_ERROR, "%s", error_message); |
|
||||||
} |
|
||||||
|
|
||||||
GlobalConfigEnvErrorFunctionType g_global_config_env_error_func = |
|
||||||
DefaultGlobalConfigEnvErrorFunction; |
|
||||||
|
|
||||||
void LogParsingError(const char* name, const char* value) { |
|
||||||
std::string error_message = absl::StrFormat( |
|
||||||
"Illegal value '%s' specified for environment variable '%s'", value, |
|
||||||
name); |
|
||||||
(*g_global_config_env_error_func)(error_message.c_str()); |
|
||||||
} |
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void SetGlobalConfigEnvErrorFunction(GlobalConfigEnvErrorFunctionType func) { |
|
||||||
g_global_config_env_error_func = func; |
|
||||||
} |
|
||||||
|
|
||||||
UniquePtr<char> GlobalConfigEnv::GetValue() { |
|
||||||
auto env = GetEnv(GetName()); |
|
||||||
return UniquePtr<char>(env.has_value() ? gpr_strdup(env.value().c_str()) |
|
||||||
: nullptr); |
|
||||||
} |
|
||||||
|
|
||||||
void GlobalConfigEnv::SetValue(const char* value) { SetEnv(GetName(), value); } |
|
||||||
|
|
||||||
void GlobalConfigEnv::Unset() { UnsetEnv(GetName()); } |
|
||||||
|
|
||||||
char* GlobalConfigEnv::GetName() { |
|
||||||
// This makes sure that name_ is in a canonical form having uppercase
|
|
||||||
// letters. This is okay to be called serveral times.
|
|
||||||
for (char* c = name_; *c != 0; ++c) { |
|
||||||
*c = toupper(*c); |
|
||||||
} |
|
||||||
return name_; |
|
||||||
} |
|
||||||
static_assert(std::is_trivially_destructible<GlobalConfigEnvBool>::value, |
|
||||||
"GlobalConfigEnvBool needs to be trivially destructible."); |
|
||||||
|
|
||||||
bool GlobalConfigEnvBool::Get() { |
|
||||||
UniquePtr<char> str = GetValue(); |
|
||||||
if (str == nullptr) { |
|
||||||
return default_value_; |
|
||||||
} |
|
||||||
// parsing given value string.
|
|
||||||
bool result = false; |
|
||||||
if (!gpr_parse_bool_value(str.get(), &result)) { |
|
||||||
LogParsingError(GetName(), str.get()); |
|
||||||
result = default_value_; |
|
||||||
} |
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
void GlobalConfigEnvBool::Set(bool value) { |
|
||||||
SetValue(value ? "true" : "false"); |
|
||||||
} |
|
||||||
|
|
||||||
static_assert(std::is_trivially_destructible<GlobalConfigEnvInt32>::value, |
|
||||||
"GlobalConfigEnvInt32 needs to be trivially destructible."); |
|
||||||
|
|
||||||
int32_t GlobalConfigEnvInt32::Get() { |
|
||||||
UniquePtr<char> str = GetValue(); |
|
||||||
if (str == nullptr) { |
|
||||||
return default_value_; |
|
||||||
} |
|
||||||
// parsing given value string.
|
|
||||||
char* end = str.get(); |
|
||||||
long result = strtol(str.get(), &end, 10); |
|
||||||
if (*end != 0) { |
|
||||||
LogParsingError(GetName(), str.get()); |
|
||||||
result = default_value_; |
|
||||||
} |
|
||||||
return static_cast<int32_t>(result); |
|
||||||
} |
|
||||||
|
|
||||||
void GlobalConfigEnvInt32::Set(int32_t value) { |
|
||||||
char buffer[GPR_LTOA_MIN_BUFSIZE]; |
|
||||||
gpr_ltoa(value, buffer); |
|
||||||
SetValue(buffer); |
|
||||||
} |
|
||||||
|
|
||||||
static_assert(std::is_trivially_destructible<GlobalConfigEnvString>::value, |
|
||||||
"GlobalConfigEnvString needs to be trivially destructible."); |
|
||||||
|
|
||||||
UniquePtr<char> GlobalConfigEnvString::Get() { |
|
||||||
UniquePtr<char> str = GetValue(); |
|
||||||
if (str == nullptr) { |
|
||||||
return UniquePtr<char>(gpr_strdup(default_value_)); |
|
||||||
} |
|
||||||
return str; |
|
||||||
} |
|
||||||
|
|
||||||
void GlobalConfigEnvString::Set(const char* value) { SetValue(value); } |
|
||||||
|
|
||||||
} // namespace grpc_core
|
|
@ -1,133 +0,0 @@ |
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright 2019 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_GPRPP_GLOBAL_CONFIG_ENV_H |
|
||||||
#define GRPC_SRC_CORE_LIB_GPRPP_GLOBAL_CONFIG_ENV_H |
|
||||||
|
|
||||||
#include <grpc/support/port_platform.h> |
|
||||||
|
|
||||||
#include <stdint.h> |
|
||||||
|
|
||||||
#include "src/core/lib/gprpp/global_config_generic.h" // IWYU pragma: export |
|
||||||
#include "src/core/lib/gprpp/memory.h" |
|
||||||
|
|
||||||
namespace grpc_core { |
|
||||||
|
|
||||||
typedef void (*GlobalConfigEnvErrorFunctionType)(const char* error_message); |
|
||||||
|
|
||||||
//
|
|
||||||
// Set global_config_env_error_function which is called when config system
|
|
||||||
// encounters errors such as parsing error. What the default function does
|
|
||||||
// is logging error message.
|
|
||||||
//
|
|
||||||
void SetGlobalConfigEnvErrorFunction(GlobalConfigEnvErrorFunctionType func); |
|
||||||
|
|
||||||
// Base class for all classes to access environment variables.
|
|
||||||
class GlobalConfigEnv { |
|
||||||
protected: |
|
||||||
// `name` should be writable and alive after constructor is called.
|
|
||||||
constexpr explicit GlobalConfigEnv(char* name) : name_(name) {} |
|
||||||
|
|
||||||
public: |
|
||||||
// Returns the value of `name` variable.
|
|
||||||
UniquePtr<char> GetValue(); |
|
||||||
|
|
||||||
// Sets the value of `name` variable.
|
|
||||||
void SetValue(const char* value); |
|
||||||
|
|
||||||
// Unsets `name` variable.
|
|
||||||
void Unset(); |
|
||||||
|
|
||||||
protected: |
|
||||||
char* GetName(); |
|
||||||
|
|
||||||
private: |
|
||||||
char* name_; |
|
||||||
}; |
|
||||||
|
|
||||||
class GlobalConfigEnvBool : public GlobalConfigEnv { |
|
||||||
public: |
|
||||||
constexpr GlobalConfigEnvBool(char* name, bool default_value) |
|
||||||
: GlobalConfigEnv(name), default_value_(default_value) {} |
|
||||||
|
|
||||||
bool Get(); |
|
||||||
void Set(bool value); |
|
||||||
|
|
||||||
private: |
|
||||||
bool default_value_; |
|
||||||
}; |
|
||||||
|
|
||||||
class GlobalConfigEnvInt32 : public GlobalConfigEnv { |
|
||||||
public: |
|
||||||
constexpr GlobalConfigEnvInt32(char* name, int32_t default_value) |
|
||||||
: GlobalConfigEnv(name), default_value_(default_value) {} |
|
||||||
|
|
||||||
int32_t Get(); |
|
||||||
void Set(int32_t value); |
|
||||||
|
|
||||||
private: |
|
||||||
int32_t default_value_; |
|
||||||
}; |
|
||||||
|
|
||||||
class GlobalConfigEnvString : public GlobalConfigEnv { |
|
||||||
public: |
|
||||||
constexpr GlobalConfigEnvString(char* name, const char* default_value) |
|
||||||
: GlobalConfigEnv(name), default_value_(default_value) {} |
|
||||||
|
|
||||||
UniquePtr<char> Get(); |
|
||||||
void Set(const char* value); |
|
||||||
|
|
||||||
private: |
|
||||||
const char* default_value_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace grpc_core
|
|
||||||
|
|
||||||
// Macros for defining global config instances using environment variables.
|
|
||||||
// This defines a GlobalConfig*Type* instance with arguments for
|
|
||||||
// mutable variable name and default value.
|
|
||||||
// Mutable name (g_env_str_##name) is here for having an array
|
|
||||||
// for the canonical name without dynamic allocation.
|
|
||||||
// `help` argument is ignored for this implementation.
|
|
||||||
|
|
||||||
#define GPR_GLOBAL_CONFIG_DEFINE_BOOL(name, default_value, help) \ |
|
||||||
static char g_env_str_##name[] = #name; \
|
|
||||||
static ::grpc_core::GlobalConfigEnvBool g_env_##name(g_env_str_##name, \
|
|
||||||
default_value); \
|
|
||||||
bool gpr_global_config_get_##name() { return g_env_##name.Get(); } \
|
|
||||||
void gpr_global_config_set_##name(bool value) { g_env_##name.Set(value); } |
|
||||||
|
|
||||||
#define GPR_GLOBAL_CONFIG_DEFINE_INT32(name, default_value, help) \ |
|
||||||
static char g_env_str_##name[] = #name; \
|
|
||||||
static ::grpc_core::GlobalConfigEnvInt32 g_env_##name(g_env_str_##name, \
|
|
||||||
default_value); \
|
|
||||||
int32_t gpr_global_config_get_##name() { return g_env_##name.Get(); } \
|
|
||||||
void gpr_global_config_set_##name(int32_t value) { g_env_##name.Set(value); } |
|
||||||
|
|
||||||
#define GPR_GLOBAL_CONFIG_DEFINE_STRING(name, default_value, help) \ |
|
||||||
static char g_env_str_##name[] = #name; \
|
|
||||||
static ::grpc_core::GlobalConfigEnvString g_env_##name(g_env_str_##name, \
|
|
||||||
default_value); \
|
|
||||||
::grpc_core::UniquePtr<char> gpr_global_config_get_##name() { \
|
|
||||||
return g_env_##name.Get(); \
|
|
||||||
} \
|
|
||||||
void gpr_global_config_set_##name(const char* value) { \
|
|
||||||
g_env_##name.Set(value); \
|
|
||||||
} |
|
||||||
|
|
||||||
#endif // GRPC_SRC_CORE_LIB_GPRPP_GLOBAL_CONFIG_ENV_H
|
|
@ -1,40 +0,0 @@ |
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright 2019 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_GPRPP_GLOBAL_CONFIG_GENERIC_H |
|
||||||
#define GRPC_SRC_CORE_LIB_GPRPP_GLOBAL_CONFIG_GENERIC_H |
|
||||||
|
|
||||||
#include <grpc/support/port_platform.h> |
|
||||||
|
|
||||||
#define GPR_GLOBAL_CONFIG_GET(name) gpr_global_config_get_##name() |
|
||||||
|
|
||||||
#define GPR_GLOBAL_CONFIG_SET(name, value) gpr_global_config_set_##name(value) |
|
||||||
|
|
||||||
#define GPR_GLOBAL_CONFIG_DECLARE_BOOL(name) \ |
|
||||||
extern bool gpr_global_config_get_##name(); \
|
|
||||||
extern void gpr_global_config_set_##name(bool value) |
|
||||||
|
|
||||||
#define GPR_GLOBAL_CONFIG_DECLARE_INT32(name) \ |
|
||||||
extern int32_t gpr_global_config_get_##name(); \
|
|
||||||
extern void gpr_global_config_set_##name(int32_t value) |
|
||||||
|
|
||||||
#define GPR_GLOBAL_CONFIG_DECLARE_STRING(name) \ |
|
||||||
extern grpc_core::UniquePtr<char> gpr_global_config_get_##name(); \
|
|
||||||
extern void gpr_global_config_set_##name(const char* value) |
|
||||||
|
|
||||||
#endif // GRPC_SRC_CORE_LIB_GPRPP_GLOBAL_CONFIG_GENERIC_H
|
|
@ -1,32 +0,0 @@ |
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright 2019 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 <grpc/support/port_platform.h> |
|
||||||
|
|
||||||
#include "src/core/lib/security/security_connector/ssl_utils_config.h" |
|
||||||
|
|
||||||
/// Config variable that points to the default SSL roots file. This file
|
|
||||||
/// must be a PEM encoded file with all the roots such as the one that can be
|
|
||||||
/// downloaded from https://pki.google.com/roots.pem.
|
|
||||||
GPR_GLOBAL_CONFIG_DEFINE_STRING(grpc_default_ssl_roots_file_path, "", |
|
||||||
"Path to the default SSL roots file."); |
|
||||||
|
|
||||||
/// Config variable used as a flag to enable/disable loading system root
|
|
||||||
/// certificates from the OS trust store.
|
|
||||||
GPR_GLOBAL_CONFIG_DEFINE_BOOL(grpc_not_use_system_ssl_roots, false, |
|
||||||
"Disable loading system root certificates."); |
|
@ -1,29 +0,0 @@ |
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright 2019 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_SECURITY_SECURITY_CONNECTOR_SSL_UTILS_CONFIG_H |
|
||||||
#define GRPC_SRC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_SSL_UTILS_CONFIG_H |
|
||||||
#include <grpc/support/port_platform.h> |
|
||||||
|
|
||||||
#include "src/core/lib/gprpp/global_config.h" |
|
||||||
#include "src/core/lib/gprpp/memory.h" |
|
||||||
|
|
||||||
GPR_GLOBAL_CONFIG_DECLARE_STRING(grpc_default_ssl_roots_file_path); |
|
||||||
GPR_GLOBAL_CONFIG_DECLARE_BOOL(grpc_not_use_system_ssl_roots); |
|
||||||
|
|
||||||
#endif // GRPC_SRC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_SSL_UTILS_CONFIG_H
|
|
@ -1,127 +0,0 @@ |
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright 2019 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/gprpp/global_config_env.h" |
|
||||||
|
|
||||||
#include <string.h> |
|
||||||
|
|
||||||
#include "gtest/gtest.h" |
|
||||||
|
|
||||||
#include "src/core/lib/gprpp/env.h" |
|
||||||
#include "src/core/lib/gprpp/memory.h" |
|
||||||
|
|
||||||
namespace { |
|
||||||
|
|
||||||
bool g_config_error_function_called; |
|
||||||
|
|
||||||
void ClearConfigErrorCalled() { g_config_error_function_called = false; } |
|
||||||
|
|
||||||
bool IsConfigErrorCalled() { return g_config_error_function_called; } |
|
||||||
|
|
||||||
// This function is for preventing the program from invoking
|
|
||||||
// an error handler due to configuration error and
|
|
||||||
// make test routines know whether there is error.
|
|
||||||
void FakeConfigErrorFunction(const char* /*error_message*/) { |
|
||||||
g_config_error_function_called = true; |
|
||||||
} |
|
||||||
|
|
||||||
class GlobalConfigEnvTest : public ::testing::Test { |
|
||||||
protected: |
|
||||||
void SetUp() override { ClearConfigErrorCalled(); } |
|
||||||
void TearDown() override { EXPECT_FALSE(IsConfigErrorCalled()); } |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
GPR_GLOBAL_CONFIG_DEFINE_BOOL(bool_var, true, ""); |
|
||||||
GPR_GLOBAL_CONFIG_DEFINE_INT32(int32_var, 1234, ""); |
|
||||||
GPR_GLOBAL_CONFIG_DEFINE_STRING(string_var, "Apple", ""); |
|
||||||
|
|
||||||
TEST_F(GlobalConfigEnvTest, BoolWithEnvTest) { |
|
||||||
const char* bool_var_name = "BOOL_VAR"; |
|
||||||
|
|
||||||
grpc_core::UnsetEnv(bool_var_name); |
|
||||||
EXPECT_TRUE(GPR_GLOBAL_CONFIG_GET(bool_var)); |
|
||||||
|
|
||||||
grpc_core::SetEnv(bool_var_name, "true"); |
|
||||||
EXPECT_TRUE(GPR_GLOBAL_CONFIG_GET(bool_var)); |
|
||||||
|
|
||||||
grpc_core::SetEnv(bool_var_name, "false"); |
|
||||||
EXPECT_FALSE(GPR_GLOBAL_CONFIG_GET(bool_var)); |
|
||||||
|
|
||||||
EXPECT_FALSE(IsConfigErrorCalled()); |
|
||||||
|
|
||||||
grpc_core::SetEnv(bool_var_name, ""); |
|
||||||
GPR_GLOBAL_CONFIG_GET(bool_var); |
|
||||||
EXPECT_TRUE(IsConfigErrorCalled()); |
|
||||||
ClearConfigErrorCalled(); |
|
||||||
|
|
||||||
grpc_core::SetEnv(bool_var_name, "!"); |
|
||||||
GPR_GLOBAL_CONFIG_GET(bool_var); |
|
||||||
EXPECT_TRUE(IsConfigErrorCalled()); |
|
||||||
ClearConfigErrorCalled(); |
|
||||||
} |
|
||||||
|
|
||||||
TEST_F(GlobalConfigEnvTest, Int32WithEnvTest) { |
|
||||||
const char* int32_var_name = "INT32_VAR"; |
|
||||||
|
|
||||||
grpc_core::UnsetEnv(int32_var_name); |
|
||||||
EXPECT_EQ(1234, GPR_GLOBAL_CONFIG_GET(int32_var)); |
|
||||||
|
|
||||||
grpc_core::SetEnv(int32_var_name, "0"); |
|
||||||
EXPECT_EQ(0, GPR_GLOBAL_CONFIG_GET(int32_var)); |
|
||||||
|
|
||||||
grpc_core::SetEnv(int32_var_name, "-123456789"); |
|
||||||
EXPECT_EQ(-123456789, GPR_GLOBAL_CONFIG_GET(int32_var)); |
|
||||||
|
|
||||||
grpc_core::SetEnv(int32_var_name, "123456789"); |
|
||||||
EXPECT_EQ(123456789, GPR_GLOBAL_CONFIG_GET(int32_var)); |
|
||||||
|
|
||||||
EXPECT_FALSE(IsConfigErrorCalled()); |
|
||||||
|
|
||||||
grpc_core::SetEnv(int32_var_name, "-1AB"); |
|
||||||
GPR_GLOBAL_CONFIG_GET(int32_var); |
|
||||||
EXPECT_TRUE(IsConfigErrorCalled()); |
|
||||||
ClearConfigErrorCalled(); |
|
||||||
} |
|
||||||
|
|
||||||
TEST_F(GlobalConfigEnvTest, StringWithEnvTest) { |
|
||||||
const char* string_var_name = "STRING_VAR"; |
|
||||||
grpc_core::UniquePtr<char> value; |
|
||||||
|
|
||||||
grpc_core::UnsetEnv(string_var_name); |
|
||||||
value = GPR_GLOBAL_CONFIG_GET(string_var); |
|
||||||
EXPECT_EQ(0, strcmp(value.get(), "Apple")); |
|
||||||
|
|
||||||
grpc_core::SetEnv(string_var_name, "Banana"); |
|
||||||
value = GPR_GLOBAL_CONFIG_GET(string_var); |
|
||||||
EXPECT_EQ(0, strcmp(value.get(), "Banana")); |
|
||||||
|
|
||||||
grpc_core::SetEnv(string_var_name, ""); |
|
||||||
value = GPR_GLOBAL_CONFIG_GET(string_var); |
|
||||||
EXPECT_EQ(0, strcmp(value.get(), "")); |
|
||||||
} |
|
||||||
|
|
||||||
int main(int argc, char** argv) { |
|
||||||
// Not to abort the test when parsing error happens.
|
|
||||||
grpc_core::SetGlobalConfigEnvErrorFunction(&FakeConfigErrorFunction); |
|
||||||
|
|
||||||
::testing::InitGoogleTest(&argc, argv); |
|
||||||
int ret = RUN_ALL_TESTS(); |
|
||||||
return ret; |
|
||||||
} |
|
@ -1,61 +0,0 @@ |
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright 2019 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/gprpp/global_config.h" |
|
||||||
|
|
||||||
#include <string.h> |
|
||||||
|
|
||||||
#include "gtest/gtest.h" |
|
||||||
|
|
||||||
#include "src/core/lib/gprpp/memory.h" |
|
||||||
|
|
||||||
GPR_GLOBAL_CONFIG_DECLARE_BOOL(bool_var); |
|
||||||
|
|
||||||
GPR_GLOBAL_CONFIG_DEFINE_BOOL(bool_var, false, ""); |
|
||||||
GPR_GLOBAL_CONFIG_DEFINE_INT32(int32_var, 0, ""); |
|
||||||
GPR_GLOBAL_CONFIG_DEFINE_STRING(string_var, "", ""); |
|
||||||
|
|
||||||
TEST(GlobalConfigTest, BoolTest) { |
|
||||||
EXPECT_FALSE(GPR_GLOBAL_CONFIG_GET(bool_var)); |
|
||||||
GPR_GLOBAL_CONFIG_SET(bool_var, true); |
|
||||||
EXPECT_TRUE(GPR_GLOBAL_CONFIG_GET(bool_var)); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(GlobalConfigTest, Int32Test) { |
|
||||||
EXPECT_EQ(0, GPR_GLOBAL_CONFIG_GET(int32_var)); |
|
||||||
GPR_GLOBAL_CONFIG_SET(int32_var, 1024); |
|
||||||
EXPECT_EQ(1024, GPR_GLOBAL_CONFIG_GET(int32_var)); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(GlobalConfigTest, StringTest) { |
|
||||||
grpc_core::UniquePtr<char> value; |
|
||||||
|
|
||||||
value = GPR_GLOBAL_CONFIG_GET(string_var); |
|
||||||
EXPECT_EQ(0, strcmp(value.get(), "")); |
|
||||||
|
|
||||||
GPR_GLOBAL_CONFIG_SET(string_var, "Test"); |
|
||||||
|
|
||||||
value = GPR_GLOBAL_CONFIG_GET(string_var); |
|
||||||
EXPECT_EQ(0, strcmp(value.get(), "Test")); |
|
||||||
} |
|
||||||
|
|
||||||
int main(int argc, char** argv) { |
|
||||||
::testing::InitGoogleTest(&argc, argv); |
|
||||||
int ret = RUN_ALL_TESTS(); |
|
||||||
return ret; |
|
||||||
} |
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue