Coverage Report

Created: 2024-09-19 09:45

/proc/self/cwd/envoy/config/subscription_factory.h
Line
Count
Source
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
32.3k
  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
14
  isPathBasedConfigSource(envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase type) {
41
14
    return type == envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase::kPath ||
42
14
           type ==
43
14
               envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase::kPathConfigSource;
44
14
  }
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 or error
58
   * status.
59
   */
60
  virtual absl::StatusOr<SubscriptionPtr> subscriptionFromConfigSource(
61
      const envoy::config::core::v3::ConfigSource& config, absl::string_view type_url,
62
      Stats::Scope& scope, SubscriptionCallbacks& callbacks,
63
      OpaqueResourceDecoderSharedPtr resource_decoder, const SubscriptionOptions& options) PURE;
64
65
  /**
66
   * Collection subscription factory interface for xDS-TP URLs.
67
   *
68
   * @param collection_locator collection resource locator.
69
   * @param config envoy::config::core::v3::ConfigSource for authority resolution.
70
   * @param type_url type URL for the resources inside the collection.
71
   * @param scope stats scope for any stats tracked by the subscription.
72
   * @param callbacks the callbacks needed by all [Collection]Subscription objects, to deliver
73
   *                  config updates. The callbacks must not result in the deletion of the
74
   *                  CollectionSubscription object.
75
   * @param resource_decoder how incoming opaque resource objects are to be decoded.
76
   *
77
   * @return SubscriptionPtr subscription object corresponding for collection_locator or error
78
   * status.
79
   */
80
  virtual absl::StatusOr<SubscriptionPtr>
81
  collectionSubscriptionFromUrl(const xds::core::v3::ResourceLocator& collection_locator,
82
                                const envoy::config::core::v3::ConfigSource& config,
83
                                absl::string_view type_url, Stats::Scope& scope,
84
                                SubscriptionCallbacks& callbacks,
85
                                OpaqueResourceDecoderSharedPtr resource_decoder) PURE;
86
};
87
88
// A factory class that individual config subscriptions can subclass to be factory-created.
89
class ConfigSubscriptionFactory : public Config::UntypedFactory {
90
public:
91
  struct SubscriptionData {
92
    const LocalInfo::LocalInfo& local_info_;
93
    Event::Dispatcher& dispatcher_;
94
    Upstream::ClusterManager& cm_;
95
    ProtobufMessage::ValidationVisitor& validation_visitor_;
96
    Api::Api& api_;
97
    const Server::Instance& server_;
98
    OptRef<XdsResourcesDelegate> xds_resources_delegate_;
99
    OptRef<XdsConfigTracker> xds_config_tracker_;
100
101
    const envoy::config::core::v3::ConfigSource& config_;
102
    absl::string_view type_url_;
103
    Stats::Scope& scope_;
104
    SubscriptionCallbacks& callbacks_;
105
    OpaqueResourceDecoderSharedPtr resource_decoder_;
106
    const SubscriptionOptions& options_;
107
    OptRef<const xds::core::v3::ResourceLocator> collection_locator_;
108
    SubscriptionStats stats_;
109
  };
110
111
238
  std::string category() const override { return "envoy.config_subscription"; }
112
  virtual SubscriptionPtr create(SubscriptionData& data) PURE;
113
};
114
115
class MuxFactory : public Config::UntypedFactory {
116
public:
117
130
  std::string category() const override { return "envoy.config_mux"; }
118
  virtual void shutdownAll() PURE;
119
  virtual std::shared_ptr<GrpcMux>
120
  create(std::unique_ptr<Grpc::RawAsyncClient>&& async_client,
121
         std::unique_ptr<Grpc::RawAsyncClient>&& async_failover_client,
122
         Event::Dispatcher& dispatcher, Random::RandomGenerator& random, Stats::Scope& scope,
123
         const envoy::config::core::v3::ApiConfigSource& ads_config,
124
         const LocalInfo::LocalInfo& local_info,
125
         std::unique_ptr<CustomConfigValidators>&& config_validators,
126
         BackOffStrategyPtr&& backoff_strategy, OptRef<XdsConfigTracker> xds_config_tracker,
127
         OptRef<XdsResourcesDelegate> xds_resources_delegate, bool use_eds_resources_cache) PURE;
128
};
129
130
} // namespace Config
131
} // namespace Envoy