Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion envoy/config/config_provider_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "envoy/config/config_provider.h"
#include "envoy/server/filter_config.h"
#include "envoy/singleton/instance.h"

#include "source/common/protobuf/protobuf.h"

Expand All @@ -23,7 +24,7 @@ namespace Config {
* growth based on the size of the configuration set, regardless of the number of threads/objects
* that must hold a reference/pointer to them.
*/
class ConfigProviderManager {
class ConfigProviderManager : public Singleton::Instance {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see why one would like to have a ConfigProviderManager as singleton, but it is unclear to me what triggered the change moving the Singleton inheritance from the implementation to the interface?
(I'm assuming this is something related to C++'s unique_ptr not aligned well with inheritance, but just want to make sure this change is needed).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the implementation code which now only knows it has the interface but not the impl needs to know it is holding a singleton

public:
class OptionalArg {
public:
Expand Down
1 change: 1 addition & 0 deletions envoy/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ envoy_cc_library(
hdrs = ["route_config_provider_manager.h"],
deps = [
":rds_interface",
"//envoy/config:config_provider_manager_interface",
"//envoy/event:dispatcher_interface",
"//envoy/json:json_object_interface",
"//envoy/local_info:local_info_interface",
Expand Down
27 changes: 27 additions & 0 deletions envoy/router/route_config_provider_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <memory>
#include <string>

#include "envoy/config/config_provider_manager.h"
#include "envoy/config/route/v3/route.pb.h"
#include "envoy/config/typed_config.h"
#include "envoy/event/dispatcher.h"
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.h"
#include "envoy/json/json_object.h"
Expand Down Expand Up @@ -59,5 +61,30 @@ class RouteConfigProviderManager {
using RouteConfigProviderManagerPtr = std::unique_ptr<RouteConfigProviderManager>;
using RouteConfigProviderManagerSharedPtr = std::shared_ptr<RouteConfigProviderManager>;

// This factory exists to avoid direct-linking the SRDS libraries into Envoy so
// they can be compiled or substituted out.
class SrdsFactory : public Envoy::Config::UntypedFactory {
public:
// UntypedFactory
virtual std::string category() const override { return "envoy.srds_factory"; }
virtual std::unique_ptr<Envoy::Config::ConfigProviderManager>
createScopedRoutesConfigProviderManager(
Server::Configuration::ServerFactoryContext& factory_context,
Router::RouteConfigProviderManager& route_config_provider_manager) PURE;
// If enabled in the HttpConnectionManager config, returns a ConfigProvider for scoped routing
// configuration.
virtual Envoy::Config::ConfigProviderPtr createConfigProvider(
const envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
config,
Server::Configuration::ServerFactoryContext& factory_context, const std::string& stat_prefix,
Envoy::Config::ConfigProviderManager& scoped_routes_config_provider_manager) PURE;

// If enabled in the HttpConnectionManager config, returns a ConfigProvider for scoped routing
// configuration.
virtual ScopeKeyBuilderPtr createScopeKeyBuilder(
const envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
config) PURE;
};

} // namespace Router
} // namespace Envoy
2 changes: 0 additions & 2 deletions mobile/envoy_build_config/extension_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ void ExtensionRegistry::registerFactories() {
// These are required to support specific route configs, if they are on.
// It's likely no current users of E-M require them so we could optionally compile out by default.
Router::forceRegisterDefaultEarlyDataPolicyFactory();
Router::forceRegisterRouteListMatchActionFactory();
Router::forceRegisterRouteMatchActionFactory();
Extensions::UriTemplate::Match::forceRegisterUriTemplateMatcherFactory();
Extensions::UriTemplate::Rewrite::forceRegisterUriTemplateRewriterFactory();
Http::Matching::forceRegisterHttpRequestHeadersDataInputFactory();
Expand Down
1 change: 1 addition & 0 deletions mobile/test/performance/files_em_does_not_use
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ source/server/guarddog_impl.h
source/server/watchdog_impl.h
source/server/options_impl.cc
source/extensions/access_loggers/common/file_access_log_impl.h
source/common/router/scoped_rds.h
2 changes: 1 addition & 1 deletion source/common/config/config_provider_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class MutableConfigProviderCommonBase : public ConfigProvider {
* This class can not be instantiated directly; instead, it provides the foundation for
* dynamic config provider implementations which derive from it.
*/
class ConfigProviderManagerImplBase : public ConfigProviderManager, public Singleton::Instance {
class ConfigProviderManagerImplBase : public ConfigProviderManager {
public:
/**
* This is invoked by the /config_dump admin handler.
Expand Down
10 changes: 5 additions & 5 deletions source/common/router/scoped_rds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,11 @@ makeScopedRouteInfos(ProtobufTypes::ConstMessagePtrVector&& config_protos,
MessageUtil::downcastAndValidate<const envoy::config::route::v3::ScopedRouteConfiguration&>(
*config_proto, factory_context.messageValidationContext().staticValidationVisitor());
if (!scoped_route_config.route_configuration_name().empty()) {
throwEnvoyExceptionOrPanic(
"Fetching routes via RDS (route_configuration_name) is not supported "
"with inline scoped routes.");
throw EnvoyException("Fetching routes via RDS (route_configuration_name) is not supported "
"with inline scoped routes.");
}
if (!scoped_route_config.has_route_configuration()) {
throwEnvoyExceptionOrPanic(
"You must specify a route_configuration with inline scoped routes.");
throw EnvoyException("You must specify a route_configuration with inline scoped routes.");
}
RouteConfigProviderPtr route_config_provider =
config_provider_manager.routeConfigProviderManager().createStaticRouteConfigProvider(
Expand Down Expand Up @@ -636,5 +634,7 @@ ConfigProviderPtr ScopedRoutesConfigProviderManager::createStaticConfigProvider(
typed_optarg.rds_config_source_);
}

REGISTER_FACTORY(SrdsFactoryDefault, SrdsFactory);

} // namespace Router
} // namespace Envoy
32 changes: 32 additions & 0 deletions source/common/router/scoped_rds.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,37 @@ class ScopedRoutesConfigProviderManagerOptArg
const envoy::config::core::v3::ConfigSource& rds_config_source_;
};

class SrdsFactoryDefault : public SrdsFactory {
public:
// UntypedFactory
virtual std::string name() const override { return "envoy.srds_factory.default"; }

virtual std::unique_ptr<Envoy::Config::ConfigProviderManager>
createScopedRoutesConfigProviderManager(
Server::Configuration::ServerFactoryContext& factory_context,
RouteConfigProviderManager& route_config_provider_manager) override {
return std::make_unique<Router::ScopedRoutesConfigProviderManager>(
factory_context.admin(), route_config_provider_manager);
}

Envoy::Config::ConfigProviderPtr createConfigProvider(
const envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
config,
Server::Configuration::ServerFactoryContext& factory_context, const std::string& stat_prefix,
Envoy::Config::ConfigProviderManager& scoped_routes_config_provider_manager) override {
return Router::ScopedRoutesConfigProviderUtil::create(
config, factory_context, factory_context.initManager(), stat_prefix,
scoped_routes_config_provider_manager);
}

// If enabled in the HttpConnectionManager config, returns a ConfigProvider for scoped routing
// configuration.
ScopeKeyBuilderPtr createScopeKeyBuilder(
const envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
config) override {
return Router::ScopedRoutesConfigProviderUtil::createScopeKeyBuilder(config);
}
};

} // namespace Router
} // namespace Envoy
1 change: 1 addition & 0 deletions source/exe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ envoy_cc_library(
# TODO(wbpcode) make this a proper extension
"//source/extensions/filters/http/match_delegate:config",
"//source/common/http:rds_lib",
"//source/common/router:scoped_rds_lib",
] + envoy_select_enable_http3(["//source/common/quic:server_codec_lib"]),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ envoy_cc_extension(
"//source/common/network:cidr_range_lib",
"//source/common/protobuf:utility_lib",
"//source/common/router:rds_lib",
"//source/common/router:scoped_rds_lib",
"//source/common/runtime:runtime_lib",
"//source/common/tracing:custom_tag_lib",
"//source/common/tracing:http_tracer_lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "source/common/protobuf/utility.h"
#include "source/common/quic/server_connection_factory.h"
#include "source/common/router/rds_impl.h"
#include "source/common/router/scoped_rds.h"
#include "source/common/runtime/runtime_impl.h"
#include "source/common/tracing/custom_tag_impl.h"
#include "source/common/tracing/tracer_config_impl.h"
Expand Down Expand Up @@ -211,6 +210,7 @@ createHeaderValidatorFactory([[maybe_unused]] const envoy::extensions::filters::
SINGLETON_MANAGER_REGISTRATION(date_provider);
SINGLETON_MANAGER_REGISTRATION(route_config_provider_manager);
SINGLETON_MANAGER_REGISTRATION(scoped_routes_config_provider_manager);
static const std::string srds_factory_name = "envoy.srds_factory.default";

Utility::Singletons Utility::createSingletons(Server::Configuration::FactoryContext& context) {
auto& server_context = context.serverFactoryContext();
Expand All @@ -227,15 +227,19 @@ Utility::Singletons Utility::createSingletons(Server::Configuration::FactoryCont
SINGLETON_MANAGER_REGISTERED_NAME(route_config_provider_manager), [&server_context] {
return std::make_shared<Router::RouteConfigProviderManagerImpl>(server_context.admin());
});

Router::ScopedRoutesConfigProviderManagerSharedPtr scoped_routes_config_provider_manager =
server_context.singletonManager().getTyped<Router::ScopedRoutesConfigProviderManager>(
std::shared_ptr<Envoy::Config::ConfigProviderManager> scoped_routes_config_provider_manager =
server_context.singletonManager().getTyped<Envoy::Config::ConfigProviderManager>(
SINGLETON_MANAGER_REGISTERED_NAME(scoped_routes_config_provider_manager),
[&server_context, route_config_provider_manager] {
return std::make_shared<Router::ScopedRoutesConfigProviderManager>(
server_context.admin(), *route_config_provider_manager);
[&server_context, route_config_provider_manager]()
-> std::shared_ptr<Envoy::Config::ConfigProviderManager> {
auto srds_factory =
Envoy::Config::Utility::getFactoryByName<Router::SrdsFactory>(srds_factory_name);
if (srds_factory) {
return srds_factory->createScopedRoutesConfigProviderManager(
server_context, *route_config_provider_manager);
}
return nullptr;
});

auto tracer_manager = Tracing::TracerManagerImpl::singleton(context);

std::shared_ptr<Http::DownstreamFilterConfigProviderManager> filter_config_provider_manager =
Expand All @@ -251,7 +255,7 @@ absl::StatusOr<std::shared_ptr<HttpConnectionManagerConfig>> Utility::createConf
proto_config,
Server::Configuration::FactoryContext& context, Http::DateProvider& date_provider,
Router::RouteConfigProviderManager& route_config_provider_manager,
Config::ConfigProviderManager& scoped_routes_config_provider_manager,
Config::ConfigProviderManager* scoped_routes_config_provider_manager,
Tracing::TracerManager& tracer_manager,
FilterConfigProviderManager& filter_config_provider_manager) {
absl::Status creation_status = absl::OkStatus();
Expand Down Expand Up @@ -281,7 +285,7 @@ HttpConnectionManagerFilterConfigFactory::createFilterFactoryFromProtoAndHopByHo
auto filter_config = THROW_OR_RETURN_VALUE(
Utility::createConfig(proto_config, context, *singletons.date_provider_,
*singletons.route_config_provider_manager_,
*singletons.scoped_routes_config_provider_manager_,
singletons.scoped_routes_config_provider_manager_.get(),
*singletons.tracer_manager_,
*singletons.filter_config_provider_manager_),
std::shared_ptr<HttpConnectionManagerConfig>);
Expand Down Expand Up @@ -337,7 +341,7 @@ HttpConnectionManagerConfig::HttpConnectionManagerConfig(
config,
Server::Configuration::FactoryContext& context, Http::DateProvider& date_provider,
Router::RouteConfigProviderManager& route_config_provider_manager,
Config::ConfigProviderManager& scoped_routes_config_provider_manager,
Config::ConfigProviderManager* scoped_routes_config_provider_manager,
Tracing::TracerManager& tracer_manager,
FilterConfigProviderManager& filter_config_provider_manager, absl::Status& creation_status)
: context_(context), stats_prefix_(fmt::format("http.{}.", config.stat_prefix())),
Expand Down Expand Up @@ -522,6 +526,8 @@ HttpConnectionManagerConfig::HttpConnectionManagerConfig(
early_header_mutation_extensions_.push_back(std::move(extension));
}

auto srds_factory =
Envoy::Config::Utility::getFactoryByName<Router::SrdsFactory>(srds_factory_name);
Comment on lines +529 to +530
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move to the kScopedRoutes switch case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind if I leave here? it's a pretty cheap function for the non-srds case and if you declare variables in a switch you need braces and it screws up coverage.

// If scoped RDS is enabled, avoid creating a route config provider. Route config providers
// will be managed by the scoped routing logic instead.
switch (config.route_specifier_case()) {
Expand All @@ -535,10 +541,13 @@ HttpConnectionManagerConfig::HttpConnectionManagerConfig(
break;
case envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager::
RouteSpecifierCase::kScopedRoutes:
scoped_routes_config_provider_ = Router::ScopedRoutesConfigProviderUtil::create(
config, context_.serverFactoryContext(), context_.initManager(), stats_prefix_,
scoped_routes_config_provider_manager_);
scope_key_builder_ = Router::ScopedRoutesConfigProviderUtil::createScopeKeyBuilder(config);
if (!srds_factory || !scoped_routes_config_provider_manager_) {
throwEnvoyExceptionOrPanic("SRDS configured but not compiled in");
}
scoped_routes_config_provider_ =
srds_factory->createConfigProvider(config, context_.serverFactoryContext(), stats_prefix_,
*scoped_routes_config_provider_manager_);
scope_key_builder_ = srds_factory->createScopeKeyBuilder(config);
break;
case envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager::
RouteSpecifierCase::ROUTE_SPECIFIER_NOT_SET:
Expand Down Expand Up @@ -838,7 +847,7 @@ HttpConnectionManagerFactory::createHttpConnectionManagerFactoryFromProto(
auto filter_config = THROW_OR_RETURN_VALUE(
Utility::createConfig(proto_config, context, *singletons.date_provider_,
*singletons.route_config_provider_manager_,
*singletons.scoped_routes_config_provider_manager_,
singletons.scoped_routes_config_provider_manager_.get(),
*singletons.tracer_manager_,
*singletons.filter_config_provider_manager_),
std::shared_ptr<HttpConnectionManagerConfig>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "source/common/local_reply/local_reply.h"
#include "source/common/network/cidr_range.h"
#include "source/common/router/rds_impl.h"
#include "source/common/router/scoped_rds.h"
#include "source/common/tracing/http_tracer_impl.h"
#include "source/extensions/filters/network/common/factory_base.h"
#include "source/extensions/filters/network/well_known_names.h"
Expand Down Expand Up @@ -135,7 +134,7 @@ class HttpConnectionManagerConfig : Logger::Loggable<Logger::Id::config>,
config,
Server::Configuration::FactoryContext& context, Http::DateProvider& date_provider,
Router::RouteConfigProviderManager& route_config_provider_manager,
Config::ConfigProviderManager& scoped_routes_config_provider_manager,
Config::ConfigProviderManager* scoped_routes_config_provider_manager,
Tracing::TracerManager& tracer_manager,
FilterConfigProviderManager& filter_config_provider_manager, absl::Status& creation_status);

Expand Down Expand Up @@ -307,7 +306,7 @@ class HttpConnectionManagerConfig : Logger::Loggable<Logger::Id::config>,
Http::ForwardClientCertType forward_client_cert_;
std::vector<Http::ClientCertDetailsType> set_current_client_cert_details_;
Router::RouteConfigProviderManager& route_config_provider_manager_;
Config::ConfigProviderManager& scoped_routes_config_provider_manager_;
Config::ConfigProviderManager* scoped_routes_config_provider_manager_;
FilterConfigProviderManager& filter_config_provider_manager_;
CodecType codec_type_;
envoy::config::core::v3::Http3ProtocolOptions http3_options_;
Expand Down Expand Up @@ -388,7 +387,7 @@ class Utility {
struct Singletons {
std::shared_ptr<Http::TlsCachingDateProviderImpl> date_provider_;
Router::RouteConfigProviderManagerSharedPtr route_config_provider_manager_;
Router::ScopedRoutesConfigProviderManagerSharedPtr scoped_routes_config_provider_manager_;
std::shared_ptr<Config::ConfigProviderManager> scoped_routes_config_provider_manager_;
Tracing::TracerManagerSharedPtr tracer_manager_;
std::shared_ptr<FilterConfigProviderManager> filter_config_provider_manager_;
};
Expand Down Expand Up @@ -416,7 +415,7 @@ class Utility {
proto_config,
Server::Configuration::FactoryContext& context, Http::DateProvider& date_provider,
Router::RouteConfigProviderManager& route_config_provider_manager,
Config::ConfigProviderManager& scoped_routes_config_provider_manager,
Config::ConfigProviderManager* scoped_routes_config_provider_manager,
Tracing::TracerManager& tracer_manager,
FilterConfigProviderManager& filter_config_provider_manager);
};
Expand Down
Loading