diff --git a/ci/build_setup.sh b/ci/build_setup.sh index abf67e3c02d7..35bac42d1c92 100755 --- a/ci/build_setup.sh +++ b/ci/build_setup.sh @@ -101,9 +101,8 @@ if [ "$1" != "-nofetch" ]; then fi # This is the hash on https://github.com/envoyproxy/envoy-filter-example.git we pin to. - (cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}" && git fetch origin && git checkout -f 03b45933284b332fd1df42cfb3270751fe543842) + (cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}" && git fetch origin && git checkout -f 5a05fb056a632a30b890ca85e69792558e90ffa9) sed -e "s|{ENVOY_SRCDIR}|${ENVOY_SRCDIR}|" "${ENVOY_SRCDIR}"/ci/WORKSPACE.filter.example > "${ENVOY_FILTER_EXAMPLE_SRCDIR}"/WORKSPACE - cp -f "${ENVOY_SRCDIR}"/.bazelversion "${ENVOY_FILTER_EXAMPLE_SRCDIR}"/.bazelversion fi # Also setup some space for building Envoy standalone. diff --git a/include/envoy/access_log/BUILD b/include/envoy/access_log/BUILD index 9dc6453cf8f6..991715a6a830 100644 --- a/include/envoy/access_log/BUILD +++ b/include/envoy/access_log/BUILD @@ -12,6 +12,7 @@ envoy_cc_library( name = "access_log_interface", hdrs = ["access_log.h"], deps = [ + "//include/envoy/config:typed_config_interface", "//include/envoy/http:header_map_interface", "//include/envoy/stream_info:stream_info_interface", "//source/common/protobuf", diff --git a/include/envoy/config/BUILD b/include/envoy/config/BUILD index 68bbc2d24579..22cd871981c3 100644 --- a/include/envoy/config/BUILD +++ b/include/envoy/config/BUILD @@ -58,10 +58,20 @@ envoy_cc_library( ], ) +envoy_cc_library( + name = "typed_config_interface", + hdrs = ["typed_config.h"], + deps = [ + "//source/common/common:assert_lib", + "//source/common/protobuf", + ], +) + envoy_cc_library( name = "typed_metadata_interface", hdrs = ["typed_metadata.h"], deps = [ + ":typed_config_interface", "//source/common/protobuf", ], ) diff --git a/include/envoy/config/typed_config.h b/include/envoy/config/typed_config.h new file mode 100644 index 000000000000..574562ff6bc0 --- /dev/null +++ b/include/envoy/config/typed_config.h @@ -0,0 +1,59 @@ +#pragma once + +#include "envoy/common/pure.h" + +#include "common/common/assert.h" +#include "common/protobuf/protobuf.h" + +namespace Envoy { +namespace Config { + +/** + * Base class for an extension factory. + */ +class UntypedFactory { +public: + virtual ~UntypedFactory() = default; + + /** + * Name of the factory, a reversed DNS name is encouraged to avoid cross-org conflict. + * It's used as key in the metadata map, as well as key in the factory registry. + */ + virtual std::string name() const PURE; + + /** + * @return std::string the identifying category name for objects + * created by this factory. Used for automatic registration with + * FactoryCategoryRegistry. + */ + virtual std::string category() const PURE; + + /** + * @return configuration proto full name, or empty for untyped factories. + */ + virtual std::string configType() { return ""; } +}; + +/** + * Base class for an extension factory configured by a typed proto message. + */ +class TypedFactory : public UntypedFactory { +public: + virtual ~TypedFactory() = default; + + /** + * @return ProtobufTypes::MessagePtr create empty config proto message for v2. The config, which + * arrives in an opaque google.protobuf.Struct message, will be converted to JSON and then parsed + * into this empty proto. + */ + virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; + + std::string configType() override { + auto ptr = createEmptyConfigProto(); + ASSERT(ptr != nullptr); + return ptr->GetDescriptor()->full_name(); + } +}; + +} // namespace Config +} // namespace Envoy diff --git a/include/envoy/config/typed_metadata.h b/include/envoy/config/typed_metadata.h index 369ec0927bd3..0604f09c7a8d 100644 --- a/include/envoy/config/typed_metadata.h +++ b/include/envoy/config/typed_metadata.h @@ -4,6 +4,7 @@ #include #include "envoy/common/pure.h" +#include "envoy/config/typed_config.h" #include "common/protobuf/protobuf.h" @@ -50,19 +51,10 @@ class TypedMetadata { * Typed metadata should implement this factory and register via Registry::registerFactory or the * convenience class RegisterFactory. */ -class TypedMetadataFactory { +class TypedMetadataFactory : public UntypedFactory { public: virtual ~TypedMetadataFactory() = default; - /** - * Name of the factory, a reversed DNS name is encouraged to avoid cross-org conflict. - * It's used as key in the metadata map, as well as key in the factory registry. - * When building a TypedMetadata from envoy::api::v2::core::Metadata, if the key is not found, the - * parse will not be called and the corresponding typedMetadata entry will be set to nullptr. - * @return the name of the factory. - */ - virtual const std::string name() const PURE; - /** * Convert the google.protobuf.Struct into an instance of TypedMetadata::Object. * It should throw an EnvoyException in case the conversion can't be completed. @@ -73,7 +65,7 @@ class TypedMetadataFactory { virtual std::unique_ptr parse(const ProtobufWkt::Struct& data) const PURE; - static std::string category() { return "typed_metadata"; } + std::string category() const override { return "typed_metadata"; } }; } // namespace Config diff --git a/include/envoy/grpc/BUILD b/include/envoy/grpc/BUILD index 41b93c7b7a81..d43a065cd8b7 100644 --- a/include/envoy/grpc/BUILD +++ b/include/envoy/grpc/BUILD @@ -50,6 +50,7 @@ envoy_cc_library( ], deps = [ "//include/envoy/api:api_interface", + "//include/envoy/config:typed_config_interface", "@envoy_api//envoy/config/core/v3alpha:pkg_cc_proto", ], ) diff --git a/include/envoy/grpc/google_grpc_creds.h b/include/envoy/grpc/google_grpc_creds.h index 00a20440bf91..e421bc5b4060 100644 --- a/include/envoy/grpc/google_grpc_creds.h +++ b/include/envoy/grpc/google_grpc_creds.h @@ -5,6 +5,7 @@ #include "envoy/api/api.h" #include "envoy/common/pure.h" #include "envoy/config/core/v3alpha/grpc_service.pb.h" +#include "envoy/config/typed_config.h" #include "grpcpp/grpcpp.h" @@ -14,7 +15,7 @@ namespace Grpc { /** * Interface for all Google gRPC credentials factories. */ -class GoogleGrpcCredentialsFactory { +class GoogleGrpcCredentialsFactory : public Config::UntypedFactory { public: virtual ~GoogleGrpcCredentialsFactory() = default; @@ -34,18 +35,7 @@ class GoogleGrpcCredentialsFactory { getChannelCredentials(const envoy::config::core::v3alpha::GrpcService& grpc_service_config, Api::Api& api) PURE; - /** - * @return std::string the identifying name for a particular implementation of - * a Google gRPC credentials factory. - */ - virtual std::string name() const PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "grpc_credentials"; } + std::string category() const override { return "grpc_credentials"; } }; } // namespace Grpc diff --git a/include/envoy/network/BUILD b/include/envoy/network/BUILD index 6fac77627a13..d4f710e5773f 100644 --- a/include/envoy/network/BUILD +++ b/include/envoy/network/BUILD @@ -127,6 +127,7 @@ envoy_cc_library( hdrs = ["resolver.h"], deps = [ ":address_interface", + "//include/envoy/config:typed_config_interface", "@envoy_api//envoy/config/core/v3alpha:pkg_cc_proto", ], ) diff --git a/include/envoy/network/resolver.h b/include/envoy/network/resolver.h index ac8f3943d3c7..5cd7eb55eb7d 100644 --- a/include/envoy/network/resolver.h +++ b/include/envoy/network/resolver.h @@ -7,6 +7,7 @@ #include "envoy/common/pure.h" #include "envoy/config/core/v3alpha/address.pb.h" +#include "envoy/config/typed_config.h" #include "envoy/network/address.h" namespace Envoy { @@ -16,7 +17,7 @@ namespace Address { /** * Interface for all network address resolvers. */ -class Resolver { +class Resolver : public Config::UntypedFactory { public: virtual ~Resolver() = default; @@ -28,18 +29,7 @@ class Resolver { virtual InstanceConstSharedPtr resolve(const envoy::config::core::v3alpha::SocketAddress& socket_address) PURE; - /** - * @return std::string the identifying name for a particular implementation of - * a resolver. - */ - virtual std::string name() const PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "resolvers"; } + std::string category() const override { return "resolvers"; } }; } // namespace Address diff --git a/include/envoy/registry/registry.h b/include/envoy/registry/registry.h index 713c97574598..7695f1994e62 100644 --- a/include/envoy/registry/registry.h +++ b/include/envoy/registry/registry.h @@ -167,6 +167,7 @@ template class FactoryRegistry : public Logger::Loggable class FactoryRegistry : public Logger::Loggable class RegisterFactory { // register its category here. This means that we have to ignore // multiple attempts to register the same category and can't detect // duplicate categories. - if (!FactoryCategoryRegistry::isRegistered(Base::category())) { - FactoryCategoryRegistry::registerCategory(Base::category(), + if (!FactoryCategoryRegistry::isRegistered(instance_.category())) { + FactoryCategoryRegistry::registerCategory(instance_.category(), new FactoryRegistryProxyImpl()); } } @@ -312,8 +314,8 @@ template class RegisterFactory { FactoryRegistry::registerFactory(instance_, deprecated_name, instance_.name()); } - if (!FactoryCategoryRegistry::isRegistered(Base::category())) { - FactoryCategoryRegistry::registerCategory(Base::category(), + if (!FactoryCategoryRegistry::isRegistered(instance_.category())) { + FactoryCategoryRegistry::registerCategory(instance_.category(), new FactoryRegistryProxyImpl()); } } diff --git a/include/envoy/server/BUILD b/include/envoy/server/BUILD index e476795442a1..9fa4099fe58a 100644 --- a/include/envoy/server/BUILD +++ b/include/envoy/server/BUILD @@ -73,6 +73,7 @@ envoy_cc_library( name = "health_checker_config_interface", hdrs = ["health_checker_config.h"], deps = [ + "//include/envoy/config:typed_config_interface", "//include/envoy/upstream:health_checker_interface", "@envoy_api//envoy/config/core/v3alpha:pkg_cc_proto", ], @@ -155,6 +156,7 @@ envoy_cc_library( ":process_context_interface", "//include/envoy/access_log:access_log_interface", "//include/envoy/api:api_interface", + "//include/envoy/config:typed_config_interface", "//include/envoy/grpc:context_interface", "//include/envoy/http:codes_interface", "//include/envoy/http:context_interface", @@ -209,6 +211,7 @@ envoy_cc_library( name = "transport_socket_config_interface", hdrs = ["transport_socket_config.h"], deps = [ + "//include/envoy/config:typed_config_interface", "//include/envoy/event:dispatcher_interface", "//include/envoy/init:manager_interface", "//include/envoy/local_info:local_info_interface", @@ -228,6 +231,7 @@ envoy_cc_library( name = "resource_monitor_interface", hdrs = ["resource_monitor.h"], deps = [ + "//include/envoy/config:typed_config_interface", "//source/common/protobuf", ], ) @@ -257,6 +261,7 @@ envoy_cc_library( hdrs = ["tracer_config.h"], deps = [ ":instance_interface", + "//include/envoy/config:typed_config_interface", "//source/common/protobuf", ], ) @@ -264,5 +269,8 @@ envoy_cc_library( envoy_cc_library( name = "active_udp_listener_config_interface", hdrs = ["active_udp_listener_config.h"], - deps = ["//include/envoy/network:connection_handler_interface"], + deps = [ + "//include/envoy/config:typed_config_interface", + "//include/envoy/network:connection_handler_interface", + ], ) diff --git a/include/envoy/server/access_log_config.h b/include/envoy/server/access_log_config.h index 5b289fabfece..596c63d41e8a 100644 --- a/include/envoy/server/access_log_config.h +++ b/include/envoy/server/access_log_config.h @@ -3,6 +3,7 @@ #include #include "envoy/access_log/access_log.h" +#include "envoy/config/typed_config.h" #include "envoy/server/filter_config.h" #include "common/protobuf/protobuf.h" @@ -15,7 +16,7 @@ namespace Configuration { * Implemented for each AccessLog::Instance and registered via Registry::registerFactory or the * convenience class RegisterFactory. */ -class AccessLogInstanceFactory { +class AccessLogInstanceFactory : public Config::TypedFactory { public: virtual ~AccessLogInstanceFactory() = default; @@ -32,25 +33,7 @@ class AccessLogInstanceFactory { AccessLog::FilterPtr&& filter, FactoryContext& context) PURE; - /** - * @return ProtobufTypes::MessagePtr create empty config proto message for v2. The config, which - * arrives in an opaque google.protobuf.Struct message, will be converted to JSON and then parsed - * into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * @return std::string the identifying name for a particular AccessLog::Instance implementation - * produced by the factory. - */ - virtual std::string name() const PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "access_loggers"; } + std::string category() const override { return "access_loggers"; } }; } // namespace Configuration diff --git a/include/envoy/server/active_udp_listener_config.h b/include/envoy/server/active_udp_listener_config.h index de2a41ce4194..56ea2f4f00b0 100644 --- a/include/envoy/server/active_udp_listener_config.h +++ b/include/envoy/server/active_udp_listener_config.h @@ -1,5 +1,6 @@ #pragma once +#include "envoy/config/typed_config.h" #include "envoy/network/connection_handler.h" #include "common/protobuf/protobuf.h" @@ -11,7 +12,7 @@ namespace Server { * Interface to create udp listener according to * envoy::api::v2::listener::UdpListenerConfig.udp_listener_name. */ -class ActiveUdpListenerConfigFactory { +class ActiveUdpListenerConfigFactory : public Config::UntypedFactory { public: virtual ~ActiveUdpListenerConfigFactory() = default; @@ -23,17 +24,7 @@ class ActiveUdpListenerConfigFactory { virtual Network::ActiveUdpListenerFactoryPtr createActiveUdpListenerFactory(const Protobuf::Message& message) PURE; - /** - * Used to identify which udp listener to create: quic or raw udp. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "udp_listeners"; } + std::string category() const override { return "udp_listeners"; } }; } // namespace Server diff --git a/include/envoy/server/filter_config.h b/include/envoy/server/filter_config.h index 8a1e49123e67..a0ff6cbca0a0 100644 --- a/include/envoy/server/filter_config.h +++ b/include/envoy/server/filter_config.h @@ -4,6 +4,7 @@ #include "envoy/access_log/access_log.h" #include "envoy/config/core/v3alpha/base.pb.h" +#include "envoy/config/typed_config.h" #include "envoy/grpc/context.h" #include "envoy/http/codes.h" #include "envoy/http/context.h" @@ -211,21 +212,9 @@ class ListenerFactoryContext : public virtual FactoryContext { /** * Common interface for listener filters and UDP listener filters */ -class ListenerFilterConfigFactoryBase { +class ListenerFilterConfigFactoryBase : public Config::TypedFactory { public: virtual ~ListenerFilterConfigFactoryBase() = default; - - /** - * @return ProtobufTypes::MessagePtr create empty config proto message. The filter - * config, which arrives in an opaque message, will be parsed into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * @return std::string the identifying name for a particular implementation of a listener filter - * produced by the factory. - */ - virtual std::string name() PURE; }; /** @@ -249,12 +238,7 @@ class NamedListenerFilterConfigFactory : public ListenerFilterConfigFactoryBase createFilterFactoryFromProto(const Protobuf::Message& config, ListenerFactoryContext& context) PURE; - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "filters.listener"; } + std::string category() const override { return "filters.listener"; } }; /** @@ -277,19 +261,14 @@ class NamedUdpListenerFilterConfigFactory : public ListenerFilterConfigFactoryBa createFilterFactoryFromProto(const Protobuf::Message& config, ListenerFactoryContext& context) PURE; - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "filters.udp_listener"; } + std::string category() const override { return "filters.udp_listener"; } }; /** * Implemented by filter factories that require more options to process the protocol used by the * upstream cluster. */ -class ProtocolOptionsFactory { +class ProtocolOptionsFactory : public Config::TypedFactory { public: virtual ~ProtocolOptionsFactory() = default; @@ -335,25 +314,7 @@ class NamedNetworkFilterConfigFactory : public ProtocolOptionsFactory { virtual Network::FilterFactoryCb createFilterFactoryFromProto(const Protobuf::Message& config, FactoryContext& context) PURE; - /** - * @return ProtobufTypes::MessagePtr create empty config proto message for v2. The filter - * config, which arrives in an opaque google.protobuf.Struct message, will be converted to - * JSON and then parsed into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * @return std::string the identifying name for a particular implementation of a network filter - * produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "filters.network"; } + std::string category() const override { return "filters.network"; } /** * @return bool true if this filter must be the last filter in a filter chain, false otherwise. @@ -377,23 +338,7 @@ class NamedUpstreamNetworkFilterConfigFactory : public ProtocolOptionsFactory { virtual Network::FilterFactoryCb createFilterFactoryFromProto(const Protobuf::Message& config, CommonFactoryContext& context) PURE; - /** - * @return ProtobufTypes::MessagePtr create empty config proto message for v2. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * @return std::string the identifying name for a particular implementation of a network filter - * produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "filters.upstream_network"; } + std::string category() const override { return "filters.upstream_network"; } }; /** @@ -418,13 +363,6 @@ class NamedHttpFilterConfigFactory : public ProtocolOptionsFactory { const std::string& stat_prefix, FactoryContext& context) PURE; - /** - * @return ProtobufTypes::MessagePtr create empty config proto message for v2. The filter - * config, which arrives in an opaque google.protobuf.Struct message, will be converted to - * JSON and then parsed into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - /** * @return ProtobufTypes::MessagePtr create an empty virtual host, route, or weighted * cluster-local config proto message for v2. The filter config, which arrives in an @@ -446,18 +384,7 @@ class NamedHttpFilterConfigFactory : public ProtocolOptionsFactory { return nullptr; } - /** - * @return std::string the identifying name for a particular implementation of an http filter - * produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "filters.http"; } + std::string category() const override { return "filters.http"; } /** * @return bool true if this filter must be the last filter in a filter chain, false otherwise. diff --git a/include/envoy/server/health_checker_config.h b/include/envoy/server/health_checker_config.h index 0d3e54481ae8..3c457fe410bb 100644 --- a/include/envoy/server/health_checker_config.h +++ b/include/envoy/server/health_checker_config.h @@ -1,6 +1,7 @@ #pragma once #include "envoy/config/core/v3alpha/health_check.pb.h" +#include "envoy/config/typed_config.h" #include "envoy/runtime/runtime.h" #include "envoy/upstream/health_checker.h" @@ -55,7 +56,7 @@ class HealthCheckerFactoryContext { * Implemented by each custom health checker and registered via Registry::registerFactory() * or the convenience class RegisterFactory. */ -class CustomHealthCheckerFactory { +class CustomHealthCheckerFactory : public Config::UntypedFactory { public: virtual ~CustomHealthCheckerFactory() = default; @@ -72,18 +73,7 @@ class CustomHealthCheckerFactory { createCustomHealthChecker(const envoy::config::core::v3alpha::HealthCheck& config, HealthCheckerFactoryContext& context) PURE; - /** - * @return std::string the identifying name for a particular implementation of a custom health - * checker produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "health_checkers"; } + std::string category() const override { return "health_checkers"; } }; } // namespace Configuration diff --git a/include/envoy/server/resource_monitor_config.h b/include/envoy/server/resource_monitor_config.h index 53edcb2f854a..cc439602016e 100644 --- a/include/envoy/server/resource_monitor_config.h +++ b/include/envoy/server/resource_monitor_config.h @@ -2,6 +2,7 @@ #include "envoy/api/api.h" #include "envoy/common/pure.h" +#include "envoy/config/typed_config.h" #include "envoy/event/dispatcher.h" #include "envoy/protobuf/message_validator.h" #include "envoy/server/resource_monitor.h" @@ -38,7 +39,7 @@ class ResourceMonitorFactoryContext { * Implemented by each resource monitor and registered via Registry::registerFactory() * or the convenience class RegistryFactory. */ -class ResourceMonitorFactory { +class ResourceMonitorFactory : public Config::TypedFactory { public: virtual ~ResourceMonitorFactory() = default; @@ -54,25 +55,7 @@ class ResourceMonitorFactory { virtual ResourceMonitorPtr createResourceMonitor(const Protobuf::Message& config, ResourceMonitorFactoryContext& context) PURE; - /** - * @return ProtobufTypes::MessagePtr create empty config proto message. The resource monitor - * config, which arrives in an opaque google.protobuf.Struct message, will be converted - * to JSON and then parsed into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * @return std::string the identifying name for a particular implementation of a resource - * monitor produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "resource_monitors"; } + std::string category() const override { return "resource_monitors"; } }; } // namespace Configuration diff --git a/include/envoy/server/tracer_config.h b/include/envoy/server/tracer_config.h index 7da24de47900..590f0475a13a 100644 --- a/include/envoy/server/tracer_config.h +++ b/include/envoy/server/tracer_config.h @@ -1,6 +1,7 @@ #pragma once #include "envoy/common/pure.h" +#include "envoy/config/typed_config.h" #include "envoy/server/instance.h" #include "envoy/tracing/http_tracer.h" @@ -14,7 +15,7 @@ namespace Configuration { * Implemented by each Tracer and registered via Registry::registerFactory() or the convenience * class RegisterFactory. */ -class TracerFactory { +class TracerFactory : public Config::TypedFactory { public: virtual ~TracerFactory() = default; @@ -29,24 +30,7 @@ class TracerFactory { virtual Tracing::HttpTracerPtr createHttpTracer(const Protobuf::Message& config, Instance& server) PURE; - /** - * @return ProtobufTypes::MessagePtr create empty config proto message for v2. The tracing - * config, which arrives in an opaque message, will be parsed into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * Returns the identifying name for a particular implementation of tracer produced by the - * factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "tracers"; } + std::string category() const override { return "tracers"; } }; } // namespace Configuration diff --git a/include/envoy/server/transport_socket_config.h b/include/envoy/server/transport_socket_config.h index b0c22e786314..e0436eafd638 100644 --- a/include/envoy/server/transport_socket_config.h +++ b/include/envoy/server/transport_socket_config.h @@ -2,6 +2,7 @@ #include +#include "envoy/config/typed_config.h" #include "envoy/event/dispatcher.h" #include "envoy/init/manager.h" #include "envoy/local_info/local_info.h" @@ -106,22 +107,9 @@ class TransportSocketFactoryContext { virtual Api::Api& api() PURE; }; -class TransportSocketConfigFactory { +class TransportSocketConfigFactory : public Config::TypedFactory { public: virtual ~TransportSocketConfigFactory() = default; - - /** - * @return ProtobufTypes::MessagePtr create empty config proto message. The transport socket - * config, which arrives in an opaque google.protobuf.Struct message, will be converted - * to JSON and then parsed into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * @return std::string the identifying name for a particular TransportSocketFactoryPtr - * implementation produced by the factory. - */ - virtual std::string name() const PURE; }; /** @@ -145,12 +133,7 @@ class UpstreamTransportSocketConfigFactory : public virtual TransportSocketConfi createTransportSocketFactory(const Protobuf::Message& config, TransportSocketFactoryContext& context) PURE; - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "transport_sockets.upstream"; } + std::string category() const override { return "transport_sockets.upstream"; } }; /** @@ -177,12 +160,7 @@ class DownstreamTransportSocketConfigFactory : public virtual TransportSocketCon TransportSocketFactoryContext& context, const std::vector& server_names) PURE; - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "transport_sockets.downstream"; } + std::string category() const override { return "transport_sockets.downstream"; } }; } // namespace Configuration diff --git a/include/envoy/singleton/BUILD b/include/envoy/singleton/BUILD index 23fd60851570..f47887a06244 100644 --- a/include/envoy/singleton/BUILD +++ b/include/envoy/singleton/BUILD @@ -18,6 +18,7 @@ envoy_cc_library( hdrs = ["manager.h"], deps = [ ":instance_interface", + "//include/envoy/config:typed_config_interface", "//include/envoy/registry", ], ) diff --git a/include/envoy/singleton/manager.h b/include/envoy/singleton/manager.h index 2278ef8942d7..9363363e8c42 100644 --- a/include/envoy/singleton/manager.h +++ b/include/envoy/singleton/manager.h @@ -5,6 +5,7 @@ #include #include "envoy/common/pure.h" +#include "envoy/config/typed_config.h" #include "envoy/registry/registry.h" #include "envoy/singleton/instance.h" @@ -14,10 +15,10 @@ namespace Singleton { /** * An abstract registration for a singleton entry. */ -class Registration { +class Registration : public Config::UntypedFactory { public: virtual ~Registration() = default; - virtual std::string name() PURE; + std::string category() const override { return "singleton"; } }; /** @@ -34,7 +35,7 @@ class Registration { */ template class RegistrationImpl : public Registration { public: - std::string name() override { return name_param; } + std::string name() const override { return name_param; } }; /** diff --git a/include/envoy/ssl/BUILD b/include/envoy/ssl/BUILD index 301b11616b64..77cfadef0785 100644 --- a/include/envoy/ssl/BUILD +++ b/include/envoy/ssl/BUILD @@ -39,6 +39,7 @@ envoy_cc_library( ":context_config_interface", ":context_interface", "//include/envoy/common:time_interface", + "//include/envoy/config:typed_config_interface", "//include/envoy/stats:stats_interface", ], ) diff --git a/include/envoy/ssl/context_manager.h b/include/envoy/ssl/context_manager.h index bb0c104e5202..dcc49f7e314a 100644 --- a/include/envoy/ssl/context_manager.h +++ b/include/envoy/ssl/context_manager.h @@ -3,6 +3,7 @@ #include #include "envoy/common/time.h" +#include "envoy/config/typed_config.h" #include "envoy/ssl/context.h" #include "envoy/ssl/context_config.h" #include "envoy/ssl/private_key/private_key.h" @@ -50,13 +51,14 @@ class ContextManager { using ContextManagerPtr = std::unique_ptr; -class ContextManagerFactory { +class ContextManagerFactory : public Config::UntypedFactory { public: virtual ~ContextManagerFactory() = default; virtual ContextManagerPtr createContextManager(TimeSource& time_source) PURE; // There could be only one factory thus the name is static. - static std::string name() { return "ssl_context_manager"; } + std::string name() const override { return "ssl_context_manager"; } + std::string category() const override { return "ssl_context_manager"; } }; } // namespace Ssl diff --git a/include/envoy/ssl/private_key/BUILD b/include/envoy/ssl/private_key/BUILD index a4fc20eb3940..9e57f1095ba0 100644 --- a/include/envoy/ssl/private_key/BUILD +++ b/include/envoy/ssl/private_key/BUILD @@ -24,6 +24,7 @@ envoy_cc_library( hdrs = ["private_key_config.h"], deps = [ ":private_key_interface", + "//include/envoy/config:typed_config_interface", "//include/envoy/registry", "@envoy_api//envoy/extensions/transport_sockets/tls/v3alpha:pkg_cc_proto", ], diff --git a/include/envoy/ssl/private_key/private_key_config.h b/include/envoy/ssl/private_key/private_key_config.h index b7bf1a038bee..0024ecd81d72 100644 --- a/include/envoy/ssl/private_key/private_key_config.h +++ b/include/envoy/ssl/private_key/private_key_config.h @@ -1,5 +1,6 @@ #pragma once +#include "envoy/config/typed_config.h" #include "envoy/extensions/transport_sockets/tls/v3alpha/cert.pb.h" #include "envoy/registry/registry.h" #include "envoy/ssl/private_key/private_key.h" @@ -9,7 +10,7 @@ namespace Ssl { // Base class which the private key operation provider implementations can register. -class PrivateKeyMethodProviderInstanceFactory { +class PrivateKeyMethodProviderInstanceFactory : public Config::UntypedFactory { public: virtual ~PrivateKeyMethodProviderInstanceFactory() = default; @@ -24,17 +25,7 @@ class PrivateKeyMethodProviderInstanceFactory { const envoy::extensions::transport_sockets::tls::v3alpha::PrivateKeyProvider& config, Server::Configuration::TransportSocketFactoryContext& factory_context) PURE; - /** - * @return std::string the identifying name for a particular implementation of - * PrivateKeyMethodProvider produced by the factory. - */ - virtual std::string name() const PURE; - - /** - * @return std::string the identifying category name for objects created by this factory. - * Used for automatic registration with FactoryCategoryRegistry. - */ - static std::string category() { return "tls.key_providers"; }; + std::string category() const override { return "tls.key_providers"; }; }; } // namespace Ssl diff --git a/include/envoy/upstream/BUILD b/include/envoy/upstream/BUILD index 806d785f55e3..b20a207141de 100644 --- a/include/envoy/upstream/BUILD +++ b/include/envoy/upstream/BUILD @@ -105,6 +105,7 @@ envoy_cc_library( name = "retry_interface", hdrs = ["retry.h"], deps = [ + "//include/envoy/config:typed_config_interface", "//include/envoy/upstream:types_interface", "//include/envoy/upstream:upstream_interface", ], @@ -166,6 +167,7 @@ envoy_cc_library( ":resource_manager_interface", ":upstream_interface", "//include/envoy/common:callback", + "//include/envoy/config:typed_config_interface", "//include/envoy/config:typed_metadata_interface", "//include/envoy/http:codec_interface", "//include/envoy/network:connection_interface", diff --git a/include/envoy/upstream/cluster_factory.h b/include/envoy/upstream/cluster_factory.h index 45773a759fcd..eb9ddb81d44b 100644 --- a/include/envoy/upstream/cluster_factory.h +++ b/include/envoy/upstream/cluster_factory.h @@ -11,6 +11,7 @@ #include "envoy/access_log/access_log.h" #include "envoy/api/api.h" #include "envoy/config/cluster/v3alpha/cluster.pb.h" +#include "envoy/config/typed_config.h" #include "envoy/event/dispatcher.h" #include "envoy/local_info/local_info.h" #include "envoy/network/dns.h" @@ -123,7 +124,7 @@ class ClusterFactoryContext { * Implemented by cluster and registered via Registry::registerFactory() or the convenience class * RegisterFactory. */ -class ClusterFactory { +class ClusterFactory : public Config::UntypedFactory { public: virtual ~ClusterFactory() = default; @@ -139,17 +140,7 @@ class ClusterFactory { create(const envoy::config::cluster::v3alpha::Cluster& cluster, ClusterFactoryContext& context) PURE; - /** - * @return std::string the identifying name for a particular implementation of a cluster factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "clusters"; } + std::string category() const override { return "clusters"; } }; } // namespace Upstream diff --git a/include/envoy/upstream/retry.h b/include/envoy/upstream/retry.h index f83983133562..590354ee2f6b 100644 --- a/include/envoy/upstream/retry.h +++ b/include/envoy/upstream/retry.h @@ -1,5 +1,6 @@ #pragma once +#include "envoy/config/typed_config.h" #include "envoy/upstream/types.h" #include "envoy/upstream/upstream.h" @@ -75,7 +76,7 @@ using RetryHostPredicateSharedPtr = std::shared_ptr; /** * Factory for RetryPriority. */ -class RetryPriorityFactory { +class RetryPriorityFactory : public Config::TypedFactory { public: virtual ~RetryPriorityFactory() = default; @@ -84,36 +85,20 @@ class RetryPriorityFactory { ProtobufMessage::ValidationVisitor& validation_visitor, uint32_t retry_count) PURE; - virtual std::string name() const PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "retry_priorities"; } - - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; + std::string category() const override { return "retry_priorities"; } }; /** * Factory for RetryHostPredicate. */ -class RetryHostPredicateFactory { +class RetryHostPredicateFactory : public Config::TypedFactory { public: virtual ~RetryHostPredicateFactory() = default; virtual RetryHostPredicateSharedPtr createHostPredicate(const Protobuf::Message& config, uint32_t retry_count) PURE; - /** - * @return name name of this factory. - */ - virtual std::string name() PURE; - - static std::string category() { return "retry_host_predicates"; } - - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; + std::string category() const override { return "retry_host_predicates"; } }; } // namespace Upstream diff --git a/source/common/access_log/BUILD b/source/common/access_log/BUILD index 2202f5b42623..70b32fc536de 100644 --- a/source/common/access_log/BUILD +++ b/source/common/access_log/BUILD @@ -15,6 +15,7 @@ envoy_cc_library( external_deps = ["abseil_hash"], deps = [ "//include/envoy/access_log:access_log_interface", + "//include/envoy/config:typed_config_interface", "//include/envoy/filesystem:filesystem_interface", "//include/envoy/http:header_map_interface", "//include/envoy/runtime:runtime_interface", diff --git a/source/common/access_log/access_log_impl.cc b/source/common/access_log/access_log_impl.cc index d2960279a376..febafbcb63c5 100644 --- a/source/common/access_log/access_log_impl.cc +++ b/source/common/access_log/access_log_impl.cc @@ -92,8 +92,8 @@ FilterFactory::fromProto(const envoy::config::filter::accesslog::v3alpha::Access kExtensionFilter: MessageUtil::validate(config, validation_visitor); { - auto& factory = Config::Utility::getAndCheckFactory( - config.extension_filter().name()); + auto& factory = + Config::Utility::getAndCheckFactory(config.extension_filter()); return factory.createFilter(config.extension_filter(), runtime, random); } default: @@ -288,8 +288,7 @@ AccessLogFactory::fromProto(const envoy::config::filter::accesslog::v3alpha::Acc } auto& factory = - Config::Utility::getAndCheckFactory( - config.name()); + Config::Utility::getAndCheckFactory(config); ProtobufTypes::MessagePtr message = Config::Utility::translateToFactoryConfig( config, context.messageValidationVisitor(), factory); diff --git a/source/common/access_log/access_log_impl.h b/source/common/access_log/access_log_impl.h index a0be72506fe2..9c44dfe7c818 100644 --- a/source/common/access_log/access_log_impl.h +++ b/source/common/access_log/access_log_impl.h @@ -7,6 +7,7 @@ #include "envoy/access_log/access_log.h" #include "envoy/config/filter/accesslog/v3alpha/accesslog.pb.h" +#include "envoy/config/typed_config.h" #include "envoy/runtime/runtime.h" #include "envoy/server/access_log_config.h" #include "envoy/type/v3alpha/percent.pb.h" @@ -231,7 +232,7 @@ class GrpcStatusFilter : public Filter { /** * Extension filter factory that reads from ExtensionFilter proto. */ -class ExtensionFilterFactory { +class ExtensionFilterFactory : public Config::TypedFactory { public: virtual ~ExtensionFilterFactory() = default; @@ -248,25 +249,7 @@ class ExtensionFilterFactory { createFilter(const envoy::config::filter::accesslog::v3alpha::ExtensionFilter& config, Runtime::Loader& runtime, Runtime::RandomGenerator& random) PURE; - /** - * @return ProtobufTypes::MessagePtr create empty config proto message for v2. The config, which - * arrives in an opaque google.protobuf.Struct message, will be converted to JSON and then parsed - * into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * @return std::string the identifying name for a particular Filter implementation - * produced by the factory. - */ - virtual std::string name() const PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "access_logger.extension_filters"; } + std::string category() const override { return "access_logger.extension_filters"; } }; /** diff --git a/source/common/config/utility.h b/source/common/config/utility.h index 016e94e88e16..d47e1a35ce4c 100644 --- a/source/common/config/utility.h +++ b/source/common/config/utility.h @@ -194,7 +194,7 @@ class Utility { * @param name string identifier for the particular implementation. Note: this is a proto string * because it is assumed that this value will be pulled directly from the configuration proto. */ - template static Factory& getAndCheckFactory(const std::string& name) { + template static Factory& getAndCheckFactoryByName(const std::string& name) { if (name.empty()) { throw EnvoyException("Provided name for static registration lookup was empty."); } @@ -209,6 +209,16 @@ class Utility { return *factory; } + /** + * Get a Factory from the registry with error checking to ensure the name and the factory are + * valid. + * @param message proto that contains fields 'name' and 'typed_config'. + */ + template + static Factory& getAndCheckFactory(const ProtoMessage& message) { + return Utility::getAndCheckFactoryByName(message.name()); + } + /** * Translate a nested config into a proto message provided by the implementation factory. * @param extension_name name of extension corresponding to config. diff --git a/source/common/http/codec_client.cc b/source/common/http/codec_client.cc index 673212d3e69b..04a2ca0d7b04 100644 --- a/source/common/http/codec_client.cc +++ b/source/common/http/codec_client.cc @@ -162,7 +162,7 @@ CodecClientProd::CodecClientProd(Type type, Network::ClientConnectionPtr&& conne } case Type::HTTP3: { codec_ = std::unique_ptr( - Config::Utility::getAndCheckFactory( + Config::Utility::getAndCheckFactoryByName( Http::QuicCodecNames::get().Quiche) .createQuicClientConnection(*connection_, *this)); } diff --git a/source/common/http/http3/BUILD b/source/common/http/http3/BUILD index 67a18855fe7f..cadca40d0d25 100644 --- a/source/common/http/http3/BUILD +++ b/source/common/http/http3/BUILD @@ -12,6 +12,7 @@ envoy_cc_library( name = "quic_codec_factory_lib", hdrs = ["quic_codec_factory.h"], deps = [ + "//include/envoy/config:typed_config_interface", "//include/envoy/http:codec_interface", "//include/envoy/network:connection_interface", ], diff --git a/source/common/http/http3/quic_codec_factory.h b/source/common/http/http3/quic_codec_factory.h index 21ca7cab8704..64d732814f9c 100644 --- a/source/common/http/http3/quic_codec_factory.h +++ b/source/common/http/http3/quic_codec_factory.h @@ -2,6 +2,7 @@ #include +#include "envoy/config/typed_config.h" #include "envoy/http/codec.h" #include "envoy/network/connection.h" @@ -9,29 +10,25 @@ namespace Envoy { namespace Http { // A factory to create Http::ServerConnection instance for QUIC. -class QuicHttpServerConnectionFactory { +class QuicHttpServerConnectionFactory : public Config::UntypedFactory { public: virtual ~QuicHttpServerConnectionFactory() {} - virtual std::string name() const PURE; - virtual std::unique_ptr createQuicServerConnection(Network::Connection& connection, ConnectionCallbacks& callbacks) PURE; - static std::string category() { return "quic_client_codec"; } + std::string category() const override { return "quic_client_codec"; } }; // A factory to create Http::ClientConnection instance for QUIC. -class QuicHttpClientConnectionFactory { +class QuicHttpClientConnectionFactory : public Config::UntypedFactory { public: virtual ~QuicHttpClientConnectionFactory() {} - virtual std::string name() const PURE; - virtual std::unique_ptr createQuicClientConnection(Network::Connection& connection, ConnectionCallbacks& callbacks) PURE; - static std::string category() { return "quic_server_codec"; } + std::string category() const override { return "quic_server_codec"; } }; } // namespace Http diff --git a/source/common/router/config_impl.cc b/source/common/router/config_impl.cc index 6088635795c9..149213d30a3b 100644 --- a/source/common/router/config_impl.cc +++ b/source/common/router/config_impl.cc @@ -83,19 +83,19 @@ RetryPolicyImpl::RetryPolicyImpl(const envoy::config::route::v3alpha::RetryPolic for (const auto& host_predicate : retry_policy.retry_host_predicate()) { auto& factory = Envoy::Config::Utility::getAndCheckFactory( - host_predicate.name()); + host_predicate); auto config = Envoy::Config::Utility::translateToFactoryConfig(host_predicate, validation_visitor, factory); - retry_host_predicate_configs_.emplace_back(host_predicate.name(), std::move(config)); + retry_host_predicate_configs_.emplace_back(factory, std::move(config)); } const auto& retry_priority = retry_policy.retry_priority(); if (!retry_priority.name().empty()) { - auto& factory = Envoy::Config::Utility::getAndCheckFactory( - retry_priority.name()); + auto& factory = + Envoy::Config::Utility::getAndCheckFactory(retry_priority); retry_priority_config_ = - std::make_pair(retry_priority.name(), Envoy::Config::Utility::translateToFactoryConfig( - retry_priority, validation_visitor, factory)); + std::make_pair(&factory, Envoy::Config::Utility::translateToFactoryConfig( + retry_priority, validation_visitor, factory)); } auto host_selection_attempts = retry_policy.host_selection_retry_max_attempts(); @@ -133,24 +133,19 @@ std::vector RetryPolicyImpl::retryHostPre std::vector predicates; for (const auto& config : retry_host_predicate_configs_) { - auto& factory = Envoy::Config::Utility::getAndCheckFactory( - config.first); - predicates.emplace_back(factory.createHostPredicate(*config.second, num_retries_)); + predicates.emplace_back(config.first.createHostPredicate(*config.second, num_retries_)); } return predicates; } Upstream::RetryPrioritySharedPtr RetryPolicyImpl::retryPriority() const { - if (retry_priority_config_.first.empty()) { + if (retry_priority_config_.first == nullptr) { return nullptr; } - auto& factory = Envoy::Config::Utility::getAndCheckFactory( - retry_priority_config_.first); - - return factory.createRetryPriority(*retry_priority_config_.second, *validation_visitor_, - num_retries_); + return retry_priority_config_.first->createRetryPriority(*retry_priority_config_.second, + *validation_visitor_, num_retries_); } CorsPolicyImpl::CorsPolicyImpl(const envoy::config::route::v3alpha::CorsPolicy& config, @@ -1198,7 +1193,7 @@ createRouteSpecificFilterConfig(const std::string& name, const ProtobufWkt::Any& const ProtobufWkt::Struct& config, Server::Configuration::ServerFactoryContext& factory_context, ProtobufMessage::ValidationVisitor& validator) { - auto& factory = Envoy::Config::Utility::getAndCheckFactory< + auto& factory = Envoy::Config::Utility::getAndCheckFactoryByName< Server::Configuration::NamedHttpFilterConfigFactory>(name); ProtobufTypes::MessagePtr proto_config = factory.createEmptyRouteConfigProto(); Envoy::Config::Utility::translateOpaqueConfig(typed_config, config, validator, *proto_config); diff --git a/source/common/router/config_impl.h b/source/common/router/config_impl.h index 94bba3715fb4..fab8f504106e 100644 --- a/source/common/router/config_impl.h +++ b/source/common/router/config_impl.h @@ -264,11 +264,12 @@ class RetryPolicyImpl : public RetryPolicy { uint32_t retry_on_{}; // Each pair contains the name and config proto to be used to create the RetryHostPredicates // that should be used when with this policy. - std::vector> retry_host_predicate_configs_; + std::vector> + retry_host_predicate_configs_; Upstream::RetryPrioritySharedPtr retry_priority_; // Name and config proto to use to create the RetryPriority to use with this policy. Default // initialized when no RetryPriority should be used. - std::pair retry_priority_config_; + std::pair retry_priority_config_; uint32_t host_selection_attempts_{1}; std::vector retriable_status_codes_; std::vector retriable_headers_; diff --git a/source/common/upstream/cluster_factory_impl.h b/source/common/upstream/cluster_factory_impl.h index 1682503f26a0..a8ec04f1efb1 100644 --- a/source/common/upstream/cluster_factory_impl.h +++ b/source/common/upstream/cluster_factory_impl.h @@ -137,7 +137,7 @@ class ClusterFactoryImplBase : public ClusterFactory { std::pair create(const envoy::config::cluster::v3alpha::Cluster& cluster, ClusterFactoryContext& context) override; - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: ClusterFactoryImplBase(const std::string& name) : name_(name) {} diff --git a/source/common/upstream/health_checker_impl.cc b/source/common/upstream/health_checker_impl.cc index 2d4d94def6d1..8780d9fef3d4 100644 --- a/source/common/upstream/health_checker_impl.cc +++ b/source/common/upstream/health_checker_impl.cc @@ -85,7 +85,7 @@ HealthCheckerSharedPtr HealthCheckerFactory::create( case envoy::config::core::v3alpha::HealthCheck::HealthCheckerCase::kCustomHealthCheck: { auto& factory = Config::Utility::getAndCheckFactory( - health_check_config.custom_health_check().name()); + health_check_config.custom_health_check()); std::unique_ptr context( new HealthCheckerFactoryContextImpl(cluster, runtime, random, dispatcher, std::move(event_logger), validation_visitor, api)); diff --git a/source/common/upstream/transport_socket_match_impl.cc b/source/common/upstream/transport_socket_match_impl.cc index 99aaf2936538..5f91d4dc094b 100644 --- a/source/common/upstream/transport_socket_match_impl.cc +++ b/source/common/upstream/transport_socket_match_impl.cc @@ -19,7 +19,7 @@ TransportSocketMatcherImpl::TransportSocketMatcherImpl( for (const auto& socket_match : socket_matches) { const auto& socket_config = socket_match.transport_socket(); auto& config_factory = Config::Utility::getAndCheckFactory< - Server::Configuration::UpstreamTransportSocketConfigFactory>(socket_config.name()); + Server::Configuration::UpstreamTransportSocketConfigFactory>(socket_config); ProtobufTypes::MessagePtr message = Config::Utility::translateToFactoryConfig( socket_config, factory_context.messageValidationVisitor(), config_factory); FactoryMatch factory_match( diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index 9329debce38b..51f2008121c9 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -758,11 +758,10 @@ ClusterInfoImpl::ClusterInfoImpl( auto filters = config.filters(); for (ssize_t i = 0; i < filters.size(); i++) { const auto& proto_config = filters[i]; - const std::string& string_name = proto_config.name(); ENVOY_LOG(debug, " upstream filter #{}:", i); - ENVOY_LOG(debug, " name: {}", string_name); + ENVOY_LOG(debug, " name: {}", proto_config.name()); auto& factory = Config::Utility::getAndCheckFactory< - Server::Configuration::NamedUpstreamNetworkFilterConfigFactory>(string_name); + Server::Configuration::NamedUpstreamNetworkFilterConfigFactory>(proto_config); auto message = factory.createEmptyConfigProto(); if (!proto_config.typed_config().value().empty()) { MessageUtil::unpackTo(proto_config.typed_config(), *message); @@ -802,7 +801,7 @@ Network::TransportSocketFactoryPtr createTransportSocketFactory( } auto& config_factory = Config::Utility::getAndCheckFactory< - Server::Configuration::UpstreamTransportSocketConfigFactory>(transport_socket.name()); + Server::Configuration::UpstreamTransportSocketConfigFactory>(transport_socket); ProtobufTypes::MessagePtr message = Config::Utility::translateToFactoryConfig( transport_socket, factory_context.messageValidationVisitor(), config_factory); return config_factory.createTransportSocketFactory(*message, factory_context); diff --git a/source/extensions/common/wasm/null/BUILD b/source/extensions/common/wasm/null/BUILD index eed8e62d2e49..6dbc6e8d65a2 100644 --- a/source/extensions/common/wasm/null/BUILD +++ b/source/extensions/common/wasm/null/BUILD @@ -12,6 +12,7 @@ envoy_cc_library( name = "null_vm_plugin_interface", hdrs = ["null_vm_plugin.h"], deps = [ + "//include/envoy/config:typed_config_interface", "//source/extensions/common/wasm:wasm_vm_interface", "//source/extensions/common/wasm:well_known_names", ], diff --git a/source/extensions/common/wasm/null/null_vm_plugin.h b/source/extensions/common/wasm/null/null_vm_plugin.h index 231651eeafad..5f6a62ead9ec 100644 --- a/source/extensions/common/wasm/null/null_vm_plugin.h +++ b/source/extensions/common/wasm/null/null_vm_plugin.h @@ -1,5 +1,7 @@ #pragma once +#include "envoy/config/typed_config.h" + #include "extensions/common/wasm/wasm_vm.h" namespace Envoy { @@ -26,21 +28,11 @@ class NullVmPlugin { * Pseudo-WASM plugins using the NullVM should implement this factory and register via * Registry::registerFactory or the convenience class RegisterFactory. */ -class NullVmPluginFactory { +class NullVmPluginFactory : public Config::UntypedFactory { public: virtual ~NullVmPluginFactory() = default; - /** - * Name of the plugin. - */ - virtual const std::string name() const PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "wasm.null_vms"; } + std::string category() const override { return "wasm.null_vms"; } /** * Create an instance of the plugin. diff --git a/source/extensions/filters/http/common/empty_http_filter_config.h b/source/extensions/filters/http/common/empty_http_filter_config.h index c204aa7a21ac..7e5fd3522985 100644 --- a/source/extensions/filters/http/common/empty_http_filter_config.h +++ b/source/extensions/filters/http/common/empty_http_filter_config.h @@ -32,7 +32,7 @@ class EmptyHttpFilterConfig : public Server::Configuration::NamedHttpFilterConfi return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Empty()}; } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: EmptyHttpFilterConfig(const std::string& name) : name_(name) {} diff --git a/source/extensions/filters/http/common/factory_base.h b/source/extensions/filters/http/common/factory_base.h index 71feb76c9e38..6aee7a15b36a 100644 --- a/source/extensions/filters/http/common/factory_base.h +++ b/source/extensions/filters/http/common/factory_base.h @@ -40,7 +40,7 @@ class FactoryBase : public Server::Configuration::NamedHttpFilterConfigFactory { validator); } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: FactoryBase(const std::string& name) : name_(name) {} diff --git a/source/extensions/filters/listener/http_inspector/config.cc b/source/extensions/filters/listener/http_inspector/config.cc index 3a0833d6721f..cb81bfa1505b 100644 --- a/source/extensions/filters/listener/http_inspector/config.cc +++ b/source/extensions/filters/listener/http_inspector/config.cc @@ -28,7 +28,7 @@ class HttpInspectorConfigFactory : public Server::Configuration::NamedListenerFi return std::make_unique(); } - std::string name() override { return ListenerFilterNames::get().HttpInspector; } + std::string name() const override { return ListenerFilterNames::get().HttpInspector; } }; /** diff --git a/source/extensions/filters/listener/original_dst/config.cc b/source/extensions/filters/listener/original_dst/config.cc index c8117ca0369c..230f99a54e5b 100644 --- a/source/extensions/filters/listener/original_dst/config.cc +++ b/source/extensions/filters/listener/original_dst/config.cc @@ -29,7 +29,7 @@ class OriginalDstConfigFactory : public Server::Configuration::NamedListenerFilt return std::make_unique(); } - std::string name() override { return ListenerFilterNames::get().OriginalDst; } + std::string name() const override { return ListenerFilterNames::get().OriginalDst; } }; /** diff --git a/source/extensions/filters/listener/original_src/original_src_config_factory.h b/source/extensions/filters/listener/original_src/original_src_config_factory.h index 9ffda7d61e1d..ea1a3cbd4ee3 100644 --- a/source/extensions/filters/listener/original_src/original_src_config_factory.h +++ b/source/extensions/filters/listener/original_src/original_src_config_factory.h @@ -21,7 +21,7 @@ class OriginalSrcConfigFactory : public Server::Configuration::NamedListenerFilt ProtobufTypes::MessagePtr createEmptyConfigProto() override; - std::string name() override { return ListenerFilterNames::get().OriginalSrc; } + std::string name() const override { return ListenerFilterNames::get().OriginalSrc; } }; } // namespace OriginalSrc diff --git a/source/extensions/filters/listener/proxy_protocol/config.cc b/source/extensions/filters/listener/proxy_protocol/config.cc index e267d994414a..e3c2f8122462 100644 --- a/source/extensions/filters/listener/proxy_protocol/config.cc +++ b/source/extensions/filters/listener/proxy_protocol/config.cc @@ -28,7 +28,7 @@ class ProxyProtocolConfigFactory : public Server::Configuration::NamedListenerFi return std::make_unique(); } - std::string name() override { return ListenerFilterNames::get().ProxyProtocol; } + std::string name() const override { return ListenerFilterNames::get().ProxyProtocol; } }; /** diff --git a/source/extensions/filters/listener/tls_inspector/config.cc b/source/extensions/filters/listener/tls_inspector/config.cc index 8f18e2c98129..cfe5ace74e2d 100644 --- a/source/extensions/filters/listener/tls_inspector/config.cc +++ b/source/extensions/filters/listener/tls_inspector/config.cc @@ -30,7 +30,7 @@ class TlsInspectorConfigFactory : public Server::Configuration::NamedListenerFil return std::make_unique(); } - std::string name() override { return ListenerFilterNames::get().TlsInspector; } + std::string name() const override { return ListenerFilterNames::get().TlsInspector; } }; /** diff --git a/source/extensions/filters/network/common/factory_base.h b/source/extensions/filters/network/common/factory_base.h index d72b4cd49765..d11eca0ec750 100644 --- a/source/extensions/filters/network/common/factory_base.h +++ b/source/extensions/filters/network/common/factory_base.h @@ -38,7 +38,7 @@ class FactoryBase : public Server::Configuration::NamedNetworkFilterConfigFactor proto_config, validation_visitor)); } - std::string name() override { return name_; } + std::string name() const override { return name_; } bool isTerminalFilter() override { return is_terminal_filter_; } diff --git a/source/extensions/filters/network/dubbo_proxy/BUILD b/source/extensions/filters/network/dubbo_proxy/BUILD index c561ff81ec03..23f4a1db115c 100644 --- a/source/extensions/filters/network/dubbo_proxy/BUILD +++ b/source/extensions/filters/network/dubbo_proxy/BUILD @@ -38,6 +38,7 @@ envoy_cc_library( ":message_lib", ":metadata_lib", ":serializer_interface", + "//include/envoy/config:typed_config_interface", "//source/common/common:assert_lib", "//source/common/config:utility_lib", "//source/common/singleton:const_singleton", @@ -67,6 +68,7 @@ envoy_cc_library( ":message_lib", ":metadata_lib", "//include/envoy/buffer:buffer_interface", + "//include/envoy/config:typed_config_interface", "//source/common/common:assert_lib", "//source/common/config:utility_lib", "//source/common/singleton:const_singleton", diff --git a/source/extensions/filters/network/dubbo_proxy/config.cc b/source/extensions/filters/network/dubbo_proxy/config.cc index 3d4fcce422e7..c91d8265504e 100644 --- a/source/extensions/filters/network/dubbo_proxy/config.cc +++ b/source/extensions/filters/network/dubbo_proxy/config.cc @@ -137,15 +137,14 @@ ProtocolPtr ConfigImpl::createProtocol() { } void ConfigImpl::registerFilter(const DubboFilterConfig& proto_config) { - const std::string& string_name = proto_config.name(); - + const auto& string_name = proto_config.name(); ENVOY_LOG(debug, " dubbo filter #{}", filter_factories_.size()); ENVOY_LOG(debug, " name: {}", string_name); ENVOY_LOG(debug, " config: {}", MessageUtil::getJsonStringFromMessage(proto_config.config(), true)); auto& factory = - Envoy::Config::Utility::getAndCheckFactory( + Envoy::Config::Utility::getAndCheckFactoryByName( string_name); ProtobufTypes::MessagePtr message = factory.createEmptyConfigProto(); Envoy::Config::Utility::translateOpaqueConfig(proto_config.config(), diff --git a/source/extensions/filters/network/dubbo_proxy/filters/BUILD b/source/extensions/filters/network/dubbo_proxy/filters/BUILD index 253738c08779..19f4fd317675 100644 --- a/source/extensions/filters/network/dubbo_proxy/filters/BUILD +++ b/source/extensions/filters/network/dubbo_proxy/filters/BUILD @@ -28,6 +28,7 @@ envoy_cc_library( hdrs = ["filter_config.h"], deps = [ ":filter_interface", + "//include/envoy/config:typed_config_interface", "//include/envoy/server:filter_config_interface", "//source/common/common:macros", "//source/common/protobuf:cc_wkt_protos", diff --git a/source/extensions/filters/network/dubbo_proxy/filters/factory_base.h b/source/extensions/filters/network/dubbo_proxy/filters/factory_base.h index 021d99b52e2f..4591ca9aac82 100644 --- a/source/extensions/filters/network/dubbo_proxy/filters/factory_base.h +++ b/source/extensions/filters/network/dubbo_proxy/filters/factory_base.h @@ -30,7 +30,7 @@ template class FactoryBase : public NamedDubboFilterConfigFa return std::make_unique(); } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: FactoryBase(const std::string& name) : name_(name) {} diff --git a/source/extensions/filters/network/dubbo_proxy/filters/filter_config.h b/source/extensions/filters/network/dubbo_proxy/filters/filter_config.h index e3cc0c4b45f5..2ccbd9047790 100644 --- a/source/extensions/filters/network/dubbo_proxy/filters/filter_config.h +++ b/source/extensions/filters/network/dubbo_proxy/filters/filter_config.h @@ -3,6 +3,7 @@ #include #include "envoy/common/pure.h" +#include "envoy/config/typed_config.h" #include "envoy/server/filter_config.h" #include "common/common/macros.h" @@ -20,7 +21,7 @@ namespace DubboFilters { * Implemented by each Dubbo filter and registered via Registry::registerFactory or the * convenience class RegisterFactory. */ -class NamedDubboFilterConfigFactory { +class NamedDubboFilterConfigFactory : public Envoy::Config::TypedFactory { public: virtual ~NamedDubboFilterConfigFactory() = default; @@ -37,25 +38,7 @@ class NamedDubboFilterConfigFactory { createFilterFactoryFromProto(const Protobuf::Message& config, const std::string& stat_prefix, Server::Configuration::FactoryContext& context) PURE; - /** - * @return ProtobufTypes::MessagePtr create empty config proto message for v2. The filter - * config, which arrives in an opaque google.protobuf.Struct message, will be converted to - * JSON and then parsed into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * @return std::string the identifying name for a particular implementation of a dubbo filter - * produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "dubbo_proxy.filters"; } + std::string category() const override { return "dubbo_proxy.filters"; } }; } // namespace DubboFilters diff --git a/source/extensions/filters/network/dubbo_proxy/protocol.h b/source/extensions/filters/network/dubbo_proxy/protocol.h index e97ab25cb748..e75e82bcc574 100644 --- a/source/extensions/filters/network/dubbo_proxy/protocol.h +++ b/source/extensions/filters/network/dubbo_proxy/protocol.h @@ -4,6 +4,7 @@ #include #include "envoy/buffer/buffer.h" +#include "envoy/config/typed_config.h" #include "common/common/assert.h" #include "common/common/fmt.h" @@ -97,7 +98,7 @@ using ProtocolPtr = std::unique_ptr; * Implemented by each Dubbo protocol and registered via Registry::registerFactory or the * convenience class RegisterFactory. */ -class NamedProtocolConfigFactory { +class NamedProtocolConfigFactory : public Config::UntypedFactory { public: virtual ~NamedProtocolConfigFactory() = default; @@ -108,18 +109,7 @@ class NamedProtocolConfigFactory { */ virtual ProtocolPtr createProtocol(SerializationType serialization_type) PURE; - /** - * @return std::string the identifying name for a particular implementation of Dubbo protocol - * produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "dubbo_proxy.protocols"; } + std::string category() const override { return "dubbo_proxy.protocols"; } /** * Convenience method to lookup a factory by type. @@ -128,7 +118,7 @@ class NamedProtocolConfigFactory { */ static NamedProtocolConfigFactory& getFactory(ProtocolType type) { const std::string& name = ProtocolNames::get().fromType(type); - return Envoy::Config::Utility::getAndCheckFactory(name); + return Envoy::Config::Utility::getAndCheckFactoryByName(name); } }; @@ -143,7 +133,7 @@ template class ProtocolFactoryBase : public NamedProtocolCo return protocol; } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: ProtocolFactoryBase(ProtocolType type) : name_(ProtocolNames::get().fromType(type)) {} diff --git a/source/extensions/filters/network/dubbo_proxy/router/BUILD b/source/extensions/filters/network/dubbo_proxy/router/BUILD index 70c68995025b..591b374cde9b 100644 --- a/source/extensions/filters/network/dubbo_proxy/router/BUILD +++ b/source/extensions/filters/network/dubbo_proxy/router/BUILD @@ -22,6 +22,7 @@ envoy_cc_library( hdrs = ["route.h"], deps = [ ":router_interface", + "//include/envoy/config:typed_config_interface", "//include/envoy/server:filter_config_interface", "//source/common/config:utility_lib", "//source/common/singleton:const_singleton", diff --git a/source/extensions/filters/network/dubbo_proxy/router/route.h b/source/extensions/filters/network/dubbo_proxy/router/route.h index 4242540e2d7d..590c26e3127a 100644 --- a/source/extensions/filters/network/dubbo_proxy/router/route.h +++ b/source/extensions/filters/network/dubbo_proxy/router/route.h @@ -3,6 +3,7 @@ #include #include +#include "envoy/config/typed_config.h" #include "envoy/extensions/filters/network/dubbo_proxy/v3alpha/route.pb.h" #include "envoy/router/router.h" #include "envoy/server/filter_config.h" @@ -66,7 +67,7 @@ using RouteMatcherConstSharedPtr = std::shared_ptr; * Implemented by each Dubbo protocol and registered via Registry::registerFactory or the * convenience class RegisterFactory. */ -class NamedRouteMatcherConfigFactory { +class NamedRouteMatcherConfigFactory : public Envoy::Config::UntypedFactory { public: virtual ~NamedRouteMatcherConfigFactory() = default; @@ -78,18 +79,7 @@ class NamedRouteMatcherConfigFactory { virtual RouteMatcherPtr createRouteMatcher(const RouteConfigurations& route_configs, Server::Configuration::FactoryContext& context) PURE; - /** - * @return std::string the identifying name for a particular implementation of Dubbo protocol - * produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "dubbo_proxy.route_matchers"; } + std::string category() const override { return "dubbo_proxy.route_matchers"; } /** * Convenience method to lookup a factory by type. @@ -98,7 +88,7 @@ class NamedRouteMatcherConfigFactory { */ static NamedRouteMatcherConfigFactory& getFactory(RouteMatcherType type) { const std::string& name = RouteMatcherNames::get().fromType(type); - return Envoy::Config::Utility::getAndCheckFactory(name); + return Envoy::Config::Utility::getAndCheckFactoryByName(name); } }; @@ -113,7 +103,7 @@ class RouteMatcherFactoryBase : public NamedRouteMatcherConfigFactory { return std::make_unique(route_configs, context); } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: RouteMatcherFactoryBase(RouteMatcherType type) : name_(RouteMatcherNames::get().fromType(type)) {} diff --git a/source/extensions/filters/network/dubbo_proxy/serializer.h b/source/extensions/filters/network/dubbo_proxy/serializer.h index c32d41ed2499..32623f36910f 100644 --- a/source/extensions/filters/network/dubbo_proxy/serializer.h +++ b/source/extensions/filters/network/dubbo_proxy/serializer.h @@ -4,6 +4,7 @@ #include #include "envoy/buffer/buffer.h" +#include "envoy/config/typed_config.h" #include "common/common/assert.h" #include "common/config/utility.h" @@ -78,7 +79,7 @@ using SerializerPtr = std::unique_ptr; * Implemented by each Dubbo serialize and registered via Registry::registerFactory or the * convenience class RegisterFactory. */ -class NamedSerializerConfigFactory { +class NamedSerializerConfigFactory : public Config::UntypedFactory { public: virtual ~NamedSerializerConfigFactory() = default; @@ -88,18 +89,7 @@ class NamedSerializerConfigFactory { */ virtual SerializerPtr createSerializer() PURE; - /** - * @return std::string the identifying name for a particular implementation of Dubbo serializer - * produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "dubbo_proxy.serializers"; } + std::string category() const override { return "dubbo_proxy.serializers"; } /** * Convenience method to lookup a factory by type. @@ -109,7 +99,7 @@ class NamedSerializerConfigFactory { static NamedSerializerConfigFactory& getFactory(ProtocolType protocol_type, SerializationType type) { const std::string& name = ProtocolSerializerNames::get().fromType(protocol_type, type); - return Envoy::Config::Utility::getAndCheckFactory(name); + return Envoy::Config::Utility::getAndCheckFactoryByName(name); } }; @@ -120,7 +110,7 @@ template class SerializerFactoryBase : public NamedSerial public: SerializerPtr createSerializer() override { return std::make_unique(); } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: SerializerFactoryBase(ProtocolType protocol_type, SerializationType type) diff --git a/source/extensions/filters/network/echo/config.cc b/source/extensions/filters/network/echo/config.cc index 34afc4458917..47375949ed4f 100644 --- a/source/extensions/filters/network/echo/config.cc +++ b/source/extensions/filters/network/echo/config.cc @@ -27,7 +27,7 @@ class EchoConfigFactory : public Server::Configuration::NamedNetworkFilterConfig return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Empty()}; } - std::string name() override { return NetworkFilterNames::get().Echo; } + std::string name() const override { return NetworkFilterNames::get().Echo; } bool isTerminalFilter() override { return true; } }; diff --git a/source/extensions/filters/network/http_connection_manager/config.cc b/source/extensions/filters/network/http_connection_manager/config.cc index 5242295ec818..ea9b96c66bec 100644 --- a/source/extensions/filters/network/http_connection_manager/config.cc +++ b/source/extensions/filters/network/http_connection_manager/config.cc @@ -403,10 +403,8 @@ void HttpConnectionManagerConfig::processFilter( proto_config, int i, absl::string_view prefix, std::list& filter_factories, bool& is_terminal) { - const std::string& string_name = proto_config.name(); - ENVOY_LOG(debug, " {} filter #{}", prefix, i); - ENVOY_LOG(debug, " name: {}", string_name); + ENVOY_LOG(debug, " name: {}", proto_config.name()); ENVOY_LOG( debug, " config: {}", MessageUtil::getJsonStringFromMessage(proto_config.hidden_envoy_deprecated_config(), true)); @@ -414,7 +412,7 @@ void HttpConnectionManagerConfig::processFilter( // Now see if there is a factory that will accept the config. auto& factory = Config::Utility::getAndCheckFactory( - string_name); + proto_config); ProtobufTypes::MessagePtr message = Config::Utility::translateToFactoryConfig( proto_config, context_.messageValidationVisitor(), factory); Http::FilterFactoryCb callback = @@ -442,7 +440,7 @@ HttpConnectionManagerConfig::createCodec(Network::Connection& connection, // from HttpConnectionManager protobuf. This is not essential till there are multiple // implementations of QUIC. return std::unique_ptr( - Config::Utility::getAndCheckFactory( + Config::Utility::getAndCheckFactoryByName( Http::QuicCodecNames::get().Quiche) .createQuicServerConnection(connection, callbacks)); case CodecType::AUTO: diff --git a/source/extensions/filters/network/sni_cluster/config.h b/source/extensions/filters/network/sni_cluster/config.h index fa0f45e68099..9091e7685401 100644 --- a/source/extensions/filters/network/sni_cluster/config.h +++ b/source/extensions/filters/network/sni_cluster/config.h @@ -19,7 +19,7 @@ class SniClusterNetworkFilterConfigFactory createFilterFactoryFromProto(const Protobuf::Message&, Server::Configuration::FactoryContext&) override; ProtobufTypes::MessagePtr createEmptyConfigProto() override; - std::string name() override { return NetworkFilterNames::get().SniCluster; } + std::string name() const override { return NetworkFilterNames::get().SniCluster; } }; } // namespace SniCluster diff --git a/source/extensions/filters/network/thrift_proxy/BUILD b/source/extensions/filters/network/thrift_proxy/BUILD index bf27c42c07fa..7ca9d1ca3204 100644 --- a/source/extensions/filters/network/thrift_proxy/BUILD +++ b/source/extensions/filters/network/thrift_proxy/BUILD @@ -159,6 +159,7 @@ envoy_cc_library( ":thrift_object_interface", ":transport_interface", "//include/envoy/buffer:buffer_interface", + "//include/envoy/config:typed_config_interface", "//include/envoy/registry", "//source/common/common:assert_lib", "//source/common/config:utility_lib", @@ -250,6 +251,7 @@ envoy_cc_library( ":metadata_lib", ":thrift_lib", "//include/envoy/buffer:buffer_interface", + "//include/envoy/config:typed_config_interface", "//include/envoy/registry", "//source/common/common:assert_lib", "//source/common/config:utility_lib", diff --git a/source/extensions/filters/network/thrift_proxy/config.cc b/source/extensions/filters/network/thrift_proxy/config.cc index 526f22819a3f..bfd415d4b0d0 100644 --- a/source/extensions/filters/network/thrift_proxy/config.cc +++ b/source/extensions/filters/network/thrift_proxy/config.cc @@ -168,7 +168,7 @@ void ConfigImpl::processFilter( MessageUtil::getJsonStringFromMessage(proto_config.hidden_envoy_deprecated_config(), true)); auto& factory = Envoy::Config::Utility::getAndCheckFactory( - string_name); + proto_config); ProtobufTypes::MessagePtr message = Envoy::Config::Utility::translateToFactoryConfig( proto_config, context_.messageValidationVisitor(), factory); diff --git a/source/extensions/filters/network/thrift_proxy/filters/BUILD b/source/extensions/filters/network/thrift_proxy/filters/BUILD index 233aaf8edc90..1f4ebe2b5fc6 100644 --- a/source/extensions/filters/network/thrift_proxy/filters/BUILD +++ b/source/extensions/filters/network/thrift_proxy/filters/BUILD @@ -13,6 +13,7 @@ envoy_cc_library( hdrs = ["filter_config.h"], deps = [ ":filter_interface", + "//include/envoy/config:typed_config_interface", "//include/envoy/server:filter_config_interface", "//source/common/common:macros", "//source/common/protobuf:cc_wkt_protos", diff --git a/source/extensions/filters/network/thrift_proxy/filters/factory_base.h b/source/extensions/filters/network/thrift_proxy/filters/factory_base.h index 159328b73a94..3f6f1b144d11 100644 --- a/source/extensions/filters/network/thrift_proxy/filters/factory_base.h +++ b/source/extensions/filters/network/thrift_proxy/filters/factory_base.h @@ -25,7 +25,7 @@ template class FactoryBase : public NamedThriftFilterConfigF return std::make_unique(); } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: FactoryBase(const std::string& name) : name_(name) {} diff --git a/source/extensions/filters/network/thrift_proxy/filters/filter_config.h b/source/extensions/filters/network/thrift_proxy/filters/filter_config.h index a012e2db7e9f..47e7f5f37bd6 100644 --- a/source/extensions/filters/network/thrift_proxy/filters/filter_config.h +++ b/source/extensions/filters/network/thrift_proxy/filters/filter_config.h @@ -1,5 +1,6 @@ #pragma once +#include "envoy/config/typed_config.h" #include "envoy/server/filter_config.h" #include "common/common/macros.h" @@ -17,7 +18,7 @@ namespace ThriftFilters { * Implemented by each Thrift filter and registered via Registry::registerFactory or the * convenience class RegisterFactory. */ -class NamedThriftFilterConfigFactory { +class NamedThriftFilterConfigFactory : public Envoy::Config::TypedFactory { public: virtual ~NamedThriftFilterConfigFactory() = default; @@ -34,25 +35,7 @@ class NamedThriftFilterConfigFactory { createFilterFactoryFromProto(const Protobuf::Message& config, const std::string& stat_prefix, Server::Configuration::FactoryContext& context) PURE; - /** - * @return ProtobufTypes::MessagePtr create empty config proto message for v2. The filter - * config, which arrives in an opaque google.protobuf.Struct message, will be converted to - * JSON and then parsed into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * @return std::string the identifying name for a particular implementation of a thrift filter - * produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "thrift_proxy.filters"; } + std::string category() const override { return "thrift_proxy.filters"; } }; } // namespace ThriftFilters diff --git a/source/extensions/filters/network/thrift_proxy/protocol.h b/source/extensions/filters/network/thrift_proxy/protocol.h index 3b3b947e7107..c6406ceb7e82 100644 --- a/source/extensions/filters/network/thrift_proxy/protocol.h +++ b/source/extensions/filters/network/thrift_proxy/protocol.h @@ -5,6 +5,7 @@ #include "envoy/buffer/buffer.h" #include "envoy/common/pure.h" +#include "envoy/config/typed_config.h" #include "envoy/registry/registry.h" #include "common/common/assert.h" @@ -498,7 +499,7 @@ class DirectResponse { * Implemented by each Thrift protocol and registered via Registry::registerFactory or the * convenience class RegisterFactory. */ -class NamedProtocolConfigFactory { +class NamedProtocolConfigFactory : public Config::UntypedFactory { public: virtual ~NamedProtocolConfigFactory() = default; @@ -508,18 +509,7 @@ class NamedProtocolConfigFactory { */ virtual ProtocolPtr createProtocol() PURE; - /** - * @return std::string the identifying name for a particular implementation of thrift protocol - * produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "thrift_proxy.protocols"; } + std::string category() const override { return "thrift_proxy.protocols"; } /** * Convenience method to lookup a factory by type. @@ -528,7 +518,7 @@ class NamedProtocolConfigFactory { */ static NamedProtocolConfigFactory& getFactory(ProtocolType type) { const std::string& name = ProtocolNames::get().fromType(type); - return Envoy::Config::Utility::getAndCheckFactory(name); + return Envoy::Config::Utility::getAndCheckFactoryByName(name); } }; @@ -539,7 +529,7 @@ template class ProtocolFactoryBase : public NamedProtocolCo public: ProtocolPtr createProtocol() override { return std::move(std::make_unique()); } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: ProtocolFactoryBase(const std::string& name) : name_(name) {} diff --git a/source/extensions/filters/network/thrift_proxy/transport.h b/source/extensions/filters/network/thrift_proxy/transport.h index 4f676da5bd52..f1801973b10a 100644 --- a/source/extensions/filters/network/thrift_proxy/transport.h +++ b/source/extensions/filters/network/thrift_proxy/transport.h @@ -4,6 +4,7 @@ #include #include "envoy/buffer/buffer.h" +#include "envoy/config/typed_config.h" #include "envoy/registry/registry.h" #include "common/common/assert.h" @@ -82,7 +83,7 @@ using TransportPtr = std::unique_ptr; * Implemented by each Thrift transport and registered via Registry::registerFactory or the * convenience class RegisterFactory. */ -class NamedTransportConfigFactory { +class NamedTransportConfigFactory : public Envoy::Config::UntypedFactory { public: virtual ~NamedTransportConfigFactory() = default; @@ -92,18 +93,7 @@ class NamedTransportConfigFactory { */ virtual TransportPtr createTransport() PURE; - /** - * @return std::string the identifying name for a particular implementation of thrift transport - * produced by the factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "thrift_proxy.transports"; } + std::string category() const override { return "thrift_proxy.transports"; } /** * Convenience method to lookup a factory by type. @@ -112,7 +102,7 @@ class NamedTransportConfigFactory { */ static NamedTransportConfigFactory& getFactory(TransportType type) { const std::string& name = TransportNames::get().fromType(type); - return Envoy::Config::Utility::getAndCheckFactory(name); + return Envoy::Config::Utility::getAndCheckFactoryByName(name); } }; @@ -123,7 +113,7 @@ template class TransportFactoryBase : public NamedTranspor public: TransportPtr createTransport() override { return std::move(std::make_unique()); } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: TransportFactoryBase(const std::string& name) : name_(name) {} diff --git a/source/extensions/filters/udp/udp_proxy/config.h b/source/extensions/filters/udp/udp_proxy/config.h index 2e6178c99b11..a82991f5dd57 100644 --- a/source/extensions/filters/udp/udp_proxy/config.h +++ b/source/extensions/filters/udp/udp_proxy/config.h @@ -36,7 +36,7 @@ class UdpProxyFilterConfigFactory return std::make_unique(); } - std::string name() override { return "envoy.filters.udp_listener.udp_proxy"; } + std::string name() const override { return "envoy.filters.udp_listener.udp_proxy"; } }; } // namespace UdpProxy diff --git a/source/extensions/health_checkers/redis/config.h b/source/extensions/health_checkers/redis/config.h index 3b255939d9db..2b160ec47549 100644 --- a/source/extensions/health_checkers/redis/config.h +++ b/source/extensions/health_checkers/redis/config.h @@ -22,7 +22,7 @@ class RedisHealthCheckerFactory : public Server::Configuration::CustomHealthChec createCustomHealthChecker(const envoy::config::core::v3alpha::HealthCheck& config, Server::Configuration::HealthCheckerFactoryContext& context) override; - std::string name() override { return HealthCheckerNames::get().RedisHealthChecker; } + std::string name() const override { return HealthCheckerNames::get().RedisHealthChecker; } }; } // namespace RedisHealthChecker diff --git a/source/extensions/quic_listeners/quiche/active_quic_listener_config.cc b/source/extensions/quic_listeners/quiche/active_quic_listener_config.cc index 89c0c87de477..61fda6646289 100644 --- a/source/extensions/quic_listeners/quiche/active_quic_listener_config.cc +++ b/source/extensions/quic_listeners/quiche/active_quic_listener_config.cc @@ -18,7 +18,7 @@ ActiveQuicListenerConfigFactory::createActiveUdpListenerFactory(const Protobuf:: return std::make_unique(config); } -std::string ActiveQuicListenerConfigFactory::name() { return QuicListenerName; } +std::string ActiveQuicListenerConfigFactory::name() const { return QuicListenerName; } REGISTER_FACTORY(ActiveQuicListenerConfigFactory, Server::ActiveUdpListenerConfigFactory); diff --git a/source/extensions/quic_listeners/quiche/active_quic_listener_config.h b/source/extensions/quic_listeners/quiche/active_quic_listener_config.h index 78d6e7bb88c0..f63e655d258c 100644 --- a/source/extensions/quic_listeners/quiche/active_quic_listener_config.h +++ b/source/extensions/quic_listeners/quiche/active_quic_listener_config.h @@ -18,7 +18,7 @@ class ActiveQuicListenerConfigFactory : public Server::ActiveUdpListenerConfigFa Network::ActiveUdpListenerFactoryPtr createActiveUdpListenerFactory(const Protobuf::Message&) override; - std::string name() override; + std::string name() const override; }; DECLARE_FACTORY(ActiveQuicListenerConfigFactory); diff --git a/source/extensions/quic_listeners/quiche/quic_transport_socket_factory.h b/source/extensions/quic_listeners/quiche/quic_transport_socket_factory.h index e254692df48e..009af3008368 100644 --- a/source/extensions/quic_listeners/quiche/quic_transport_socket_factory.h +++ b/source/extensions/quic_listeners/quiche/quic_transport_socket_factory.h @@ -71,6 +71,9 @@ class QuicServerTransportSocketConfigFactory // Server::Configuration::TransportSocketConfigFactory ProtobufTypes::MessagePtr createEmptyConfigProto() override; + + // Prevent double registration for the config proto + std::string configType() override { return ""; } }; DECLARE_FACTORY(QuicServerTransportSocketConfigFactory); @@ -86,6 +89,9 @@ class QuicClientTransportSocketConfigFactory // Server::Configuration::TransportSocketConfigFactory ProtobufTypes::MessagePtr createEmptyConfigProto() override; + + // Prevent double registration for the config proto + std::string configType() override { return ""; } }; DECLARE_FACTORY(QuicClientTransportSocketConfigFactory); diff --git a/source/extensions/resource_monitors/common/factory_base.h b/source/extensions/resource_monitors/common/factory_base.h index 65350bc6950c..97253f648960 100644 --- a/source/extensions/resource_monitors/common/factory_base.h +++ b/source/extensions/resource_monitors/common/factory_base.h @@ -24,7 +24,7 @@ class FactoryBase : public Server::Configuration::ResourceMonitorFactory { return std::make_unique(); } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: FactoryBase(const std::string& name) : name_(name) {} @@ -52,7 +52,7 @@ class EmptyConfigFactoryBase : public Server::Configuration::ResourceMonitorFact return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Empty()}; } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: EmptyConfigFactoryBase(const std::string& name) : name_(name) {} diff --git a/source/extensions/retry/host/omit_canary_hosts/config.h b/source/extensions/retry/host/omit_canary_hosts/config.h index 53e3476499d8..e2240e4471af 100644 --- a/source/extensions/retry/host/omit_canary_hosts/config.h +++ b/source/extensions/retry/host/omit_canary_hosts/config.h @@ -16,7 +16,9 @@ class OmitCanaryHostsRetryPredicateFactory : public Upstream::RetryHostPredicate return std::make_shared(); } - std::string name() override { return RetryHostPredicateValues::get().OmitCanaryHostsPredicate; } + std::string name() const override { + return RetryHostPredicateValues::get().OmitCanaryHostsPredicate; + } ProtobufTypes::MessagePtr createEmptyConfigProto() override { return std::make_unique(); diff --git a/source/extensions/retry/host/previous_hosts/config.h b/source/extensions/retry/host/previous_hosts/config.h index ddc762f661eb..8c76ba65a9c8 100644 --- a/source/extensions/retry/host/previous_hosts/config.h +++ b/source/extensions/retry/host/previous_hosts/config.h @@ -17,7 +17,9 @@ class PreviousHostsRetryPredicateFactory : public Upstream::RetryHostPredicateFa return std::make_shared(retry_count); } - std::string name() override { return RetryHostPredicateValues::get().PreviousHostsPredicate; } + std::string name() const override { + return RetryHostPredicateValues::get().PreviousHostsPredicate; + } ProtobufTypes::MessagePtr createEmptyConfigProto() override { return std::make_unique(); diff --git a/source/extensions/stat_sinks/dog_statsd/config.cc b/source/extensions/stat_sinks/dog_statsd/config.cc index 896b043cd090..b060fd1a3e1c 100644 --- a/source/extensions/stat_sinks/dog_statsd/config.cc +++ b/source/extensions/stat_sinks/dog_statsd/config.cc @@ -32,7 +32,7 @@ ProtobufTypes::MessagePtr DogStatsdSinkFactory::createEmptyConfigProto() { return std::make_unique(); } -std::string DogStatsdSinkFactory::name() { return StatsSinkNames::get().DogStatsd; } +std::string DogStatsdSinkFactory::name() const { return StatsSinkNames::get().DogStatsd; } /** * Static registration for the this sink factory. @see RegisterFactory. diff --git a/source/extensions/stat_sinks/dog_statsd/config.h b/source/extensions/stat_sinks/dog_statsd/config.h index 44e1ecaaa77f..5e9cfdef1cb2 100644 --- a/source/extensions/stat_sinks/dog_statsd/config.h +++ b/source/extensions/stat_sinks/dog_statsd/config.h @@ -20,7 +20,7 @@ class DogStatsdSinkFactory : Logger::Loggable, ProtobufTypes::MessagePtr createEmptyConfigProto() override; - std::string name() override; + std::string name() const override; }; } // namespace DogStatsd diff --git a/source/extensions/stat_sinks/hystrix/config.cc b/source/extensions/stat_sinks/hystrix/config.cc index d9639a40ebe7..4d42347373a9 100644 --- a/source/extensions/stat_sinks/hystrix/config.cc +++ b/source/extensions/stat_sinks/hystrix/config.cc @@ -28,7 +28,7 @@ ProtobufTypes::MessagePtr HystrixSinkFactory::createEmptyConfigProto() { return std::make_unique(); } -std::string HystrixSinkFactory::name() { return StatsSinkNames::get().Hystrix; } +std::string HystrixSinkFactory::name() const { return StatsSinkNames::get().Hystrix; } /** * Static registration for the statsd sink factory. @see RegisterFactory. diff --git a/source/extensions/stat_sinks/hystrix/config.h b/source/extensions/stat_sinks/hystrix/config.h index 2f3f7c37f878..396cab600254 100644 --- a/source/extensions/stat_sinks/hystrix/config.h +++ b/source/extensions/stat_sinks/hystrix/config.h @@ -20,7 +20,7 @@ class HystrixSinkFactory : Logger::Loggable, ProtobufTypes::MessagePtr createEmptyConfigProto() override; - std::string name() override; + std::string name() const override; }; } // namespace Hystrix diff --git a/source/extensions/stat_sinks/metrics_service/config.cc b/source/extensions/stat_sinks/metrics_service/config.cc index 414827a7396e..8d88c3db4430 100644 --- a/source/extensions/stat_sinks/metrics_service/config.cc +++ b/source/extensions/stat_sinks/metrics_service/config.cc @@ -41,7 +41,7 @@ ProtobufTypes::MessagePtr MetricsServiceSinkFactory::createEmptyConfigProto() { std::make_unique()); } -std::string MetricsServiceSinkFactory::name() { return StatsSinkNames::get().MetricsService; } +std::string MetricsServiceSinkFactory::name() const { return StatsSinkNames::get().MetricsService; } /** * Static registration for the this sink factory. @see RegisterFactory. diff --git a/source/extensions/stat_sinks/metrics_service/config.h b/source/extensions/stat_sinks/metrics_service/config.h index 5c2f95e49a64..702ea0e97821 100644 --- a/source/extensions/stat_sinks/metrics_service/config.h +++ b/source/extensions/stat_sinks/metrics_service/config.h @@ -21,7 +21,7 @@ class MetricsServiceSinkFactory : Logger::Loggable, ProtobufTypes::MessagePtr createEmptyConfigProto() override; - std::string name() override; + std::string name() const override; }; DECLARE_FACTORY(MetricsServiceSinkFactory); diff --git a/source/extensions/stat_sinks/statsd/config.cc b/source/extensions/stat_sinks/statsd/config.cc index fd5beb20a340..58ea4b050873 100644 --- a/source/extensions/stat_sinks/statsd/config.cc +++ b/source/extensions/stat_sinks/statsd/config.cc @@ -45,7 +45,7 @@ ProtobufTypes::MessagePtr StatsdSinkFactory::createEmptyConfigProto() { return std::make_unique(); } -std::string StatsdSinkFactory::name() { return StatsSinkNames::get().Statsd; } +std::string StatsdSinkFactory::name() const { return StatsSinkNames::get().Statsd; } /** * Static registration for the statsd sink factory. @see RegisterFactory. diff --git a/source/extensions/stat_sinks/statsd/config.h b/source/extensions/stat_sinks/statsd/config.h index 64d82f17624d..591308a70ef4 100644 --- a/source/extensions/stat_sinks/statsd/config.h +++ b/source/extensions/stat_sinks/statsd/config.h @@ -21,7 +21,7 @@ class StatsdSinkFactory : Logger::Loggable, ProtobufTypes::MessagePtr createEmptyConfigProto() override; - std::string name() override; + std::string name() const override; }; } // namespace Statsd diff --git a/source/extensions/tracers/common/factory_base.h b/source/extensions/tracers/common/factory_base.h index b32975a74e9f..7a6c3e0d1ad0 100644 --- a/source/extensions/tracers/common/factory_base.h +++ b/source/extensions/tracers/common/factory_base.h @@ -27,7 +27,7 @@ template class FactoryBase : public Server::Configuration::T return std::make_unique(); } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: FactoryBase(const std::string& name) : name_(name) {} diff --git a/source/extensions/transport_sockets/tap/config.cc b/source/extensions/transport_sockets/tap/config.cc index 3c9f7db67ae9..8f12a3920f28 100644 --- a/source/extensions/transport_sockets/tap/config.cc +++ b/source/extensions/transport_sockets/tap/config.cc @@ -39,8 +39,7 @@ Network::TransportSocketFactoryPtr UpstreamTapSocketConfigFactory::createTranspo const envoy::extensions::transport_sockets::tap::v3alpha::Tap&>( message, context.messageValidationVisitor()); auto& inner_config_factory = Config::Utility::getAndCheckFactory< - Server::Configuration::UpstreamTransportSocketConfigFactory>( - outer_config.transport_socket().name()); + Server::Configuration::UpstreamTransportSocketConfigFactory>(outer_config.transport_socket()); ProtobufTypes::MessagePtr inner_factory_config = Config::Utility::translateToFactoryConfig( outer_config.transport_socket(), context.messageValidationVisitor(), inner_config_factory); auto inner_transport_factory = @@ -59,7 +58,7 @@ Network::TransportSocketFactoryPtr DownstreamTapSocketConfigFactory::createTrans message, context.messageValidationVisitor()); auto& inner_config_factory = Config::Utility::getAndCheckFactory< Server::Configuration::DownstreamTransportSocketConfigFactory>( - outer_config.transport_socket().name()); + outer_config.transport_socket()); ProtobufTypes::MessagePtr inner_factory_config = Config::Utility::translateToFactoryConfig( outer_config.transport_socket(), context.messageValidationVisitor(), inner_config_factory); auto inner_transport_factory = inner_config_factory.createTransportSocketFactory( diff --git a/source/server/BUILD b/source/server/BUILD index 115cf25bb372..128feeab5222 100644 --- a/source/server/BUILD +++ b/source/server/BUILD @@ -29,6 +29,7 @@ envoy_cc_library( srcs = ["configuration_impl.cc"], hdrs = ["configuration_impl.h"], deps = [ + "//include/envoy/config:typed_config_interface", "//include/envoy/http:filter_interface", "//include/envoy/network:connection_interface", "//include/envoy/network:filter_interface", diff --git a/source/server/active_raw_udp_listener_config.cc b/source/server/active_raw_udp_listener_config.cc index 8eea3f4742e9..269b64450aa5 100644 --- a/source/server/active_raw_udp_listener_config.cc +++ b/source/server/active_raw_udp_listener_config.cc @@ -23,7 +23,9 @@ ActiveRawUdpListenerConfigFactory::createActiveUdpListenerFactory( return std::make_unique(); } -std::string ActiveRawUdpListenerConfigFactory::name() { return UdpListenerNames::get().RawUdp; } +std::string ActiveRawUdpListenerConfigFactory::name() const { + return UdpListenerNames::get().RawUdp; +} REGISTER_FACTORY(ActiveRawUdpListenerConfigFactory, Server::ActiveUdpListenerConfigFactory); diff --git a/source/server/active_raw_udp_listener_config.h b/source/server/active_raw_udp_listener_config.h index 3a2477f27492..337709bd29bb 100644 --- a/source/server/active_raw_udp_listener_config.h +++ b/source/server/active_raw_udp_listener_config.h @@ -26,7 +26,7 @@ class ActiveRawUdpListenerConfigFactory : public ActiveUdpListenerConfigFactory Network::ActiveUdpListenerFactoryPtr createActiveUdpListenerFactory(const Protobuf::Message&) override; - std::string name() override; + std::string name() const override; }; DECLARE_FACTORY(ActiveRawUdpListenerConfigFactory); diff --git a/source/server/config_validation/server.cc b/source/server/config_validation/server.cc index 891a77f84473..fd1635c72e5c 100644 --- a/source/server/config_validation/server.cc +++ b/source/server/config_validation/server.cc @@ -94,8 +94,7 @@ void ValidationInstance::initialize(const Options& options, thread_local_.registerThread(*dispatcher_, true); runtime_loader_ = component_factory.createRuntime(*this, initial_config); secret_manager_ = std::make_unique(admin().getConfigTracker()); - ssl_context_manager_ = - createContextManager(Ssl::ContextManagerFactory::name(), api_->timeSource()); + ssl_context_manager_ = createContextManager("ssl_context_manager", api_->timeSource()); cluster_manager_factory_ = std::make_unique( admin(), runtime(), stats(), threadLocal(), random(), dnsResolver(), sslContextManager(), dispatcher(), localInfo(), *secret_manager_, messageValidationContext(), *api_, http_context_, diff --git a/source/server/configuration_impl.cc b/source/server/configuration_impl.cc index da1739c158da..8a290ea7fb24 100644 --- a/source/server/configuration_impl.cc +++ b/source/server/configuration_impl.cc @@ -102,11 +102,10 @@ void MainImpl::initializeTracers(const envoy::config::trace::v3alpha::Tracing& c } // Initialize tracing driver. - std::string type = configuration.http().name(); - ENVOY_LOG(info, " loading tracing driver: {}", type); + ENVOY_LOG(info, " loading tracing driver: {}", configuration.http().name()); // Now see if there is a factory that will accept the config. - auto& factory = Config::Utility::getAndCheckFactory(type); + auto& factory = Config::Utility::getAndCheckFactory(configuration.http()); ProtobufTypes::MessagePtr message = Config::Utility::translateToFactoryConfig( configuration.http(), server.messageValidationContext().staticValidationVisitor(), factory); http_tracer_ = factory.createHttpTracer(*message, server); @@ -118,7 +117,7 @@ void MainImpl::initializeStatsSinks(const envoy::config::bootstrap::v3alpha::Boo for (const envoy::config::metrics::v3alpha::StatsSink& sink_object : bootstrap.stats_sinks()) { // Generate factory and translate stats sink custom config - auto& factory = Config::Utility::getAndCheckFactory(sink_object.name()); + auto& factory = Config::Utility::getAndCheckFactory(sink_object); ProtobufTypes::MessagePtr message = Config::Utility::translateToFactoryConfig( sink_object, server.messageValidationContext().staticValidationVisitor(), factory); diff --git a/source/server/configuration_impl.h b/source/server/configuration_impl.h index c07957d073d7..27067cef980e 100644 --- a/source/server/configuration_impl.h +++ b/source/server/configuration_impl.h @@ -11,6 +11,7 @@ #include "envoy/config/bootstrap/v3alpha/bootstrap.pb.h" #include "envoy/config/trace/v3alpha/trace.pb.h" +#include "envoy/config/typed_config.h" #include "envoy/http/filter.h" #include "envoy/network/filter.h" #include "envoy/server/configuration.h" @@ -30,7 +31,7 @@ namespace Configuration { * Implemented for each Stats::Sink and registered via Registry::registerFactory() or * the convenience class RegisterFactory. */ -class StatsSinkFactory { +class StatsSinkFactory : public Config::TypedFactory { public: virtual ~StatsSinkFactory() = default; @@ -43,25 +44,7 @@ class StatsSinkFactory { */ virtual Stats::SinkPtr createStatsSink(const Protobuf::Message& config, Instance& server) PURE; - /** - * @return ProtobufTypes::MessagePtr create empty config proto message for v2. The filter - * config, which arrives in an opaque google.protobuf.Struct message, will be converted to - * JSON and then parsed into this empty proto. - */ - virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; - - /** - * Returns the identifying name for a particular implementation of Stats::Sink produced by the - * factory. - */ - virtual std::string name() PURE; - - /** - * @return std::string the identifying category name for objects - * created by this factory. Used for automatic registration with - * FactoryCategoryRegistry. - */ - static std::string category() { return "stats_sinks"; } + std::string category() const override { return "stats_sinks"; } }; /** diff --git a/source/server/listener_impl.cc b/source/server/listener_impl.cc index 8b7432a1a21f..eb81fdf36523 100644 --- a/source/server/listener_impl.cc +++ b/source/server/listener_impl.cc @@ -174,8 +174,9 @@ ListenerImpl::ListenerImpl(const envoy::config::listener::v3alpha::Listener& con if (udp_config.udp_listener_name().empty()) { udp_config.set_udp_listener_name(UdpListenerNames::get().RawUdp); } - auto& config_factory = Config::Utility::getAndCheckFactory( - udp_config.udp_listener_name()); + auto& config_factory = + Config::Utility::getAndCheckFactoryByName( + udp_config.udp_listener_name()); ProtobufTypes::MessagePtr message = Config::Utility::translateToFactoryConfig(udp_config, validation_visitor_, config_factory); udp_listener_factory_ = config_factory.createActiveUdpListenerFactory(*message); @@ -250,7 +251,7 @@ ListenerImpl::ListenerImpl(const envoy::config::listener::v3alpha::Listener& con // Add original dst listener filter if 'use_original_dst' flag is set. if (PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, hidden_envoy_deprecated_use_original_dst, false)) { auto& factory = - Config::Utility::getAndCheckFactory( + Config::Utility::getAndCheckFactoryByName( Extensions::ListenerFilters::ListenerFilterNames::get().OriginalDst); listener_filter_factories_.push_back( factory.createFilterFactoryFromProto(Envoy::ProtobufWkt::Empty(), *this)); @@ -261,7 +262,7 @@ ListenerImpl::ListenerImpl(const envoy::config::listener::v3alpha::Listener& con // selected. if (PROTOBUF_GET_WRAPPED_OR_DEFAULT(config.filter_chains()[0], use_proxy_proto, false)) { auto& factory = - Config::Utility::getAndCheckFactory( + Config::Utility::getAndCheckFactoryByName( Extensions::ListenerFilters::ListenerFilterNames::get().ProxyProtocol); listener_filter_factories_.push_back( factory.createFilterFactoryFromProto(Envoy::ProtobufWkt::Empty(), *this)); @@ -291,7 +292,7 @@ ListenerImpl::ListenerImpl(const envoy::config::listener::v3alpha::Listener& con ENVOY_LOG(warn, "{}", message); auto& factory = - Config::Utility::getAndCheckFactory( + Config::Utility::getAndCheckFactoryByName( Extensions::ListenerFilters::ListenerFilterNames::get().TlsInspector); listener_filter_factories_.push_back( factory.createFilterFactoryFromProto(Envoy::ProtobufWkt::Empty(), *this)); diff --git a/source/server/listener_manager_impl.cc b/source/server/listener_manager_impl.cc index 72cfff34ee80..23007cfc7661 100644 --- a/source/server/listener_manager_impl.cc +++ b/source/server/listener_manager_impl.cc @@ -87,9 +87,8 @@ std::vector ProdListenerComponentFactory::createNetwor std::vector ret; for (ssize_t i = 0; i < filters.size(); i++) { const auto& proto_config = filters[i]; - const std::string& string_name = proto_config.name(); ENVOY_LOG(debug, " filter #{}:", i); - ENVOY_LOG(debug, " name: {}", string_name); + ENVOY_LOG(debug, " name: {}", proto_config.name()); ENVOY_LOG( debug, " config: {}", MessageUtil::getJsonStringFromMessage(proto_config.hidden_envoy_deprecated_config(), true)); @@ -97,7 +96,7 @@ std::vector ProdListenerComponentFactory::createNetwor // Now see if there is a factory that will accept the config. auto& factory = Config::Utility::getAndCheckFactory( - string_name); + proto_config); Config::Utility::validateTerminalFilters(filters[i].name(), "network", factory.isTerminalFilter(), i == filters.size() - 1); @@ -117,9 +116,8 @@ ProdListenerComponentFactory::createListenerFilterFactoryList_( std::vector ret; for (ssize_t i = 0; i < filters.size(); i++) { const auto& proto_config = filters[i]; - const std::string& string_name = proto_config.name(); ENVOY_LOG(debug, " filter #{}:", i); - ENVOY_LOG(debug, " name: {}", string_name); + ENVOY_LOG(debug, " name: {}", proto_config.name()); ENVOY_LOG( debug, " config: {}", MessageUtil::getJsonStringFromMessage(proto_config.hidden_envoy_deprecated_config(), true)); @@ -127,7 +125,7 @@ ProdListenerComponentFactory::createListenerFilterFactoryList_( // Now see if there is a factory that will accept the config. auto& factory = Config::Utility::getAndCheckFactory( - string_name); + proto_config); auto message = Config::Utility::translateToFactoryConfig( proto_config, context.messageValidationVisitor(), factory); ret.push_back(factory.createFilterFactoryFromProto(*message, context)); @@ -142,9 +140,8 @@ ProdListenerComponentFactory::createUdpListenerFilterFactoryList_( std::vector ret; for (ssize_t i = 0; i < filters.size(); i++) { const auto& proto_config = filters[i]; - const std::string& string_name = proto_config.name(); ENVOY_LOG(debug, " filter #{}:", i); - ENVOY_LOG(debug, " name: {}", string_name); + ENVOY_LOG(debug, " name: {}", proto_config.name()); ENVOY_LOG( debug, " config: {}", MessageUtil::getJsonStringFromMessage(proto_config.hidden_envoy_deprecated_config(), true)); @@ -152,7 +149,7 @@ ProdListenerComponentFactory::createUdpListenerFilterFactoryList_( // Now see if there is a factory that will accept the config. auto& factory = Config::Utility::getAndCheckFactory( - string_name); + proto_config); auto message = Config::Utility::translateToFactoryConfig( proto_config, context.messageValidationVisitor(), factory); @@ -770,7 +767,7 @@ std::unique_ptr ListenerFilterChainFactoryBuilder::buildFi } auto& config_factory = Config::Utility::getAndCheckFactory< - Server::Configuration::DownstreamTransportSocketConfigFactory>(transport_socket.name()); + Server::Configuration::DownstreamTransportSocketConfigFactory>(transport_socket); ProtobufTypes::MessagePtr message = Config::Utility::translateToFactoryConfig( transport_socket, parent_.messageValidationVisitor(), config_factory); diff --git a/source/server/overload_manager_impl.cc b/source/server/overload_manager_impl.cc index 80fa2b85c714..dc2bd75cdebc 100644 --- a/source/server/overload_manager_impl.cc +++ b/source/server/overload_manager_impl.cc @@ -109,7 +109,7 @@ OverloadManagerImpl::OverloadManagerImpl( const auto& name = resource.name(); ENVOY_LOG(debug, "Adding resource monitor for {}", name); auto& factory = - Config::Utility::getAndCheckFactory(name); + Config::Utility::getAndCheckFactory(resource); auto config = Config::Utility::translateToFactoryConfig(resource, validation_visitor, factory); auto monitor = factory.createResourceMonitor(*config, context); diff --git a/source/server/server.cc b/source/server/server.cc index 8001cff962c6..2abf405e94ac 100644 --- a/source/server/server.cc +++ b/source/server/server.cc @@ -368,7 +368,7 @@ void InstanceImpl::initialize(const Options& options, hooks.onRuntimeCreated(); // Once we have runtime we can initialize the SSL context manager. - ssl_context_manager_ = createContextManager(Ssl::ContextManagerFactory::name(), time_source_); + ssl_context_manager_ = createContextManager("ssl_context_manager", time_source_); const bool use_tcp_for_dns_lookups = bootstrap_.use_tcp_for_dns_lookups(); dns_resolver_ = dispatcher_->createDnsResolver({}, use_tcp_for_dns_lookups); diff --git a/test/common/config/BUILD b/test/common/config/BUILD index 1012479e11fa..125e1a749c67 100644 --- a/test/common/config/BUILD +++ b/test/common/config/BUILD @@ -334,6 +334,7 @@ envoy_cc_test( name = "registry_test", srcs = ["registry_test.cc"], deps = [ + "//include/envoy/config:typed_config_interface", "//test/test_common:logging_lib", "//test/test_common:utility_lib", ], diff --git a/test/common/config/metadata_test.cc b/test/common/config/metadata_test.cc index 0116a834c435..fda68f4e363a 100644 --- a/test/common/config/metadata_test.cc +++ b/test/common/config/metadata_test.cc @@ -62,7 +62,7 @@ class TypedMetadataTest : public testing::Test { class FooFactory : public TypedMetadataFactory { public: - const std::string name() const override { return "foo"; } + std::string name() const override { return "foo"; } // Throws EnvoyException (conversion failure) if d is empty. std::unique_ptr parse(const ProtobufWkt::Struct& d) const override { diff --git a/test/common/config/registry_test.cc b/test/common/config/registry_test.cc index 3b951e561222..287b3c49e20a 100644 --- a/test/common/config/registry_test.cc +++ b/test/common/config/registry_test.cc @@ -1,5 +1,6 @@ #include +#include "envoy/config/typed_config.h" #include "envoy/registry/registry.h" #include "common/common/fmt.h" @@ -13,15 +14,15 @@ namespace Envoy { namespace Config { namespace { -class InternalFactory { +class InternalFactory : public Config::UntypedFactory { public: virtual ~InternalFactory() = default; - virtual std::string name() PURE; + std::string category() const override { return ""; } }; class TestInternalFactory : public InternalFactory { public: - std::string name() override { return "testing.internal.test"; } + std::string name() const override { return "testing.internal.test"; } }; static Registry::RegisterInternalFactory @@ -46,16 +47,15 @@ TEST(RegistryTest, InternalFactoryNotPublished) { nullptr); } -class PublishedFactory { +class PublishedFactory : public Config::UntypedFactory { public: virtual ~PublishedFactory() = default; - virtual std::string name() PURE; - static std::string category() { return "testing.published"; } + std::string category() const override { return "testing.published"; } }; class TestPublishedFactory : public PublishedFactory { public: - std::string name() override { return "testing.published.test"; } + std::string name() const override { return "testing.published.test"; } }; REGISTER_FACTORY(TestPublishedFactory, PublishedFactory); @@ -77,7 +77,7 @@ TEST(RegistryTest, DefaultFactoryPublished) { class TestWithDeprecatedPublishedFactory : public PublishedFactory { public: - std::string name() override { return "testing.published.instead_name"; } + std::string name() const override { return "testing.published.instead_name"; } }; REGISTER_FACTORY(TestWithDeprecatedPublishedFactory, diff --git a/test/common/router/config_impl_test.cc b/test/common/router/config_impl_test.cc index cb87c41e5c5c..19ae87f7d39c 100644 --- a/test/common/router/config_impl_test.cc +++ b/test/common/router/config_impl_test.cc @@ -4073,7 +4073,7 @@ struct Baz : public Envoy::Config::TypedMetadata::Object { }; class BazFactory : public HttpRouteTypedMetadataFactory { public: - const std::string name() const override { return "baz"; } + std::string name() const override { return "baz"; } // Returns nullptr (conversion failure) if d is empty. std::unique_ptr parse(const ProtobufWkt::Struct& d) const override { diff --git a/test/common/upstream/cluster_manager_impl_test.cc b/test/common/upstream/cluster_manager_impl_test.cc index 08033201e142..2f0e66124d15 100644 --- a/test/common/upstream/cluster_manager_impl_test.cc +++ b/test/common/upstream/cluster_manager_impl_test.cc @@ -2736,7 +2736,7 @@ class TestUpstreamNetworkFilterConfigFactory ProtobufTypes::MessagePtr createEmptyConfigProto() override { return std::make_unique(); } - std::string name() override { return "envoy.test.filter"; } + std::string name() const override { return "envoy.test.filter"; } }; // Verify that configured upstream filters are added to client connections. diff --git a/test/common/upstream/upstream_impl_test.cc b/test/common/upstream/upstream_impl_test.cc index cbd286df1efb..702fb0b7e0e7 100644 --- a/test/common/upstream/upstream_impl_test.cc +++ b/test/common/upstream/upstream_impl_test.cc @@ -1869,7 +1869,7 @@ struct Baz : public Envoy::Config::TypedMetadata::Object { class BazFactory : public ClusterTypedMetadataFactory { public: - const std::string name() const override { return "baz"; } + std::string name() const override { return "baz"; } // Returns nullptr (conversion failure) if d is empty. std::unique_ptr parse(const ProtobufWkt::Struct& d) const override { @@ -2135,7 +2135,8 @@ class TestNetworkFilterConfigFactory ProtobufMessage::ValidationVisitor&) override { return parent_.createProtocolOptionsConfig(msg); } - std::string name() override { CONSTRUCT_ON_FIRST_USE(std::string, "envoy.test.filter"); } + std::string name() const override { CONSTRUCT_ON_FIRST_USE(std::string, "envoy.test.filter"); } + std::string configType() override { return ""; }; TestFilterConfigFactoryBase& parent_; }; @@ -2169,7 +2170,8 @@ class TestHttpFilterConfigFactory : public Server::Configuration::NamedHttpFilte ProtobufMessage::ValidationVisitor&) override { return parent_.createProtocolOptionsConfig(msg); } - std::string name() override { CONSTRUCT_ON_FIRST_USE(std::string, "envoy.test.filter"); } + std::string name() const override { CONSTRUCT_ON_FIRST_USE(std::string, "envoy.test.filter"); } + std::string configType() override { return ""; }; TestFilterConfigFactoryBase& parent_; }; diff --git a/test/extensions/common/wasm/wasm_vm_test.cc b/test/extensions/common/wasm/wasm_vm_test.cc index 1584406c8909..853174bc7fe3 100644 --- a/test/extensions/common/wasm/wasm_vm_test.cc +++ b/test/extensions/common/wasm/wasm_vm_test.cc @@ -30,7 +30,7 @@ class PluginFactory : public Null::NullVmPluginFactory { public: PluginFactory() = default; - const std::string name() const override { return "test_null_vm_plugin"; } + std::string name() const override { return "test_null_vm_plugin"; } std::unique_ptr create() const override; }; diff --git a/test/extensions/filters/network/dubbo_proxy/mocks.h b/test/extensions/filters/network/dubbo_proxy/mocks.h index dbe59849c523..557b40f557da 100644 --- a/test/extensions/filters/network/dubbo_proxy/mocks.h +++ b/test/extensions/filters/network/dubbo_proxy/mocks.h @@ -125,7 +125,7 @@ class MockNamedSerializerConfigFactory : public NamedSerializerConfigFactory { MockNamedSerializerConfigFactory(std::function f) : f_(f) {} SerializerPtr createSerializer() override { return SerializerPtr{f_()}; } - std::string name() override { + std::string name() const override { return SerializerNames::get().fromType(SerializationType::Hessian2); } @@ -141,7 +141,7 @@ class MockNamedProtocolConfigFactory : public NamedProtocolConfigFactory { protocol->initSerializer(serialization_type); return protocol; } - std::string name() override { return ProtocolNames::get().fromType(ProtocolType::Dubbo); } + std::string name() const override { return ProtocolNames::get().fromType(ProtocolType::Dubbo); } std::function f_; }; @@ -287,7 +287,7 @@ template class MockFactoryBase : public NamedDubboFilterConf return std::make_unique(); } - std::string name() override { return name_; } + std::string name() const override { return name_; } protected: MockFactoryBase(const std::string& name) : name_(name) {} diff --git a/test/extensions/filters/network/dubbo_proxy/router_test.cc b/test/extensions/filters/network/dubbo_proxy/router_test.cc index e37c9f12bbb9..13796ab9fead 100644 --- a/test/extensions/filters/network/dubbo_proxy/router_test.cc +++ b/test/extensions/filters/network/dubbo_proxy/router_test.cc @@ -35,7 +35,7 @@ class TestNamedSerializerConfigFactory : public NamedSerializerConfigFactory { TestNamedSerializerConfigFactory(std::function f) : f_(f) {} SerializerPtr createSerializer() override { return SerializerPtr{f_()}; } - std::string name() override { + std::string name() const override { return SerializerNames::get().fromType(SerializationType::Hessian2); } @@ -51,7 +51,7 @@ class TestNamedProtocolConfigFactory : public NamedProtocolConfigFactory { protocol->initSerializer(serialization_type); return protocol; } - std::string name() override { return ProtocolNames::get().fromType(ProtocolType::Dubbo); } + std::string name() const override { return ProtocolNames::get().fromType(ProtocolType::Dubbo); } std::function f_; }; diff --git a/test/extensions/filters/network/thrift_proxy/router_test.cc b/test/extensions/filters/network/thrift_proxy/router_test.cc index ef7a4ba6f843..3b094f1ad344 100644 --- a/test/extensions/filters/network/thrift_proxy/router_test.cc +++ b/test/extensions/filters/network/thrift_proxy/router_test.cc @@ -43,7 +43,7 @@ class TestNamedTransportConfigFactory : public NamedTransportConfigFactory { TestNamedTransportConfigFactory(std::function f) : f_(f) {} TransportPtr createTransport() override { return TransportPtr{f_()}; } - std::string name() override { return TransportNames::get().FRAMED; } + std::string name() const override { return TransportNames::get().FRAMED; } std::function f_; }; @@ -53,7 +53,7 @@ class TestNamedProtocolConfigFactory : public NamedProtocolConfigFactory { TestNamedProtocolConfigFactory(std::function f) : f_(f) {} ProtocolPtr createProtocol() override { return ProtocolPtr{f_()}; } - std::string name() override { return ProtocolNames::get().BINARY; } + std::string name() const override { return ProtocolNames::get().BINARY; } std::function f_; }; diff --git a/test/extensions/quic_listeners/quiche/active_quic_listener_config_test.cc b/test/extensions/quic_listeners/quiche/active_quic_listener_config_test.cc index 641eb5409ee4..ca2699a1e721 100644 --- a/test/extensions/quic_listeners/quiche/active_quic_listener_config_test.cc +++ b/test/extensions/quic_listeners/quiche/active_quic_listener_config_test.cc @@ -20,7 +20,8 @@ class ActiveQuicListenerFactoryPeer { TEST(ActiveQuicListenerConfigTest, CreateActiveQuicListenerFactory) { std::string listener_name = QuicListenerName; auto& config_factory = - Config::Utility::getAndCheckFactory(listener_name); + Config::Utility::getAndCheckFactoryByName( + listener_name); ProtobufTypes::MessagePtr config = config_factory.createEmptyConfigProto(); std::string yaml = R"EOF( diff --git a/test/extensions/transport_sockets/tls/test_private_key_method_provider.h b/test/extensions/transport_sockets/tls/test_private_key_method_provider.h index 44fb2271b718..d295be8f0a6a 100644 --- a/test/extensions/transport_sockets/tls/test_private_key_method_provider.h +++ b/test/extensions/transport_sockets/tls/test_private_key_method_provider.h @@ -89,7 +89,7 @@ class TestPrivateKeyMethodFactory : public Ssl::PrivateKeyMethodProviderInstance return std::make_shared(config.typed_config(), factory_context); } - std::string name() const override { return std::string("test"); }; + std::string name() const override { return "test"; }; }; } // namespace PrivateKeyMethodProvider diff --git a/test/integration/cluster_filter_integration_test.cc b/test/integration/cluster_filter_integration_test.cc index ebce95d0121b..667088230501 100644 --- a/test/integration/cluster_filter_integration_test.cc +++ b/test/integration/cluster_filter_integration_test.cc @@ -70,7 +70,7 @@ class PoliteFilterConfigFactory return std::make_unique(); } - std::string name() override { return "envoy.upstream.polite"; } + std::string name() const override { return "envoy.upstream.polite"; } }; // perform static registration diff --git a/test/integration/filter_manager_integration_test.h b/test/integration/filter_manager_integration_test.h index 9e1f90567047..e6966b85729e 100644 --- a/test/integration/filter_manager_integration_test.h +++ b/test/integration/filter_manager_integration_test.h @@ -256,7 +256,7 @@ class DispenserFilterConfigFactory : public Server::Configuration::NamedNetworkF return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Empty()}; } - std::string name() override { return name_; } + std::string name() const override { return name_; } private: const std::string name_; diff --git a/test/integration/tcp_conn_pool_integration_test.cc b/test/integration/tcp_conn_pool_integration_test.cc index e481799f3814..3bf48355b00a 100644 --- a/test/integration/tcp_conn_pool_integration_test.cc +++ b/test/integration/tcp_conn_pool_integration_test.cc @@ -97,7 +97,7 @@ class TestFilterConfigFactory : public Server::Configuration::NamedNetworkFilter return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Empty()}; } - std::string name() override { CONSTRUCT_ON_FIRST_USE(std::string, "envoy.test.router"); } + std::string name() const override { CONSTRUCT_ON_FIRST_USE(std::string, "envoy.test.router"); } bool isTerminalFilter() override { return true; } }; diff --git a/test/integration/test_host_predicate_config.h b/test/integration/test_host_predicate_config.h index 06b6dd576f7f..dc4bbf89802a 100644 --- a/test/integration/test_host_predicate_config.h +++ b/test/integration/test_host_predicate_config.h @@ -9,7 +9,7 @@ namespace Envoy { class TestHostPredicateFactory : public Upstream::RetryHostPredicateFactory { public: - std::string name() override { return "envoy.test_host_predicate"; } + std::string name() const override { return "envoy.test_host_predicate"; } Upstream::RetryHostPredicateSharedPtr createHostPredicate(const Protobuf::Message&, uint32_t) override { diff --git a/test/mocks/upstream/mocks.h b/test/mocks/upstream/mocks.h index bd0cf5735109..684d36ea0fc2 100644 --- a/test/mocks/upstream/mocks.h +++ b/test/mocks/upstream/mocks.h @@ -423,7 +423,7 @@ class TestRetryHostPredicateFactory : public RetryHostPredicateFactory { return std::make_shared>(); } - std::string name() override { return "envoy.test_host_predicate"; } + std::string name() const override { return "envoy.test_host_predicate"; } ProtobufTypes::MessagePtr createEmptyConfigProto() override { return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Empty()}; } diff --git a/test/server/BUILD b/test/server/BUILD index 38e8c276b8ef..239a099bd6cf 100644 --- a/test/server/BUILD +++ b/test/server/BUILD @@ -127,6 +127,7 @@ envoy_cc_test( name = "options_impl_test", srcs = ["options_impl_test.cc"], deps = [ + "//include/envoy/config:typed_config_interface", "//source/common/common:utility_lib", "//source/common/stats:stats_lib", "//source/server:options_lib", diff --git a/test/server/connection_handler_test.cc b/test/server/connection_handler_test.cc index e711e184062b..fc6ef77cf362 100644 --- a/test/server/connection_handler_test.cc +++ b/test/server/connection_handler_test.cc @@ -61,7 +61,7 @@ class ConnectionHandlerTest : public testing::Test, protected Logger::Loggable(listener_name) + Config::Utility::getAndCheckFactoryByName(listener_name) .createActiveUdpListenerFactory(dummy); ON_CALL(*socket_, socketType()).WillByDefault(Return(socket_type)); } diff --git a/test/server/listener_manager_impl_test.cc b/test/server/listener_manager_impl_test.cc index 49367e87b08b..085bc1bf4ba1 100644 --- a/test/server/listener_manager_impl_test.cc +++ b/test/server/listener_manager_impl_test.cc @@ -340,7 +340,7 @@ class NonTerminalFilterFactory : public Configuration::NamedNetworkFilterConfigF return std::make_unique(); } - std::string name() override { return "non_terminal"; } + std::string name() const override { return "non_terminal"; } }; TEST_F(ListenerManagerImplWithRealFiltersTest, TerminalNotLast) { @@ -413,7 +413,7 @@ class TestStatsConfigFactory : public Configuration::NamedNetworkFilterConfigFac return std::make_unique(); } - std::string name() override { return "stats_test"; } + std::string name() const override { return "stats_test"; } bool isTerminalFilter() override { return true; } private: @@ -3158,7 +3158,7 @@ TEST_F(ListenerManagerImplWithRealFiltersTest, OriginalDstTestFilter) { return std::make_unique(); } - std::string name() override { return "test.listener.original_dst"; } + std::string name() const override { return "test.listener.original_dst"; } }; /** @@ -3232,7 +3232,7 @@ TEST_F(ListenerManagerImplWithRealFiltersTest, OriginalDstTestFilterIPv6) { return std::make_unique(); } - std::string name() override { return "test.listener.original_dstipv6"; } + std::string name() const override { return "test.listener.original_dstipv6"; } }; /** diff --git a/test/server/options_impl_test.cc b/test/server/options_impl_test.cc index 80efeed3140c..c231cee15ef1 100644 --- a/test/server/options_impl_test.cc +++ b/test/server/options_impl_test.cc @@ -8,6 +8,7 @@ #include "envoy/admin/v3alpha/server_info.pb.h" #include "envoy/common/exception.h" #include "envoy/config/bootstrap/v3alpha/bootstrap.pb.h" +#include "envoy/config/typed_config.h" #include "common/common/utility.h" @@ -450,28 +451,26 @@ TEST_F(OptionsImplPlatformLinuxTest, AffinityTest4) { #endif -class TestFactory { +class TestFactory : public Config::UntypedFactory { public: virtual ~TestFactory() = default; - virtual std::string name() PURE; - static std::string category() { return "test"; } + std::string category() const override { return "test"; } }; class TestTestFactory : public TestFactory { public: - std::string name() override { return "test"; } + std::string name() const override { return "test"; } }; -class TestingFactory { +class TestingFactory : public Config::UntypedFactory { public: virtual ~TestingFactory() = default; - virtual std::string name() PURE; - static std::string category() { return "testing"; } + std::string category() const override { return "testing"; } }; class TestTestingFactory : public TestingFactory { public: - std::string name() override { return "test"; } + std::string name() const override { return "test"; } }; REGISTER_FACTORY(TestTestFactory, TestFactory){"test-1", "test-2"}; diff --git a/test/server/server_test.cc b/test/server/server_test.cc index 4f8fd1ff9c9f..464ef9a24659 100644 --- a/test/server/server_test.cc +++ b/test/server/server_test.cc @@ -268,7 +268,7 @@ class CustomStatsSinkFactory : public Server::Configuration::StatsSinkFactory { return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Empty()}; } - std::string name() override { return "envoy.custom_stats_sink"; } + std::string name() const override { return "envoy.custom_stats_sink"; } }; INSTANTIATE_TEST_SUITE_P(IpVersions, ServerInstanceImplTest, @@ -993,7 +993,7 @@ class CallbacksStatsSinkFactory : public Server::Configuration::StatsSinkFactory return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Empty()}; } - std::string name() override { return "envoy.callbacks_stats_sink"; } + std::string name() const override { return "envoy.callbacks_stats_sink"; } }; REGISTER_FACTORY(CallbacksStatsSinkFactory, Server::Configuration::StatsSinkFactory); diff --git a/test/test_common/registry.h b/test/test_common/registry.h index 6c58095594dc..ccbbac80ef66 100644 --- a/test/test_common/registry.h +++ b/test/test_common/registry.h @@ -15,7 +15,7 @@ namespace Registry { template class InjectFactory { public: InjectFactory(Base& instance) : instance_(instance) { - EXPECT_STRNE(Base::category().c_str(), ""); + EXPECT_STRNE(instance.category().c_str(), ""); displaced_ = Registry::FactoryRegistry::replaceFactoryForTest(instance_); }