LCOV - code coverage report
Current view: top level - source/server - server.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 84 121 69.4 %
Date: 2024-01-05 06:35:25 Functions: 51 78 65.4 %

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

Generated by: LCOV version 1.15