From 51513a7a10c6d345594a800fd28ef49d633ab4d5 Mon Sep 17 00:00:00 2001 From: Auni Ahsan Date: Sat, 13 Feb 2021 14:41:36 +0000 Subject: [PATCH 1/7] Add FilterDependencies to base http filter factory interface Signed-off-by: Auni Ahsan --- include/envoy/server/BUILD | 1 + include/envoy/server/filter_config.h | 10 ++++++++++ test/server/filter_config_test.cc | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/envoy/server/BUILD b/include/envoy/server/BUILD index 8f0d6691103d..6ffc35a3ffe2 100644 --- a/include/envoy/server/BUILD +++ b/include/envoy/server/BUILD @@ -220,6 +220,7 @@ envoy_cc_library( "//source/common/common:assert_lib", "//source/common/common:macros", "//source/common/protobuf", + "@envoy_api//envoy/extensions/filters/common/dependency/v3:pkg_cc_proto", ], ) diff --git a/include/envoy/server/filter_config.h b/include/envoy/server/filter_config.h index 97b2b3fe51b0..201c9516717b 100644 --- a/include/envoy/server/filter_config.h +++ b/include/envoy/server/filter_config.h @@ -8,6 +8,7 @@ #include "envoy/network/filter.h" #include "envoy/server/drain_manager.h" #include "envoy/server/factory_context.h" +#include "envoy/extensions/filters/common/dependency/v3/dependency.pb.h" #include "common/common/assert.h" #include "common/common/macros.h" @@ -201,6 +202,15 @@ class NamedHttpFilterConfigFactory : public ProtocolOptionsFactory { * @return bool true if this filter must be the last filter in a filter chain, false otherwise. */ virtual bool isTerminalFilter() { return false; } + + /** + * @return FilterDependencies specification of dependencies required or + * provided on the decode and encode paths. + */ + virtual envoy::extensions::filters::common::dependency::v3::FilterDependencies dependencies() { + envoy::extensions::filters::common::dependency::v3::FilterDependencies dependency; + return dependency; + } }; } // namespace Configuration diff --git a/test/server/filter_config_test.cc b/test/server/filter_config_test.cc index b8ddc9e063bf..c4ac3ed323c9 100644 --- a/test/server/filter_config_test.cc +++ b/test/server/filter_config_test.cc @@ -10,6 +10,9 @@ namespace Envoy { namespace { +using envoy::extensions::filters::common::dependency::v3::Dependency; +using envoy::extensions::filters::common::dependency::v3::FilterDependencies; + class TestHttpFilterConfigFactory : public Server::Configuration::NamedHttpFilterConfigFactory { public: TestHttpFilterConfigFactory() = default; @@ -25,6 +28,14 @@ class TestHttpFilterConfigFactory : public Server::Configuration::NamedHttpFilte ProtobufTypes::MessagePtr createEmptyConfigProto() override { return nullptr; } ProtobufTypes::MessagePtr createEmptyProtocolOptionsProto() override { return nullptr; } + FilterDependencies dependencies() override { + FilterDependencies dependencies; + Dependency* d = dependencies.add_decode_required(); + d->set_name("foobar"); + d->set_type(Dependency::FILTER_STATE_KEY); + return dependencies; + } + std::string name() const override { return "envoy.test.http_filter"; } std::string configType() override { return ""; }; }; @@ -38,5 +49,16 @@ TEST(NamedHttpFilterConfigFactoryTest, CreateFilterFactory) { factory.createFilterFactoryFromProto(*message, stats_prefix, context); } +TEST(NamedHttpFilterConfigFactoryTest, Dependencies) { + TestHttpFilterConfigFactory factory; + const std::string stats_prefix = "foo"; + Server::Configuration::MockFactoryContext context; + ProtobufTypes::MessagePtr message{new Envoy::ProtobufWkt::Struct()}; + + factory.createFilterFactoryFromProto(*message, stats_prefix, context); + + EXPECT_EQ(factory.dependencies().decode_required().size(), 1); +} + } // namespace } // namespace Envoy From ec1d1e4009ac163be3764bd35cf342714b90632c Mon Sep 17 00:00:00 2001 From: Auni Ahsan Date: Tue, 23 Feb 2021 19:30:08 +0000 Subject: [PATCH 2/7] Add docs Signed-off-by: Auni Ahsan --- docs/root/version_history/current.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/root/version_history/current.rst b/docs/root/version_history/current.rst index 24f8dbfd20cb..f10043db081f 100644 --- a/docs/root/version_history/current.rst +++ b/docs/root/version_history/current.rst @@ -93,6 +93,7 @@ New Features * http: added support for `Envoy::ScopeTrackedObject` for HTTP/1 and HTTP/2 dispatching. Crashes while inside the dispatching loop should dump debug information. * http: added support for :ref:`preconnecting `. Preconnecting is off by default, but recommended for clusters serving latency-sensitive traffic, especially if using HTTP/1.1. * http: change frame flood and abuse checks to the upstream HTTP/2 codec to ON by default. It can be disabled by setting the `envoy.reloadable_features.upstream_http2_flood_checks` runtime key to false. +* http filter: add function to `NamedHttpFilterConfigFactory` which can be overridden to return a :ref`FilterDependencies ` specification. Config-plane validation of dependencies is currently WIP. * json: introduced new JSON parser (https://github.com/nlohmann/json) to replace RapidJSON. The new parser is disabled by default. To test the new RapidJSON parser, enable the runtime feature `envoy.reloadable_features.remove_legacy_json`. * original_dst: added support for :ref:`Original Destination ` on Windows. This enables the use of Envoy as a sidecar proxy on Windows. * overload: add support for scaling :ref:`transport connection timeouts`. This can be used to reduce the TLS handshake timeout in response to overload. From 80f3d200eacbe787dbddd04c598d566eff0e9e12 Mon Sep 17 00:00:00 2001 From: Auni Ahsan Date: Tue, 23 Feb 2021 20:09:12 +0000 Subject: [PATCH 3/7] fix format Signed-off-by: Auni Ahsan --- include/envoy/server/filter_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/envoy/server/filter_config.h b/include/envoy/server/filter_config.h index 201c9516717b..f6b3f5cac138 100644 --- a/include/envoy/server/filter_config.h +++ b/include/envoy/server/filter_config.h @@ -3,12 +3,12 @@ #include #include "envoy/config/typed_config.h" +#include "envoy/extensions/filters/common/dependency/v3/dependency.pb.h" #include "envoy/http/filter.h" #include "envoy/init/manager.h" #include "envoy/network/filter.h" #include "envoy/server/drain_manager.h" #include "envoy/server/factory_context.h" -#include "envoy/extensions/filters/common/dependency/v3/dependency.pb.h" #include "common/common/assert.h" #include "common/common/macros.h" From 91364e71fdd2287b727b9c4fec42d6dd845b2196 Mon Sep 17 00:00:00 2001 From: Auni Ahsan Date: Wed, 24 Feb 2021 19:06:41 +0000 Subject: [PATCH 4/7] Revert "Add docs" This reverts commit ec1d1e4009ac163be3764bd35cf342714b90632c. Signed-off-by: Auni Ahsan --- docs/root/version_history/current.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/root/version_history/current.rst b/docs/root/version_history/current.rst index f10043db081f..24f8dbfd20cb 100644 --- a/docs/root/version_history/current.rst +++ b/docs/root/version_history/current.rst @@ -93,7 +93,6 @@ New Features * http: added support for `Envoy::ScopeTrackedObject` for HTTP/1 and HTTP/2 dispatching. Crashes while inside the dispatching loop should dump debug information. * http: added support for :ref:`preconnecting `. Preconnecting is off by default, but recommended for clusters serving latency-sensitive traffic, especially if using HTTP/1.1. * http: change frame flood and abuse checks to the upstream HTTP/2 codec to ON by default. It can be disabled by setting the `envoy.reloadable_features.upstream_http2_flood_checks` runtime key to false. -* http filter: add function to `NamedHttpFilterConfigFactory` which can be overridden to return a :ref`FilterDependencies ` specification. Config-plane validation of dependencies is currently WIP. * json: introduced new JSON parser (https://github.com/nlohmann/json) to replace RapidJSON. The new parser is disabled by default. To test the new RapidJSON parser, enable the runtime feature `envoy.reloadable_features.remove_legacy_json`. * original_dst: added support for :ref:`Original Destination ` on Windows. This enables the use of Envoy as a sidecar proxy on Windows. * overload: add support for scaling :ref:`transport connection timeouts`. This can be used to reduce the TLS handshake timeout in response to overload. From 116922b4aac6f1be6d61e82d1082a651defc0b46 Mon Sep 17 00:00:00 2001 From: Auni Ahsan Date: Tue, 2 Mar 2021 18:18:52 +0000 Subject: [PATCH 5/7] change dependencies() call to unique ptr Signed-off-by: Auni Ahsan --- include/envoy/server/filter_config.h | 12 ++++++++---- test/server/filter_config_test.cc | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/envoy/server/filter_config.h b/include/envoy/server/filter_config.h index f6b3f5cac138..7f1c1b28b4c6 100644 --- a/include/envoy/server/filter_config.h +++ b/include/envoy/server/filter_config.h @@ -153,6 +153,9 @@ class NamedUpstreamNetworkFilterConfigFactory : public ProtocolOptionsFactory { std::string category() const override { return "envoy.filters.upstream_network"; } }; +using FilterDependenciesPtr = + std::unique_ptr; + /** * Implemented by each HTTP filter and registered via Registry::registerFactory or the * convenience class RegisterFactory. @@ -205,11 +208,12 @@ class NamedHttpFilterConfigFactory : public ProtocolOptionsFactory { /** * @return FilterDependencies specification of dependencies required or - * provided on the decode and encode paths. + * provided on the decode and encode paths. This function returns an empty + * filter dependencies specification by default, and can be overriden. */ - virtual envoy::extensions::filters::common::dependency::v3::FilterDependencies dependencies() { - envoy::extensions::filters::common::dependency::v3::FilterDependencies dependency; - return dependency; + virtual FilterDependenciesPtr dependencies() { + return std::make_unique< + envoy::extensions::filters::common::dependency::v3::FilterDependencies>(); } }; diff --git a/test/server/filter_config_test.cc b/test/server/filter_config_test.cc index c4ac3ed323c9..15e89c590020 100644 --- a/test/server/filter_config_test.cc +++ b/test/server/filter_config_test.cc @@ -8,6 +8,8 @@ #include "gtest/gtest.h" namespace Envoy { +namespace Server { +namespace Configuration { namespace { using envoy::extensions::filters::common::dependency::v3::Dependency; @@ -28,12 +30,12 @@ class TestHttpFilterConfigFactory : public Server::Configuration::NamedHttpFilte ProtobufTypes::MessagePtr createEmptyConfigProto() override { return nullptr; } ProtobufTypes::MessagePtr createEmptyProtocolOptionsProto() override { return nullptr; } - FilterDependencies dependencies() override { + FilterDependenciesPtr dependencies() override { FilterDependencies dependencies; Dependency* d = dependencies.add_decode_required(); d->set_name("foobar"); d->set_type(Dependency::FILTER_STATE_KEY); - return dependencies; + return std::make_unique(dependencies); } std::string name() const override { return "envoy.test.http_filter"; } @@ -57,8 +59,10 @@ TEST(NamedHttpFilterConfigFactoryTest, Dependencies) { factory.createFilterFactoryFromProto(*message, stats_prefix, context); - EXPECT_EQ(factory.dependencies().decode_required().size(), 1); + EXPECT_EQ(factory.dependencies()->decode_required().size(), 1); } } // namespace +} // namespace Configuration +} // namespace Server } // namespace Envoy From dcdb15ee13afb5cff43f4fcc4b23b154264cf073 Mon Sep 17 00:00:00 2001 From: Auni Ahsan Date: Tue, 2 Mar 2021 19:58:30 +0000 Subject: [PATCH 6/7] Fix typo Signed-off-by: Auni Ahsan --- include/envoy/server/filter_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/envoy/server/filter_config.h b/include/envoy/server/filter_config.h index 7f1c1b28b4c6..bb66424f6072 100644 --- a/include/envoy/server/filter_config.h +++ b/include/envoy/server/filter_config.h @@ -209,7 +209,7 @@ class NamedHttpFilterConfigFactory : public ProtocolOptionsFactory { /** * @return FilterDependencies specification of dependencies required or * provided on the decode and encode paths. This function returns an empty - * filter dependencies specification by default, and can be overriden. + * filter dependencies specification by default, and can be overridden. */ virtual FilterDependenciesPtr dependencies() { return std::make_unique< From fb8b464ef994e7eff9acf28e9a7d0f374f2bdf85 Mon Sep 17 00:00:00 2001 From: Auni Ahsan Date: Fri, 5 Mar 2021 14:32:51 +0000 Subject: [PATCH 7/7] Add ptr Signed-off-by: Auni Ahsan --- include/envoy/server/filter_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/envoy/server/filter_config.h b/include/envoy/server/filter_config.h index bb66424f6072..5260902f9753 100644 --- a/include/envoy/server/filter_config.h +++ b/include/envoy/server/filter_config.h @@ -207,7 +207,7 @@ class NamedHttpFilterConfigFactory : public ProtocolOptionsFactory { virtual bool isTerminalFilter() { return false; } /** - * @return FilterDependencies specification of dependencies required or + * @return FilterDependenciesPtr specification of dependencies required or * provided on the decode and encode paths. This function returns an empty * filter dependencies specification by default, and can be overridden. */