• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //
16 // Automatically generated by tools/codegen/core/gen_config_vars.py
17 //
18 
19 #ifndef GRPC_SRC_CORE_LIB_CONFIG_CONFIG_VARS_H
20 #define GRPC_SRC_CORE_LIB_CONFIG_CONFIG_VARS_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include <stdint.h>
25 
26 #include <atomic>
27 #include <string>
28 
29 #include "absl/strings/string_view.h"
30 #include "absl/types/optional.h"
31 
32 namespace grpc_core {
33 
34 class GPR_DLL ConfigVars {
35  public:
36   struct Overrides {
37     absl::optional<int32_t> client_channel_backup_poll_interval_ms;
38     absl::optional<bool> enable_fork_support;
39     absl::optional<bool> abort_on_leaks;
40     absl::optional<bool> not_use_system_ssl_roots;
41     absl::optional<bool> absl_logging;
42     absl::optional<std::string> dns_resolver;
43     absl::optional<std::string> verbosity;
44     absl::optional<std::string> stacktrace_minloglevel;
45     absl::optional<std::string> poll_strategy;
46     absl::optional<std::string> system_ssl_roots_dir;
47     absl::optional<std::string> default_ssl_roots_file_path;
48     absl::optional<std::string> ssl_cipher_suites;
49     absl::optional<std::string> experiments;
50     absl::optional<std::string> trace;
51   };
52   ConfigVars(const ConfigVars&) = delete;
53   ConfigVars& operator=(const ConfigVars&) = delete;
54   // Get the core configuration; if it does not exist, create it.
Get()55   static const ConfigVars& Get() {
56     auto* p = config_vars_.load(std::memory_order_acquire);
57     if (p != nullptr) return *p;
58     return Load();
59   }
60   static void SetOverrides(const Overrides& overrides);
61   // Drop the config vars. Users must ensure no other threads are
62   // accessing the configuration.
63   static void Reset();
64   std::string ToString() const;
65   // A comma separated list of currently active experiments. Experiments may be
66   // prefixed with a '-' to disable them.
Experiments()67   absl::string_view Experiments() const { return experiments_; }
68   // Declares the interval in ms between two backup polls on client channels.
69   // These polls are run in the timer thread so that gRPC can process connection
70   // failures while there is no active polling thread. They help reconnect
71   // disconnected client channels (mostly due to idleness), so that the next RPC
72   // on this channel won't fail. Set to 0 to turn off the backup polls.
ClientChannelBackupPollIntervalMs()73   int32_t ClientChannelBackupPollIntervalMs() const {
74     return client_channel_backup_poll_interval_ms_;
75   }
76   // Declares which DNS resolver to use. The default is ares if gRPC is built
77   // with c-ares support. Otherwise, the value of this environment variable is
78   // ignored.
DnsResolver()79   absl::string_view DnsResolver() const { return dns_resolver_; }
80   // A comma separated list of tracers that provide additional insight into how
81   // gRPC C core is processing requests via debug logs.
Trace()82   absl::string_view Trace() const { return trace_; }
83   // Default gRPC logging verbosity
Verbosity()84   absl::string_view Verbosity() const { return verbosity_; }
85   // Messages logged at the same or higher level than this will print stacktrace
StacktraceMinloglevel()86   absl::string_view StacktraceMinloglevel() const {
87     return stacktrace_minloglevel_;
88   }
89   // Enable fork support
EnableForkSupport()90   bool EnableForkSupport() const { return enable_fork_support_; }
91   // Declares which polling engines to try when starting gRPC. This is a
92   // comma-separated list of engines, which are tried in priority order first ->
93   // last.
PollStrategy()94   absl::string_view PollStrategy() const { return poll_strategy_; }
95   // A debugging aid to cause a call to abort() when gRPC objects are leaked
96   // past grpc_shutdown()
AbortOnLeaks()97   bool AbortOnLeaks() const { return abort_on_leaks_; }
98   // Custom directory to SSL Roots
99   std::string SystemSslRootsDir() const;
100   // Path to the default SSL roots file.
101   std::string DefaultSslRootsFilePath() const;
102   // Disable loading system root certificates.
NotUseSystemSslRoots()103   bool NotUseSystemSslRoots() const { return not_use_system_ssl_roots_; }
104   // A colon separated list of cipher suites to use with OpenSSL
SslCipherSuites()105   absl::string_view SslCipherSuites() const { return ssl_cipher_suites_; }
106   // Use absl logging from within gpr_log.
AbslLogging()107   bool AbslLogging() const { return absl_logging_; }
108 
109  private:
110   explicit ConfigVars(const Overrides& overrides);
111   static const ConfigVars& Load();
112   static std::atomic<ConfigVars*> config_vars_;
113   int32_t client_channel_backup_poll_interval_ms_;
114   bool enable_fork_support_;
115   bool abort_on_leaks_;
116   bool not_use_system_ssl_roots_;
117   bool absl_logging_;
118   std::string dns_resolver_;
119   std::string verbosity_;
120   std::string stacktrace_minloglevel_;
121   std::string poll_strategy_;
122   std::string ssl_cipher_suites_;
123   std::string experiments_;
124   std::string trace_;
125   absl::optional<std::string> override_system_ssl_roots_dir_;
126   absl::optional<std::string> override_default_ssl_roots_file_path_;
127 };
128 
129 }  // namespace grpc_core
130 
131 #endif  // GRPC_SRC_CORE_LIB_CONFIG_CONFIG_VARS_H
132