/proc/self/cwd/source/server/server.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include <atomic> |
4 | | #include <chrono> |
5 | | #include <cstdint> |
6 | | #include <functional> |
7 | | #include <list> |
8 | | #include <memory> |
9 | | #include <string> |
10 | | |
11 | | #include "envoy/config/bootstrap/v3/bootstrap.pb.h" |
12 | | #include "envoy/event/timer.h" |
13 | | #include "envoy/server/bootstrap_extension_config.h" |
14 | | #include "envoy/server/configuration.h" |
15 | | #include "envoy/server/drain_manager.h" |
16 | | #include "envoy/server/guarddog.h" |
17 | | #include "envoy/server/instance.h" |
18 | | #include "envoy/server/process_context.h" |
19 | | #include "envoy/server/tracer_config.h" |
20 | | #include "envoy/server/transport_socket_config.h" |
21 | | #include "envoy/ssl/context_manager.h" |
22 | | #include "envoy/stats/stats_macros.h" |
23 | | #include "envoy/stats/timespan.h" |
24 | | #include "envoy/tracing/tracer.h" |
25 | | |
26 | | #include "source/common/access_log/access_log_manager_impl.h" |
27 | | #include "source/common/common/assert.h" |
28 | | #include "source/common/common/cleanup.h" |
29 | | #include "source/common/common/logger_delegates.h" |
30 | | #include "source/common/common/perf_tracing.h" |
31 | | #include "source/common/grpc/async_client_manager_impl.h" |
32 | | #include "source/common/grpc/context_impl.h" |
33 | | #include "source/common/http/context_impl.h" |
34 | | #include "source/common/init/manager_impl.h" |
35 | | #include "source/common/memory/stats.h" |
36 | | #include "source/common/protobuf/message_validator_impl.h" |
37 | | #include "source/common/quic/quic_stat_names.h" |
38 | | #include "source/common/router/context_impl.h" |
39 | | #include "source/common/runtime/runtime_impl.h" |
40 | | #include "source/common/secret/secret_manager_impl.h" |
41 | | #include "source/common/singleton/manager_impl.h" |
42 | | #include "source/common/upstream/health_discovery_service.h" |
43 | | |
44 | | #ifdef ENVOY_ADMIN_FUNCTIONALITY |
45 | | #include "source/server/admin/admin.h" |
46 | | #endif |
47 | | #include "source/server/configuration_impl.h" |
48 | | #include "source/server/listener_hooks.h" |
49 | | #include "source/server/worker_impl.h" |
50 | | |
51 | | #include "absl/container/node_hash_map.h" |
52 | | #include "absl/types/optional.h" |
53 | | |
54 | | namespace Envoy { |
55 | | namespace Server { |
56 | | namespace CompilationSettings { |
57 | | /** |
58 | | * All server compilation settings stats. @see stats_macros.h |
59 | | */ |
60 | | #define ALL_SERVER_COMPILATION_SETTINGS_STATS(COUNTER, GAUGE, HISTOGRAM) \ |
61 | 4.61k | GAUGE(fips_mode, NeverImport) |
62 | | |
63 | | struct ServerCompilationSettingsStats { |
64 | | ALL_SERVER_COMPILATION_SETTINGS_STATS(GENERATE_COUNTER_STRUCT, GENERATE_GAUGE_STRUCT, |
65 | | GENERATE_HISTOGRAM_STRUCT) |
66 | | }; |
67 | | } // namespace CompilationSettings |
68 | | |
69 | | /** |
70 | | * All server wide stats. @see stats_macros.h |
71 | | */ |
72 | | #define ALL_SERVER_STATS(COUNTER, GAUGE, HISTOGRAM) \ |
73 | 4.61k | COUNTER(debug_assertion_failures) \ |
74 | 4.61k | COUNTER(envoy_bug_failures) \ |
75 | 4.61k | COUNTER(dynamic_unknown_fields) \ |
76 | 4.61k | COUNTER(static_unknown_fields) \ |
77 | 4.61k | COUNTER(wip_protos) \ |
78 | 4.61k | COUNTER(dropped_stat_flushes) \ |
79 | 4.61k | GAUGE(concurrency, NeverImport) \ |
80 | 4.61k | GAUGE(days_until_first_cert_expiring, NeverImport) \ |
81 | 4.61k | GAUGE(seconds_until_first_ocsp_response_expiring, NeverImport) \ |
82 | 4.61k | GAUGE(hot_restart_epoch, NeverImport) \ |
83 | 4.61k | /* hot_restart_generation is an Accumulate gauge; we omit it here for testing dynamics. */ \ |
84 | 4.61k | GAUGE(live, NeverImport) \ |
85 | 4.61k | GAUGE(memory_allocated, Accumulate) \ |
86 | 4.61k | GAUGE(memory_heap_size, Accumulate) \ |
87 | 4.61k | GAUGE(memory_physical_size, Accumulate) \ |
88 | 4.61k | GAUGE(parent_connections, Accumulate) \ |
89 | 4.61k | GAUGE(state, NeverImport) \ |
90 | 4.61k | GAUGE(stats_recent_lookups, NeverImport) \ |
91 | 4.61k | GAUGE(total_connections, Accumulate) \ |
92 | 4.61k | GAUGE(uptime, Accumulate) \ |
93 | 4.61k | GAUGE(version, NeverImport) \ |
94 | 4.61k | HISTOGRAM(initialization_time_ms, Milliseconds) |
95 | | |
96 | | struct ServerStats { |
97 | | ALL_SERVER_STATS(GENERATE_COUNTER_STRUCT, GENERATE_GAUGE_STRUCT, GENERATE_HISTOGRAM_STRUCT) |
98 | | }; |
99 | | |
100 | | /** |
101 | | * Interface for creating service components during boot. |
102 | | */ |
103 | | class ComponentFactory { |
104 | | public: |
105 | 1.97k | virtual ~ComponentFactory() = default; |
106 | | |
107 | | /** |
108 | | * @return DrainManagerPtr a new drain manager for the server. |
109 | | */ |
110 | | virtual DrainManagerPtr createDrainManager(Instance& server) PURE; |
111 | | |
112 | | /** |
113 | | * @return Runtime::LoaderPtr the runtime implementation for the server. |
114 | | */ |
115 | | virtual Runtime::LoaderPtr createRuntime(Instance& server, Configuration::Initial& config) PURE; |
116 | | }; |
117 | | |
118 | | /** |
119 | | * Helpers used during server creation. |
120 | | */ |
121 | | class InstanceUtil : Logger::Loggable<Logger::Id::main> { |
122 | | public: |
123 | | /** |
124 | | * Default implementation of runtime loader creation used in the real server and in most |
125 | | * integration tests where a mock runtime is not needed. |
126 | | */ |
127 | | static Runtime::LoaderPtr createRuntime(Instance& server, Server::Configuration::Initial& config); |
128 | | |
129 | | /** |
130 | | * Helper for flushing counters, gauges and histograms to sinks. This takes care of calling |
131 | | * flush() on each sink. |
132 | | * @param sinks supplies the list of sinks. |
133 | | * @param store provides the store being flushed. |
134 | | */ |
135 | | static void flushMetricsToSinks(const std::list<Stats::SinkPtr>& sinks, Stats::Store& store, |
136 | | Upstream::ClusterManager& cm, TimeSource& time_source); |
137 | | |
138 | | /** |
139 | | * Load a bootstrap config and perform validation. |
140 | | * @param bootstrap supplies the bootstrap to fill. |
141 | | * @param options supplies the server options. |
142 | | * @param validation_visitor message validation visitor instance. |
143 | | * @param api reference to the Api object |
144 | | */ |
145 | | static absl::Status loadBootstrapConfig(envoy::config::bootstrap::v3::Bootstrap& bootstrap, |
146 | | const Options& options, |
147 | | ProtobufMessage::ValidationVisitor& validation_visitor, |
148 | | Api::Api& api); |
149 | | }; |
150 | | |
151 | | /** |
152 | | * This is a helper used by InstanceBase::run() on the stack. It's broken out to make testing |
153 | | * easier. |
154 | | */ |
155 | | class RunHelper : Logger::Loggable<Logger::Id::main> { |
156 | | public: |
157 | | RunHelper(Instance& instance, const Options& options, Event::Dispatcher& dispatcher, |
158 | | Upstream::ClusterManager& cm, AccessLog::AccessLogManager& access_log_manager, |
159 | | Init::Manager& init_manager, OverloadManager& overload_manager, |
160 | | OverloadManager& null_overload_manager, std::function<void()> workers_start_cb); |
161 | | |
162 | | private: |
163 | | Init::WatcherImpl init_watcher_; |
164 | | Event::SignalEventPtr sigterm_; |
165 | | Event::SignalEventPtr sigint_; |
166 | | Event::SignalEventPtr sig_usr_1_; |
167 | | Event::SignalEventPtr sig_hup_; |
168 | | }; |
169 | | |
170 | | // ServerFactoryContextImpl implements both ServerFactoryContext and |
171 | | // TransportSocketFactoryContext for convenience as these two contexts |
172 | | // share common member functions and member variables. |
173 | | class ServerFactoryContextImpl : public Configuration::ServerFactoryContext, |
174 | | public Configuration::TransportSocketFactoryContext { |
175 | | public: |
176 | | explicit ServerFactoryContextImpl(Instance& server) |
177 | 10.5k | : server_(server), server_scope_(server_.stats().createScope("")) {} Unexecuted instantiation: Envoy::Server::ServerFactoryContextImpl::ServerFactoryContextImpl(Envoy::Server::Instance&) Envoy::Server::ServerFactoryContextImpl::ServerFactoryContextImpl(Envoy::Server::Instance&) Line | Count | Source | 177 | 10.5k | : server_(server), server_scope_(server_.stats().createScope("")) {} |
|
178 | | |
179 | | // Configuration::ServerFactoryContext |
180 | 11.8k | Upstream::ClusterManager& clusterManager() override { return server_.clusterManager(); } |
181 | 4.40k | Http::HttpServerPropertiesCacheManager& httpServerPropertiesCacheManager() override { |
182 | 4.40k | return server_.httpServerPropertiesCacheManager(); |
183 | 4.40k | } |
184 | 26.2k | Event::Dispatcher& mainThreadDispatcher() override { return server_.dispatcher(); } |
185 | 4.40k | const Server::Options& options() override { return server_.options(); } |
186 | 12.6k | const LocalInfo::LocalInfo& localInfo() const override { return server_.localInfo(); } |
187 | 7.04k | ProtobufMessage::ValidationContext& messageValidationContext() override { |
188 | 7.04k | return server_.messageValidationContext(); |
189 | 7.04k | } |
190 | 64.2k | Envoy::Runtime::Loader& runtime() override { return server_.runtime(); } |
191 | 6.00k | Stats::Scope& scope() override { return *server_scope_; } |
192 | 2.40k | Stats::Scope& serverScope() override { return *server_scope_; } |
193 | 19.8k | Singleton::Manager& singletonManager() override { return server_.singletonManager(); } |
194 | 12.5k | ThreadLocal::Instance& threadLocal() override { return server_.threadLocal(); } |
195 | 8.29k | OptRef<Admin> admin() override { return server_.admin(); } |
196 | 8.34k | TimeSource& timeSource() override { return api().timeSource(); } |
197 | 8.44k | AccessLog::AccessLogManager& accessLogManager() override { return server_.accessLogManager(); } |
198 | 68.2k | Api::Api& api() override { return server_.api(); } |
199 | 4.97k | Http::Context& httpContext() override { return server_.httpContext(); } |
200 | 4.33k | Grpc::Context& grpcContext() override { return server_.grpcContext(); } |
201 | 8.35k | Router::Context& routerContext() override { return server_.routerContext(); } |
202 | 0 | ProcessContextOptRef processContext() override { return server_.processContext(); } |
203 | 0 | Envoy::Server::DrainManager& drainManager() override { return server_.drainManager(); } |
204 | 0 | ServerLifecycleNotifier& lifecycleNotifier() override { return server_.lifecycleNotifier(); } |
205 | 5.12k | Regex::Engine& regexEngine() override { return server_.regexEngine(); } |
206 | 2.40k | Configuration::StatsConfig& statsConfig() override { return server_.statsConfig(); } |
207 | 54 | envoy::config::bootstrap::v3::Bootstrap& bootstrap() override { return server_.bootstrap(); } |
208 | 2.92k | OverloadManager& overloadManager() override { return server_.overloadManager(); } |
209 | 0 | OverloadManager& nullOverloadManager() override { return server_.nullOverloadManager(); } |
210 | 0 | bool healthCheckFailed() const override { return server_.healthCheckFailed(); } |
211 | | |
212 | | // Configuration::TransportSocketFactoryContext |
213 | 0 | ServerFactoryContext& serverFactoryContext() override { return *this; } |
214 | 0 | Ssl::ContextManager& sslContextManager() override { return server_.sslContextManager(); } |
215 | 0 | Secret::SecretManager& secretManager() override { return server_.secretManager(); } |
216 | 0 | Stats::Scope& statsScope() override { return *server_scope_; } |
217 | 15.7k | Init::Manager& initManager() override { return server_.initManager(); } |
218 | 15.7k | ProtobufMessage::ValidationVisitor& messageValidationVisitor() override { |
219 | | // Server has two message validation visitors, one for static and |
220 | | // other for dynamic configuration. Choose the dynamic validation |
221 | | // visitor if server's init manager indicates that the server is |
222 | | // in the Initialized state, as this state is engaged right after |
223 | | // the static configuration (e.g., bootstrap) has been completed. |
224 | 15.7k | return initManager().state() == Init::Manager::State::Initialized |
225 | 15.7k | ? server_.messageValidationContext().dynamicValidationVisitor() |
226 | 15.7k | : server_.messageValidationContext().staticValidationVisitor(); |
227 | 15.7k | } |
228 | | |
229 | | private: |
230 | | Instance& server_; |
231 | | Stats::ScopeSharedPtr server_scope_; |
232 | | }; |
233 | | |
234 | | /** |
235 | | * This is the base class for the standalone server which stitches together various common |
236 | | * components. Some components are optional (so PURE) and can be created or not by subclasses. |
237 | | */ |
238 | | class InstanceBase : Logger::Loggable<Logger::Id::main>, |
239 | | public Instance, |
240 | | public ServerLifecycleNotifier { |
241 | | public: |
242 | | /** |
243 | | * @throw EnvoyException if initialization fails. |
244 | | */ |
245 | | InstanceBase(Init::Manager& init_manager, const Options& options, Event::TimeSystem& time_system, |
246 | | ListenerHooks& hooks, HotRestart& restarter, Stats::StoreRoot& store, |
247 | | Thread::BasicLockable& access_log_lock, |
248 | | Random::RandomGeneratorPtr&& random_generator, ThreadLocal::Instance& tls, |
249 | | Thread::ThreadFactory& thread_factory, Filesystem::Instance& file_system, |
250 | | std::unique_ptr<ProcessContext> process_context, |
251 | | Buffer::WatermarkFactorySharedPtr watermark_factory = nullptr); |
252 | | |
253 | | // initialize the server. This must be called before run(). |
254 | | void initialize(Network::Address::InstanceConstSharedPtr local_address, |
255 | | ComponentFactory& component_factory); |
256 | | ~InstanceBase() override; |
257 | | |
258 | | virtual void maybeCreateHeapShrinker() PURE; |
259 | | virtual absl::StatusOr<std::unique_ptr<OverloadManager>> createOverloadManager() PURE; |
260 | | virtual std::unique_ptr<OverloadManager> createNullOverloadManager() PURE; |
261 | | virtual std::unique_ptr<Server::GuardDog> maybeCreateGuardDog(absl::string_view name) PURE; |
262 | | |
263 | | void run() override; |
264 | | |
265 | | // Server::Instance |
266 | 25.1k | OptRef<Admin> admin() override { return makeOptRefFromPtr(admin_.get()); } |
267 | 77.8k | Api::Api& api() override { return *api_; } |
268 | | Upstream::ClusterManager& clusterManager() override; |
269 | | const Upstream::ClusterManager& clusterManager() const override; |
270 | 4.40k | Http::HttpServerPropertiesCacheManager& httpServerPropertiesCacheManager() override { |
271 | 4.40k | return *http_server_properties_cache_manager_; |
272 | 4.40k | } |
273 | 14.1k | Ssl::ContextManager& sslContextManager() override { return *ssl_context_manager_; } |
274 | 61.2k | Event::Dispatcher& dispatcher() override { return *dispatcher_; } |
275 | 0 | Network::DnsResolverSharedPtr dnsResolver() override { return dns_resolver_; } |
276 | | void drainListeners(OptRef<const Network::ExtraShutdownListenerOptions> options) override; |
277 | 1.34k | DrainManager& drainManager() override { return *drain_manager_; } |
278 | 8.27k | AccessLog::AccessLogManager& accessLogManager() override { return access_log_manager_; } |
279 | | void failHealthcheck(bool fail) override; |
280 | 3.61k | HotRestart& hotRestart() override { return restarter_; } |
281 | 29.4k | Init::Manager& initManager() override { return init_manager_; } |
282 | 0 | ServerLifecycleNotifier& lifecycleNotifier() override { return *this; } |
283 | 8.76k | ListenerManager& listenerManager() override { return *listener_manager_; } |
284 | 3.28k | Secret::SecretManager& secretManager() override { return *secret_manager_; } |
285 | 0 | Envoy::MutexTracer* mutexTracer() override { return mutex_tracer_; } |
286 | 13.8k | OverloadManager& overloadManager() override { return *overload_manager_; } |
287 | 6.42k | OverloadManager& nullOverloadManager() override { return *null_overload_manager_; } |
288 | | Runtime::Loader& runtime() override; |
289 | | void shutdown() override; |
290 | 5.92k | bool isShutdown() final { return shutdown_; } |
291 | | void shutdownAdmin() override; |
292 | 19.8k | Singleton::Manager& singletonManager() override { return singleton_manager_; } |
293 | | bool healthCheckFailed() override; |
294 | 42.1k | const Options& options() override { return options_; } |
295 | 0 | time_t startTimeCurrentEpoch() override { return start_time_; } |
296 | 0 | time_t startTimeFirstEpoch() override { return original_start_time_; } |
297 | 57.4k | Stats::Store& stats() override { return stats_store_; } |
298 | 4.33k | Grpc::Context& grpcContext() override { return grpc_context_; } |
299 | 4.97k | Http::Context& httpContext() override { return http_context_; } |
300 | 8.35k | Router::Context& routerContext() override { return router_context_; } |
301 | | ProcessContextOptRef processContext() override; |
302 | 30.4k | ThreadLocal::Instance& threadLocal() override { return thread_local_; } |
303 | 17.1k | LocalInfo::LocalInfo& localInfo() const override { return *local_info_; } |
304 | 16.4k | TimeSource& timeSource() override { return time_source_; } |
305 | | void flushStats() override; |
306 | 2.40k | Configuration::StatsConfig& statsConfig() override { return config_.statsConfig(); } |
307 | 3.08k | Regex::Engine& regexEngine() override { return *regex_engine_; } |
308 | 4.52k | envoy::config::bootstrap::v3::Bootstrap& bootstrap() override { return bootstrap_; } |
309 | 103k | Configuration::ServerFactoryContext& serverFactoryContext() override { return server_contexts_; } |
310 | 0 | Configuration::TransportSocketFactoryContext& transportSocketFactoryContext() override { |
311 | 0 | return server_contexts_; |
312 | 0 | } |
313 | 56.9k | ProtobufMessage::ValidationContext& messageValidationContext() override { |
314 | 56.9k | return validation_context_; |
315 | 56.9k | } |
316 | 4.40k | void setDefaultTracingConfig(const envoy::config::trace::v3::Tracing& tracing_config) override { |
317 | 4.40k | http_context_.setDefaultTracingConfig(tracing_config); |
318 | 4.40k | } |
319 | | bool enableReusePortDefault() override; |
320 | | |
321 | 0 | Quic::QuicStatNames& quicStatNames() { return quic_stat_names_; } |
322 | | |
323 | 0 | void setSinkPredicates(std::unique_ptr<Envoy::Stats::SinkPredicates>&& sink_predicates) override { |
324 | 0 | stats_store_.setSinkPredicates(std::move(sink_predicates)); |
325 | 0 | } |
326 | | |
327 | | // ServerLifecycleNotifier |
328 | | ServerLifecycleNotifier::HandlePtr registerCallback(Stage stage, StageCallback callback) override; |
329 | | ServerLifecycleNotifier::HandlePtr |
330 | | registerCallback(Stage stage, StageCallbackWithCompletion callback) override; |
331 | | |
332 | | protected: |
333 | 6.11k | const Configuration::MainImpl& config() { return config_; } |
334 | | |
335 | | private: |
336 | | Network::DnsResolverSharedPtr getOrCreateDnsResolver(); |
337 | | |
338 | | ProtobufTypes::MessagePtr dumpBootstrapConfig(); |
339 | | void flushStatsInternal(); |
340 | | void updateServerStats(); |
341 | | // This does most of the work of initialization, but can throw or return errors caught |
342 | | // by initialize(). |
343 | | absl::Status initializeOrThrow(Network::Address::InstanceConstSharedPtr local_address, |
344 | | ComponentFactory& component_factory); |
345 | | void loadServerFlags(const absl::optional<std::string>& flags_path); |
346 | | void startWorkers(); |
347 | | void terminate(); |
348 | | void notifyCallbacksForStage( |
349 | 3.95k | Stage stage, std::function<void()> completion_cb = [] {}); |
350 | | void onRuntimeReady(); |
351 | | void onClusterManagerPrimaryInitializationComplete(); |
352 | | using LifecycleNotifierCallbacks = std::list<StageCallback>; |
353 | | using LifecycleNotifierCompletionCallbacks = std::list<StageCallbackWithCompletion>; |
354 | | |
355 | | // init_manager_ must come before any member that participates in initialization, and destructed |
356 | | // only after referencing members are gone, since initialization continuation can potentially |
357 | | // occur at any point during member lifetime. This init manager is populated with LdsApi targets. |
358 | | Init::Manager& init_manager_; |
359 | | // secret_manager_ must come before listener_manager_, config_ and dispatcher_, and destructed |
360 | | // only after these members can no longer reference it, since: |
361 | | // - There may be active filter chains referencing it in listener_manager_. |
362 | | // - There may be active clusters referencing it in config_.cluster_manager_. |
363 | | // - There may be active connections referencing it. |
364 | | std::unique_ptr<Secret::SecretManager> secret_manager_; |
365 | | bool workers_started_{false}; |
366 | | std::atomic<bool> live_; |
367 | | bool shutdown_{false}; |
368 | | const Options& options_; |
369 | | ProtobufMessage::ProdValidationContextImpl validation_context_; |
370 | | TimeSource& time_source_; |
371 | | // Delete local_info_ as late as possible as some members below may reference it during their |
372 | | // destruction. |
373 | | LocalInfo::LocalInfoPtr local_info_; |
374 | | HotRestart& restarter_; |
375 | | const time_t start_time_; |
376 | | time_t original_start_time_; |
377 | | Stats::StoreRoot& stats_store_; |
378 | | std::unique_ptr<ServerStats> server_stats_; |
379 | | std::unique_ptr<CompilationSettings::ServerCompilationSettingsStats> |
380 | | server_compilation_settings_stats_; |
381 | | Assert::ActionRegistrationPtr assert_action_registration_; |
382 | | Assert::ActionRegistrationPtr envoy_bug_action_registration_; |
383 | | ThreadLocal::Instance& thread_local_; |
384 | | Random::RandomGeneratorPtr random_generator_; |
385 | | envoy::config::bootstrap::v3::Bootstrap bootstrap_; |
386 | | Api::ApiPtr api_; |
387 | | // ssl_context_manager_ must come before dispatcher_, since ClusterInfo |
388 | | // references SslSocketFactory and is deleted on the main thread via the dispatcher. |
389 | | std::unique_ptr<Ssl::ContextManager> ssl_context_manager_; |
390 | | Event::DispatcherPtr dispatcher_; |
391 | | AccessLog::AccessLogManagerImpl access_log_manager_; |
392 | | std::shared_ptr<Admin> admin_; |
393 | | Singleton::ManagerImpl singleton_manager_; |
394 | | Network::ConnectionHandlerPtr handler_; |
395 | | std::unique_ptr<Runtime::Loader> runtime_; |
396 | | ProdWorkerFactory worker_factory_; |
397 | | std::unique_ptr<ListenerManager> listener_manager_; |
398 | | absl::node_hash_map<Stage, LifecycleNotifierCallbacks> stage_callbacks_; |
399 | | absl::node_hash_map<Stage, LifecycleNotifierCompletionCallbacks> stage_completable_callbacks_; |
400 | | Configuration::MainImpl config_; |
401 | | Network::DnsResolverSharedPtr dns_resolver_; |
402 | | Event::TimerPtr stat_flush_timer_; |
403 | | DrainManagerPtr drain_manager_; |
404 | | std::unique_ptr<Upstream::ClusterManagerFactory> cluster_manager_factory_; |
405 | | std::unique_ptr<Server::GuardDog> main_thread_guard_dog_; |
406 | | std::unique_ptr<Server::GuardDog> worker_guard_dog_; |
407 | | bool terminated_{false}; |
408 | | std::unique_ptr<Logger::FileSinkDelegate> file_logger_; |
409 | | ConfigTracker::EntryOwnerPtr config_tracker_entry_; |
410 | | SystemTime bootstrap_config_update_time_; |
411 | | Grpc::AsyncClientManagerPtr async_client_manager_; |
412 | | Upstream::ProdClusterInfoFactory info_factory_; |
413 | | Upstream::HdsDelegatePtr hds_delegate_; |
414 | | std::unique_ptr<OverloadManager> overload_manager_; |
415 | | std::unique_ptr<OverloadManager> null_overload_manager_; |
416 | | std::vector<BootstrapExtensionPtr> bootstrap_extensions_; |
417 | | std::unique_ptr<Http::HttpServerPropertiesCacheManager> http_server_properties_cache_manager_; |
418 | | Envoy::MutexTracer* mutex_tracer_; |
419 | | Grpc::ContextImpl grpc_context_; |
420 | | Http::ContextImpl http_context_; |
421 | | Router::ContextImpl router_context_; |
422 | | std::unique_ptr<ProcessContext> process_context_; |
423 | | // initialization_time is a histogram for tracking the initialization time across hot restarts |
424 | | // whenever we have support for histogram merge across hot restarts. |
425 | | Stats::TimespanPtr initialization_timer_; |
426 | | ListenerHooks& hooks_; |
427 | | Quic::QuicStatNames quic_stat_names_; |
428 | | ServerFactoryContextImpl server_contexts_; |
429 | | bool enable_reuse_port_default_{false}; |
430 | | Regex::EnginePtr regex_engine_; |
431 | | bool stats_flush_in_progress_ : 1; |
432 | | std::unique_ptr<Memory::AllocatorManager> memory_allocator_manager_; |
433 | | |
434 | | template <class T> |
435 | | class LifecycleCallbackHandle : public ServerLifecycleNotifier::Handle, RaiiListElement<T> { |
436 | | public: |
437 | | LifecycleCallbackHandle(std::list<T>& callbacks, T& callback) |
438 | 0 | : RaiiListElement<T>(callbacks, callback) {} Unexecuted instantiation: Envoy::Server::InstanceBase::LifecycleCallbackHandle<std::__1::function<void ()> >::LifecycleCallbackHandle(std::__1::list<std::__1::function<void ()>, std::__1::allocator<std::__1::function<void ()> > >&, std::__1::function<void ()>&) Unexecuted instantiation: Envoy::Server::InstanceBase::LifecycleCallbackHandle<std::__1::function<void (absl::lts_20230802::AnyInvocable<void ()>)> >::LifecycleCallbackHandle(std::__1::list<std::__1::function<void (absl::lts_20230802::AnyInvocable<void ()>)>, std::__1::allocator<std::__1::function<void (absl::lts_20230802::AnyInvocable<void ()>)> > >&, std::__1::function<void (absl::lts_20230802::AnyInvocable<void ()>)>&) |
439 | | }; |
440 | | |
441 | | #ifdef ENVOY_PERFETTO |
442 | | std::unique_ptr<perfetto::TracingSession> tracing_session_{}; |
443 | | os_fd_t tracing_fd_{INVALID_HANDLE}; |
444 | | #endif |
445 | | }; |
446 | | |
447 | | // Local implementation of Stats::MetricSnapshot used to flush metrics to sinks. We could |
448 | | // potentially have a single class instance held in a static and have a clear() method to avoid some |
449 | | // vector constructions and reservations, but I'm not sure it's worth the extra complexity until it |
450 | | // shows up in perf traces. |
451 | | // TODO(mattklein123): One thing we probably want to do is switch from returning vectors of metrics |
452 | | // to a lambda based callback iteration API. This would require less vector |
453 | | // copying and probably be a cleaner API in general. |
454 | | class MetricSnapshotImpl : public Stats::MetricSnapshot { |
455 | | public: |
456 | | explicit MetricSnapshotImpl(Stats::Store& store, Upstream::ClusterManager& cluster_manager, |
457 | | TimeSource& time_source); |
458 | | |
459 | | // Stats::MetricSnapshot |
460 | 0 | const std::vector<CounterSnapshot>& counters() override { return counters_; } |
461 | 0 | const std::vector<std::reference_wrapper<const Stats::Gauge>>& gauges() override { |
462 | 0 | return gauges_; |
463 | 0 | }; |
464 | 0 | const std::vector<std::reference_wrapper<const Stats::ParentHistogram>>& histograms() override { |
465 | 0 | return histograms_; |
466 | 0 | } |
467 | 0 | const std::vector<std::reference_wrapper<const Stats::TextReadout>>& textReadouts() override { |
468 | 0 | return text_readouts_; |
469 | 0 | } |
470 | 0 | const std::vector<Stats::PrimitiveCounterSnapshot>& hostCounters() override { |
471 | 0 | return host_counters_; |
472 | 0 | } |
473 | 0 | const std::vector<Stats::PrimitiveGaugeSnapshot>& hostGauges() override { return host_gauges_; } |
474 | 0 | SystemTime snapshotTime() const override { return snapshot_time_; } |
475 | | |
476 | | private: |
477 | | std::vector<Stats::CounterSharedPtr> snapped_counters_; |
478 | | std::vector<CounterSnapshot> counters_; |
479 | | std::vector<Stats::GaugeSharedPtr> snapped_gauges_; |
480 | | std::vector<std::reference_wrapper<const Stats::Gauge>> gauges_; |
481 | | std::vector<Stats::ParentHistogramSharedPtr> snapped_histograms_; |
482 | | std::vector<std::reference_wrapper<const Stats::ParentHistogram>> histograms_; |
483 | | std::vector<Stats::TextReadoutSharedPtr> snapped_text_readouts_; |
484 | | std::vector<std::reference_wrapper<const Stats::TextReadout>> text_readouts_; |
485 | | std::vector<Stats::PrimitiveCounterSnapshot> host_counters_; |
486 | | std::vector<Stats::PrimitiveGaugeSnapshot> host_gauges_; |
487 | | SystemTime snapshot_time_; |
488 | | }; |
489 | | |
490 | | } // namespace Server |
491 | | } // namespace Envoy |