LCOV - code coverage report
Current view: top level - envoy/config - subscription_factory.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 8 8 100.0 %
Date: 2024-01-05 06:35:25 Functions: 4 4 100.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "envoy/api/api.h"
       4             : #include "envoy/common/backoff_strategy.h"
       5             : #include "envoy/config/core/v3/config_source.pb.h"
       6             : #include "envoy/config/custom_config_validators.h"
       7             : #include "envoy/config/grpc_mux.h"
       8             : #include "envoy/config/subscription.h"
       9             : #include "envoy/config/typed_config.h"
      10             : #include "envoy/local_info/local_info.h"
      11             : #include "envoy/protobuf/message_validator.h"
      12             : #include "envoy/stats/scope.h"
      13             : 
      14             : #include "xds/core/v3/resource_locator.pb.h"
      15             : 
      16             : namespace Envoy {
      17             : 
      18             : namespace Server {
      19             : class Instance;
      20             : } // namespace Server
      21             : namespace Grpc {
      22             : class RawAsyncClient;
      23             : } // namespace Grpc
      24             : 
      25             : namespace Config {
      26             : class XdsResourcesDelegate;
      27             : class XdsConfigTracker;
      28             : 
      29             : class SubscriptionFactory {
      30             : public:
      31         317 :   virtual ~SubscriptionFactory() = default;
      32             : 
      33             :   static constexpr uint32_t RetryInitialDelayMs = 500;
      34             :   static constexpr uint32_t RetryMaxDelayMs = 30000; // Do not cross more than 30s
      35             : 
      36             :   /**
      37             :    * @return true if a config source comes from the local filesystem.
      38             :    */
      39             :   static bool
      40          28 :   isPathBasedConfigSource(envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase type) {
      41          28 :     return type == envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase::kPath ||
      42          28 :            type ==
      43          28 :                envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase::kPathConfigSource;
      44          28 :   }
      45             : 
      46             :   /**
      47             :    * Subscription factory interface.
      48             :    *
      49             :    * @param config envoy::config::core::v3::ConfigSource to construct from.
      50             :    * @param type_url type URL for the resource being subscribed to.
      51             :    * @param scope stats scope for any stats tracked by the subscription.
      52             :    * @param callbacks the callbacks needed by all Subscription objects, to deliver config updates.
      53             :    *                  The callbacks must not result in the deletion of the Subscription object.
      54             :    * @param resource_decoder how incoming opaque resource objects are to be decoded.
      55             :    * @param options subscription options.
      56             :    *
      57             :    * @return SubscriptionPtr subscription object corresponding for config and type_url.
      58             :    */
      59             :   virtual SubscriptionPtr subscriptionFromConfigSource(
      60             :       const envoy::config::core::v3::ConfigSource& config, absl::string_view type_url,
      61             :       Stats::Scope& scope, SubscriptionCallbacks& callbacks,
      62             :       OpaqueResourceDecoderSharedPtr resource_decoder, const SubscriptionOptions& options) PURE;
      63             : 
      64             :   /**
      65             :    * Collection subscription factory interface for xDS-TP URLs.
      66             :    *
      67             :    * @param collection_locator collection resource locator.
      68             :    * @param config envoy::config::core::v3::ConfigSource for authority resolution.
      69             :    * @param type_url type URL for the resources inside the collection.
      70             :    * @param scope stats scope for any stats tracked by the subscription.
      71             :    * @param callbacks the callbacks needed by all [Collection]Subscription objects, to deliver
      72             :    *                  config updates. The callbacks must not result in the deletion of the
      73             :    *                  CollectionSubscription object.
      74             :    * @param resource_decoder how incoming opaque resource objects are to be decoded.
      75             :    *
      76             :    * @return SubscriptionPtr subscription object corresponding for collection_locator.
      77             :    */
      78             :   virtual SubscriptionPtr
      79             :   collectionSubscriptionFromUrl(const xds::core::v3::ResourceLocator& collection_locator,
      80             :                                 const envoy::config::core::v3::ConfigSource& config,
      81             :                                 absl::string_view type_url, Stats::Scope& scope,
      82             :                                 SubscriptionCallbacks& callbacks,
      83             :                                 OpaqueResourceDecoderSharedPtr resource_decoder) PURE;
      84             : };
      85             : 
      86             : // A factory class that individual config subscriptions can subclass to be factory-created.
      87             : class ConfigSubscriptionFactory : public Config::UntypedFactory {
      88             : public:
      89             :   struct SubscriptionData {
      90             :     const LocalInfo::LocalInfo& local_info_;
      91             :     Event::Dispatcher& dispatcher_;
      92             :     Upstream::ClusterManager& cm_;
      93             :     ProtobufMessage::ValidationVisitor& validation_visitor_;
      94             :     Api::Api& api_;
      95             :     const Server::Instance& server_;
      96             :     OptRef<XdsResourcesDelegate> xds_resources_delegate_;
      97             :     OptRef<XdsConfigTracker> xds_config_tracker_;
      98             : 
      99             :     const envoy::config::core::v3::ConfigSource& config_;
     100             :     absl::string_view type_url_;
     101             :     Stats::Scope& scope_;
     102             :     SubscriptionCallbacks& callbacks_;
     103             :     OpaqueResourceDecoderSharedPtr resource_decoder_;
     104             :     const SubscriptionOptions& options_;
     105             :     OptRef<const xds::core::v3::ResourceLocator> collection_locator_;
     106             :     SubscriptionStats stats_;
     107             :   };
     108             : 
     109         119 :   std::string category() const override { return "envoy.config_subscription"; }
     110             :   virtual SubscriptionPtr create(SubscriptionData& data) PURE;
     111             : };
     112             : 
     113             : class MuxFactory : public Config::UntypedFactory {
     114             : public:
     115          65 :   std::string category() const override { return "envoy.config_mux"; }
     116             :   virtual void shutdownAll() PURE;
     117             :   virtual std::shared_ptr<GrpcMux>
     118             :   create(std::unique_ptr<Grpc::RawAsyncClient>&& async_client, Event::Dispatcher& dispatcher,
     119             :          Random::RandomGenerator& random, Stats::Scope& scope,
     120             :          const envoy::config::core::v3::ApiConfigSource& ads_config,
     121             :          const LocalInfo::LocalInfo& local_info,
     122             :          std::unique_ptr<CustomConfigValidators>&& config_validators,
     123             :          BackOffStrategyPtr&& backoff_strategy, OptRef<XdsConfigTracker> xds_config_tracker,
     124             :          OptRef<XdsResourcesDelegate> xds_resources_delegate, bool use_eds_resources_cache) PURE;
     125             : };
     126             : 
     127             : } // namespace Config
     128             : } // namespace Envoy

Generated by: LCOV version 1.15