diff --git a/source/extensions/filters/http/tap/BUILD b/source/extensions/filters/http/tap/BUILD index 6955cf61c279b..7b72e3949d90b 100644 --- a/source/extensions/filters/http/tap/BUILD +++ b/source/extensions/filters/http/tap/BUILD @@ -60,6 +60,7 @@ envoy_cc_extension( ":tap_filter_lib", "//envoy/registry", "//source/extensions/filters/http/common:factory_base_lib", + "//source/server:generic_factory_context_lib", "@envoy_api//envoy/config/tap/v3:pkg_cc_proto", "@envoy_api//envoy/extensions/filters/http/tap/v3:pkg_cc_proto", ], diff --git a/source/extensions/filters/http/tap/config.cc b/source/extensions/filters/http/tap/config.cc index 7ea08fc4b1aff..9aa97140ec833 100644 --- a/source/extensions/filters/http/tap/config.cc +++ b/source/extensions/filters/http/tap/config.cc @@ -7,6 +7,7 @@ #include "source/extensions/filters/http/tap/tap_config_impl.h" #include "source/extensions/filters/http/tap/tap_filter.h" +#include "source/server/generic_factory_context.h" namespace Envoy { namespace Extensions { @@ -15,8 +16,9 @@ namespace TapFilter { class HttpTapConfigFactoryImpl : public Extensions::Common::Tap::TapConfigFactory { public: - HttpTapConfigFactoryImpl(Server::Configuration::FactoryContext& context) - : factory_context_(context) {} + HttpTapConfigFactoryImpl(Server::Configuration::ServerFactoryContext& context, + ProtobufMessage::ValidationVisitor& validation_visitor) + : factory_context_(context, validation_visitor) {} // TapConfigFactory Extensions::Common::Tap::TapConfigSharedPtr createConfigFromProto(const envoy::config::tap::v3::TapConfig& proto_config, @@ -26,18 +28,18 @@ class HttpTapConfigFactoryImpl : public Extensions::Common::Tap::TapConfigFactor } private: - Server::Configuration::FactoryContext& factory_context_; + Server::GenericFactoryContextImpl factory_context_; }; -absl::StatusOr TapFilterFactory::createFilterFactoryFromProtoTyped( +absl::StatusOr TapFilterFactory::createFilterFactory( const envoy::extensions::filters::http::tap::v3::Tap& proto_config, - const std::string& stats_prefix, Server::Configuration::FactoryContext& context) { - auto& server_context = context.serverFactoryContext(); - - FilterConfigSharedPtr filter_config(new FilterConfigImpl( - proto_config, stats_prefix, std::make_unique(context), - context.scope(), server_context.admin(), server_context.singletonManager(), - server_context.threadLocal(), server_context.mainThreadDispatcher())); + const std::string& stats_prefix, Server::Configuration::ServerFactoryContext& context, + Stats::Scope& scope, ProtobufMessage::ValidationVisitor& validation_visitor) { + FilterConfigSharedPtr filter_config( + new FilterConfigImpl(proto_config, stats_prefix, + std::make_unique(context, validation_visitor), + scope, context.admin(), context.singletonManager(), + context.threadLocal(), context.mainThreadDispatcher())); return [filter_config](Http::FilterChainFactoryCallbacks& callbacks) -> void { auto filter = std::make_shared(filter_config); callbacks.addStreamFilter(filter); @@ -45,6 +47,20 @@ absl::StatusOr TapFilterFactory::createFilterFactoryFromP }; } +absl::StatusOr TapFilterFactory::createFilterFactoryFromProtoTyped( + const envoy::extensions::filters::http::tap::v3::Tap& proto_config, + const std::string& stats_prefix, Server::Configuration::FactoryContext& context) { + return createFilterFactory(proto_config, stats_prefix, context.serverFactoryContext(), + context.scope(), context.messageValidationVisitor()); +} + +absl::StatusOr TapFilterFactory::createHttpFilterFactoryFromProtoTyped( + const envoy::extensions::filters::http::tap::v3::Tap& proto_config, + const std::string& stats_prefix, Server::Configuration::ServerFactoryContext& context) { + return createFilterFactory(proto_config, stats_prefix, context, context.scope(), + context.messageValidationVisitor()); +} + /** * Static registration for the tap filter. @see RegisterFactory. */ diff --git a/source/extensions/filters/http/tap/config.h b/source/extensions/filters/http/tap/config.h index 42ee6c532b28d..39d4723a7f10a 100644 --- a/source/extensions/filters/http/tap/config.h +++ b/source/extensions/filters/http/tap/config.h @@ -22,6 +22,18 @@ class TapFilterFactory absl::StatusOr createFilterFactoryFromProtoTyped( const envoy::extensions::filters::http::tap::v3::Tap& proto_config, const std::string& stats_prefix, Server::Configuration::FactoryContext& context) override; + absl::StatusOr createHttpFilterFactoryFromProtoTyped( + const envoy::extensions::filters::http::tap::v3::Tap& proto_config, + const std::string& stats_prefix, + Server::Configuration::ServerFactoryContext& context) override; + + // Shared factory creation used by both the downstream (FactoryContext) and route/vhost-level + // (ServerFactoryContext) paths. The FilterConfig stats are scoped to the given scope. + absl::StatusOr + createFilterFactory(const envoy::extensions::filters::http::tap::v3::Tap& proto_config, + const std::string& stats_prefix, + Server::Configuration::ServerFactoryContext& context, Stats::Scope& scope, + ProtobufMessage::ValidationVisitor& validation_visitor); }; } // namespace TapFilter diff --git a/source/extensions/filters/http/tap/tap_config_impl.cc b/source/extensions/filters/http/tap/tap_config_impl.cc index b021642327a68..5c3458343fa8f 100644 --- a/source/extensions/filters/http/tap/tap_config_impl.cc +++ b/source/extensions/filters/http/tap/tap_config_impl.cc @@ -31,7 +31,7 @@ fillHeaderList(Protobuf::RepeatedPtrField* HttpTapConfigImpl::HttpTapConfigImpl(const envoy::config::tap::v3::TapConfig& proto_config, Common::Tap::Sink* admin_streamer, - Server::Configuration::FactoryContext& context) + Server::Configuration::GenericFactoryContext& context) : TapCommon::TapConfigBaseImpl(std::move(proto_config), admin_streamer, context), time_source_(context.serverFactoryContext().mainThreadDispatcher().timeSource()) {} diff --git a/source/extensions/filters/http/tap/tap_config_impl.h b/source/extensions/filters/http/tap/tap_config_impl.h index e02f0da17b048..aced81058ca42 100644 --- a/source/extensions/filters/http/tap/tap_config_impl.h +++ b/source/extensions/filters/http/tap/tap_config_impl.h @@ -21,7 +21,7 @@ class HttpTapConfigImpl : public Extensions::Common::Tap::TapConfigBaseImpl, public: HttpTapConfigImpl(const envoy::config::tap::v3::TapConfig& proto_config, Extensions::Common::Tap::Sink* admin_streamer, - Server::Configuration::FactoryContext& context); + Server::Configuration::GenericFactoryContext& context); // TapFilter::HttpTapConfig HttpPerRequestTapperPtr