Line data Source code
1 : #pragma once 2 : 3 : #include <memory> 4 : #include <string> 5 : 6 : #include "envoy/config/core/v3/config_source.pb.h" 7 : #include "envoy/config/subscription.h" 8 : #include "envoy/rds/route_config_provider.h" 9 : #include "envoy/rds/route_config_update_receiver.h" 10 : #include "envoy/server/factory_context.h" 11 : #include "envoy/stats/scope.h" 12 : 13 : #include "source/common/grpc/common.h" 14 : #include "source/common/init/manager_impl.h" 15 : #include "source/common/init/target_impl.h" 16 : #include "source/common/init/watcher_impl.h" 17 : #include "source/common/rds/route_config_provider_manager.h" 18 : 19 : #include "absl/types/optional.h" 20 : 21 : namespace Envoy { 22 : namespace Rds { 23 : 24 : /** 25 : * All RDS stats. @see stats_macros.h 26 : */ 27 : #define ALL_RDS_STATS(COUNTER, GAUGE) \ 28 : COUNTER(config_reload) \ 29 : COUNTER(update_empty) \ 30 : GAUGE(config_reload_time_ms, NeverImport) 31 : 32 : /** 33 : * Struct definition for all RDS stats. @see stats_macros.h 34 : */ 35 : struct RdsStats { 36 : ALL_RDS_STATS(GENERATE_COUNTER_STRUCT, GENERATE_GAUGE_STRUCT) 37 : }; 38 : 39 : /** 40 : * A class that fetches the route configuration dynamically using the RDS API and updates them to 41 : * RDS config providers. 42 : */ 43 : class RdsRouteConfigSubscription : Envoy::Config::SubscriptionCallbacks, 44 : protected Logger::Loggable<Logger::Id::rds> { 45 : public: 46 : RdsRouteConfigSubscription(RouteConfigUpdatePtr&& config_update, 47 : Envoy::Config::OpaqueResourceDecoderSharedPtr&& resource_decoder, 48 : const envoy::config::core::v3::ConfigSource& config_source, 49 : const std::string& route_config_name, 50 : const uint64_t manager_identifier, 51 : Server::Configuration::ServerFactoryContext& factory_context, 52 : const std::string& stat_prefix, const std::string& rds_type, 53 : RouteConfigProviderManager& route_config_provider_manager); 54 : 55 : ~RdsRouteConfigSubscription() override; 56 : 57 150 : RouteConfigProvider*& routeConfigProvider() { return route_config_provider_; } 58 : 59 50 : RouteConfigUpdatePtr& routeConfigUpdate() { return config_update_info_; } 60 : 61 50 : const Init::Target& initTarget() { return parent_init_target_; } 62 : 63 : private: 64 : // Config::SubscriptionCallbacks 65 : absl::Status onConfigUpdate(const std::vector<Envoy::Config::DecodedResourceRef>& resources, 66 : const std::string& version_info) override; 67 : 68 : absl::Status onConfigUpdate(const std::vector<Envoy::Config::DecodedResourceRef>& added_resources, 69 : const Protobuf::RepeatedPtrField<std::string>& removed_resources, 70 : const std::string&) override; 71 : 72 : void onConfigUpdateFailed(Envoy::Config::ConfigUpdateFailureReason reason, 73 : const EnvoyException*) override; 74 : 75 : virtual void beforeProviderUpdate(std::unique_ptr<Init::ManagerImpl>&, 76 0 : std::unique_ptr<Cleanup>&) {} 77 0 : virtual void afterProviderUpdate() {} 78 : 79 : protected: 80 : const std::string route_config_name_; 81 : // This scope must outlive the subscription_ below as the subscription has derived stats. 82 : Stats::ScopeSharedPtr scope_; 83 : Envoy::Config::SubscriptionPtr subscription_; 84 : Server::Configuration::ServerFactoryContext& factory_context_; 85 : 86 : // Init target used to notify the parent init manager that the subscription [and its sub resource] 87 : // is ready. 88 : Init::SharedTargetImpl parent_init_target_; 89 : // Init watcher on RDS and VHDS ready event. This watcher marks parent_init_target_ ready. 90 : Init::WatcherImpl local_init_watcher_; 91 : // Target which starts the RDS subscription. 92 : Init::TargetImpl local_init_target_; 93 : Init::ManagerImpl local_init_manager_; 94 : const std::string stat_prefix_; 95 : const std::string rds_type_; 96 : RdsStats stats_; 97 : RouteConfigProviderManager& route_config_provider_manager_; 98 : const uint64_t manager_identifier_; 99 : RouteConfigProvider* route_config_provider_{nullptr}; 100 : RouteConfigUpdatePtr config_update_info_; 101 : Envoy::Config::OpaqueResourceDecoderSharedPtr resource_decoder_; 102 : }; 103 : 104 : using RdsRouteConfigSubscriptionSharedPtr = std::shared_ptr<RdsRouteConfigSubscription>; 105 : 106 : } // namespace Rds 107 : } // namespace Envoy