mirror of https://github.com/grpc/grpc.git
Revert "[config] Move global config alongside core configuration" (#32659)
Reverts grpc/grpc#30788 (it breaks grpc_objc_bazel_test (see https://github.com/grpc/grpc/pull/30788#issuecomment-1476372187) and also seems to be breaking some other internal stuff).pull/32663/head^2
parent
5873ba96dc
commit
0c1797cd9f
108 changed files with 1472 additions and 1418 deletions
@ -0,0 +1,30 @@ |
|||||||
|
//
|
||||||
|
// 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.") |
@ -0,0 +1,29 @@ |
|||||||
|
//
|
||||||
|
//
|
||||||
|
// 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
|
@ -1,137 +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 <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, |
|
||||||
overrides.client_channel_backup_poll_interval_ms, 5000)), |
|
||||||
enable_fork_support_(LoadConfig(FLAGS_grpc_enable_fork_support, |
|
||||||
overrides.enable_fork_support, |
|
||||||
GRPC_ENABLE_FORK_SUPPORT_DEFAULT)), |
|
||||||
abort_on_leaks_(LoadConfig(FLAGS_grpc_abort_on_leaks, |
|
||||||
overrides.abort_on_leaks, false)), |
|
||||||
not_use_system_ssl_roots_(LoadConfig(FLAGS_grpc_not_use_system_ssl_roots, |
|
||||||
overrides.not_use_system_ssl_roots, |
|
||||||
false)), |
|
||||||
experiments_( |
|
||||||
LoadConfig(FLAGS_grpc_experiments, overrides.experiments, "")), |
|
||||||
dns_resolver_( |
|
||||||
LoadConfig(FLAGS_grpc_dns_resolver, overrides.dns_resolver, "")), |
|
||||||
trace_(LoadConfig(FLAGS_grpc_trace, overrides.trace, "")), |
|
||||||
verbosity_(LoadConfig(FLAGS_grpc_verbosity, overrides.verbosity, |
|
||||||
GPR_DEFAULT_LOG_VERBOSITY_STRING)), |
|
||||||
stacktrace_minloglevel_(LoadConfig(FLAGS_grpc_stacktrace_minloglevel, |
|
||||||
overrides.stacktrace_minloglevel, "")), |
|
||||||
poll_strategy_( |
|
||||||
LoadConfig(FLAGS_grpc_poll_strategy, overrides.poll_strategy, "all")), |
|
||||||
system_ssl_roots_dir_(LoadConfig(FLAGS_grpc_system_ssl_roots_dir, |
|
||||||
overrides.system_ssl_roots_dir, "")), |
|
||||||
default_ssl_roots_file_path_( |
|
||||||
LoadConfig(FLAGS_grpc_default_ssl_roots_file_path, |
|
||||||
overrides.default_ssl_roots_file_path, "")), |
|
||||||
ssl_cipher_suites_(LoadConfig( |
|
||||||
FLAGS_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")) {} |
|
||||||
|
|
||||||
std::string ConfigVars::ToString() const { |
|
||||||
return absl::StrCat( |
|
||||||
"experiments: ", "\"", absl::CEscape(experiments_), "\"", |
|
||||||
", client_channel_backup_poll_interval_ms: ", |
|
||||||
client_channel_backup_poll_interval_ms_, ", dns_resolver: ", "\"", |
|
||||||
absl::CEscape(dns_resolver_), "\"", ", trace: ", "\"", |
|
||||||
absl::CEscape(trace_), "\"", ", verbosity: ", "\"", |
|
||||||
absl::CEscape(verbosity_), "\"", ", stacktrace_minloglevel: ", "\"", |
|
||||||
absl::CEscape(stacktrace_minloglevel_), "\"", |
|
||||||
", enable_fork_support: ", enable_fork_support_ ? "true" : "false", |
|
||||||
", poll_strategy: ", "\"", absl::CEscape(poll_strategy_), "\"", |
|
||||||
", abort_on_leaks: ", abort_on_leaks_ ? "true" : "false", |
|
||||||
", system_ssl_roots_dir: ", "\"", absl::CEscape(system_ssl_roots_dir_), |
|
||||||
"\"", ", default_ssl_roots_file_path: ", "\"", |
|
||||||
absl::CEscape(default_ssl_roots_file_path_), "\"", |
|
||||||
", not_use_system_ssl_roots: ", |
|
||||||
not_use_system_ssl_roots_ ? "true" : "false", |
|
||||||
", ssl_cipher_suites: ", "\"", absl::CEscape(ssl_cipher_suites_), "\""); |
|
||||||
} |
|
||||||
|
|
||||||
} // namespace grpc_core
|
|
@ -1,129 +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 <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
|
|
||||||
absl::string_view SystemSslRootsDir() const { return system_ssl_roots_dir_; } |
|
||||||
// Path to the default SSL roots file.
|
|
||||||
absl::string_view DefaultSslRootsFilePath() const { |
|
||||||
return default_ssl_roots_file_path_; |
|
||||||
} |
|
||||||
// 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 system_ssl_roots_dir_; |
|
||||||
std::string default_ssl_roots_file_path_; |
|
||||||
std::string ssl_cipher_suites_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace grpc_core
|
|
||||||
|
|
||||||
#endif // GRPC_SRC_CORE_LIB_CONFIG_CONFIG_VARS_H
|
|
@ -1,102 +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. |
|
||||||
|
|
||||||
- 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 |
|
||||||
- name: default_ssl_roots_file_path |
|
||||||
type: string |
|
||||||
default: |
|
||||||
description: Path to the default SSL roots file. |
|
||||||
- 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,51 +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 <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
|
|
@ -1,70 +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 <grpc/support/port_platform.h> |
|
||||||
|
|
||||||
#include "src/core/lib/config/load_config.h" |
|
||||||
|
|
||||||
#include <stdio.h> |
|
||||||
|
|
||||||
#include "absl/flags/marshalling.h" |
|
||||||
#include "absl/strings/ascii.h" |
|
||||||
#include "absl/strings/numbers.h" |
|
||||||
#include "absl/strings/str_cat.h" |
|
||||||
#include "absl/types/optional.h" |
|
||||||
|
|
||||||
#include "src/core/lib/gprpp/env.h" |
|
||||||
|
|
||||||
namespace grpc_core { |
|
||||||
|
|
||||||
namespace { |
|
||||||
std::string EnvironmentVarFromVarName(absl::string_view var_name) { |
|
||||||
return absl::StrCat(absl::AsciiStrToUpper(var_name)); |
|
||||||
} |
|
||||||
|
|
||||||
absl::optional<std::string> LoadEnv(absl::string_view var_name) { |
|
||||||
return GetEnv(EnvironmentVarFromVarName(var_name).c_str()); |
|
||||||
} |
|
||||||
} // namespace
|
|
||||||
|
|
||||||
std::string LoadConfigFromEnv(absl::string_view var_name, |
|
||||||
const char* default_value) { |
|
||||||
return LoadEnv(var_name).value_or(default_value); |
|
||||||
} |
|
||||||
|
|
||||||
int32_t LoadConfigFromEnv(absl::string_view var_name, int32_t default_value) { |
|
||||||
auto env = LoadEnv(var_name); |
|
||||||
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", |
|
||||||
EnvironmentVarFromVarName(var_name).c_str(), env->c_str()); |
|
||||||
} |
|
||||||
return default_value; |
|
||||||
} |
|
||||||
|
|
||||||
bool LoadConfigFromEnv(absl::string_view var_name, bool default_value) { |
|
||||||
auto env = LoadEnv(var_name); |
|
||||||
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", |
|
||||||
EnvironmentVarFromVarName(var_name).c_str(), env->c_str(), |
|
||||||
error.c_str()); |
|
||||||
} |
|
||||||
return default_value; |
|
||||||
} |
|
||||||
|
|
||||||
} // namespace grpc_core
|
|
@ -1,46 +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 <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 var_name, |
|
||||||
const char* default_value); |
|
||||||
int32_t LoadConfigFromEnv(absl::string_view var_name, int32_t default_value); |
|
||||||
bool LoadConfigFromEnv(absl::string_view var_name, bool default_value); |
|
||||||
|
|
||||||
template <typename T, typename D> |
|
||||||
T LoadConfig(const absl::Flag<absl::optional<T>>& flag, |
|
||||||
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(flag.Name(), default_value); |
|
||||||
} |
|
||||||
|
|
||||||
} // namespace grpc_core
|
|
||||||
|
|
||||||
#endif // GRPC_SRC_CORE_LIB_CONFIG_LOAD_CONFIG_H
|
|
@ -0,0 +1,93 @@ |
|||||||
|
//
|
||||||
|
//
|
||||||
|
// 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
|
@ -0,0 +1,29 @@ |
|||||||
|
//
|
||||||
|
//
|
||||||
|
// 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
|
@ -0,0 +1,140 @@ |
|||||||
|
//
|
||||||
|
//
|
||||||
|
// 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
|
@ -0,0 +1,133 @@ |
|||||||
|
//
|
||||||
|
//
|
||||||
|
// 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
|
@ -0,0 +1,40 @@ |
|||||||
|
//
|
||||||
|
//
|
||||||
|
// 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
|
@ -0,0 +1,32 @@ |
|||||||
|
//
|
||||||
|
//
|
||||||
|
// 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."); |
@ -0,0 +1,29 @@ |
|||||||
|
//
|
||||||
|
//
|
||||||
|
// 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
|
@ -0,0 +1,127 @@ |
|||||||
|
//
|
||||||
|
//
|
||||||
|
// 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; |
||||||
|
} |
@ -0,0 +1,61 @@ |
|||||||
|
//
|
||||||
|
//
|
||||||
|
// 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