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