LCOV - code coverage report
Current view: top level - source/common/upstream - od_cds_api_impl.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 1 2 50.0 %
Date: 2024-01-05 06:35:25 Functions: 1 2 50.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <string>
       4             : #include <vector>
       5             : 
       6             : #include "envoy/config/cluster/v3/cluster.pb.h"
       7             : #include "envoy/config/cluster/v3/cluster.pb.validate.h"
       8             : #include "envoy/config/core/v3/config_source.pb.h"
       9             : #include "envoy/config/subscription.h"
      10             : #include "envoy/protobuf/message_validator.h"
      11             : #include "envoy/stats/scope.h"
      12             : #include "envoy/upstream/cluster_manager.h"
      13             : 
      14             : #include "source/common/config/subscription_base.h"
      15             : #include "source/common/protobuf/protobuf.h"
      16             : #include "source/common/upstream/cds_api_helper.h"
      17             : 
      18             : namespace Envoy {
      19             : namespace Upstream {
      20             : 
      21             : enum class StartStatus {
      22             :   // No initial fetch started.
      23             :   NotStarted,
      24             :   // Initial fetch started.
      25             :   Started,
      26             :   // Initial fetch arrived.
      27             :   InitialFetchDone,
      28             : };
      29             : 
      30             : /**
      31             :  * An interface for on-demand CDS. Defined to allow mocking.
      32             :  */
      33             : class OdCdsApi {
      34             : public:
      35           0 :   virtual ~OdCdsApi() = default;
      36             : 
      37             :   // Subscribe to a cluster with a given name. It's meant to eventually send a discovery request
      38             :   // with the cluster name to the management server.
      39             :   virtual void updateOnDemand(std::string cluster_name) PURE;
      40             : };
      41             : 
      42             : using OdCdsApiSharedPtr = std::shared_ptr<OdCdsApi>;
      43             : 
      44             : /**
      45             :  * An interface used by OdCdsApiImpl for sending notifications about the missing cluster that was
      46             :  * requested.
      47             :  */
      48             : class MissingClusterNotifier {
      49             : public:
      50         131 :   virtual ~MissingClusterNotifier() = default;
      51             : 
      52             :   virtual void notifyMissingCluster(absl::string_view name) PURE;
      53             : };
      54             : 
      55             : /**
      56             :  * ODCDS API implementation that fetches via Subscription.
      57             :  */
      58             : class OdCdsApiImpl : public OdCdsApi,
      59             :                      Envoy::Config::SubscriptionBase<envoy::config::cluster::v3::Cluster>,
      60             :                      Logger::Loggable<Logger::Id::upstream> {
      61             : public:
      62             :   static OdCdsApiSharedPtr create(const envoy::config::core::v3::ConfigSource& odcds_config,
      63             :                                   OptRef<xds::core::v3::ResourceLocator> odcds_resources_locator,
      64             :                                   ClusterManager& cm, MissingClusterNotifier& notifier,
      65             :                                   Stats::Scope& scope,
      66             :                                   ProtobufMessage::ValidationVisitor& validation_visitor);
      67             : 
      68             :   // Upstream::OdCdsApi
      69             :   void updateOnDemand(std::string cluster_name) override;
      70             : 
      71             : private:
      72             :   // Config::SubscriptionCallbacks
      73             :   absl::Status onConfigUpdate(const std::vector<Config::DecodedResourceRef>& resources,
      74             :                               const std::string& version_info) override;
      75             :   absl::Status onConfigUpdate(const std::vector<Config::DecodedResourceRef>& added_resources,
      76             :                               const Protobuf::RepeatedPtrField<std::string>& removed_resources,
      77             :                               const std::string& system_version_info) override;
      78             :   void onConfigUpdateFailed(Envoy::Config::ConfigUpdateFailureReason reason,
      79             :                             const EnvoyException* e) override;
      80             : 
      81             :   OdCdsApiImpl(const envoy::config::core::v3::ConfigSource& odcds_config,
      82             :                OptRef<xds::core::v3::ResourceLocator> odcds_resources_locator, ClusterManager& cm,
      83             :                MissingClusterNotifier& notifier, Stats::Scope& scope,
      84             :                ProtobufMessage::ValidationVisitor& validation_visitor);
      85             :   void sendAwaiting();
      86             : 
      87             :   CdsApiHelper helper_;
      88             :   ClusterManager& cm_;
      89             :   MissingClusterNotifier& notifier_;
      90             :   Stats::ScopeSharedPtr scope_;
      91             :   StartStatus status_{StartStatus::NotStarted};
      92             :   absl::flat_hash_set<std::string> awaiting_names_;
      93             :   Config::SubscriptionPtr subscription_;
      94             : };
      95             : 
      96             : } // namespace Upstream
      97             : } // namespace Envoy

Generated by: LCOV version 1.15