-
Notifications
You must be signed in to change notification settings - Fork 5.3k
listener: keep ListenerFactoryContext small #7528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2686,30 +2686,12 @@ class OriginalDstTestFilter : public Extensions::ListenerFilters::OriginalDst::O | |||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| TEST_F(ListenerManagerImplWithRealFiltersTest, OriginalDstTestFilter) { | ||||||||||||||||||||||
| // Static scope required for the io_handle to be in scope for the lambda below | ||||||||||||||||||||||
| // and for the final check at the end of this test. | ||||||||||||||||||||||
| static int fd; | ||||||||||||||||||||||
| fd = -1; | ||||||||||||||||||||||
| // temporary io_handle to test result of socket creation | ||||||||||||||||||||||
| Network::IoHandlePtr io_handle_tmp = std::make_unique<Network::IoSocketHandleImpl>(0); | ||||||||||||||||||||||
| EXPECT_CALL(*listener_factory_.socket_, ioHandle()).WillOnce(ReturnRef(*io_handle_tmp)); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class OriginalDstTestConfigFactory : public Configuration::NamedListenerFilterConfigFactory { | ||||||||||||||||||||||
| public: | ||||||||||||||||||||||
| // NamedListenerFilterConfigFactory | ||||||||||||||||||||||
| Network::ListenerFilterFactoryCb | ||||||||||||||||||||||
| createFilterFactoryFromProto(const Protobuf::Message&, | ||||||||||||||||||||||
| Configuration::ListenerFactoryContext& context) override { | ||||||||||||||||||||||
| auto option = std::make_unique<Network::MockSocketOption>(); | ||||||||||||||||||||||
| EXPECT_CALL(*option, setOption(_, envoy::api::v2::core::SocketOption::STATE_PREBIND)) | ||||||||||||||||||||||
| .WillOnce(Return(true)); | ||||||||||||||||||||||
| EXPECT_CALL(*option, setOption(_, envoy::api::v2::core::SocketOption::STATE_BOUND)) | ||||||||||||||||||||||
| .WillOnce(Invoke( | ||||||||||||||||||||||
| [](Network::Socket& socket, envoy::api::v2::core::SocketOption::SocketState) -> bool { | ||||||||||||||||||||||
| fd = socket.ioHandle().fd(); | ||||||||||||||||||||||
| return true; | ||||||||||||||||||||||
| })); | ||||||||||||||||||||||
| context.addListenSocketOption(std::move(option)); | ||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattklein123 The tricky test is verifying if BTW I think envoy/source/server/listener_manager_impl.cc Lines 208 to 217 in 1ca1d13
ListenerFactoryContext
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still concerned that people may have private listener filters that are using this and won't be able to now. Can you see who added the tests that you changed and ask them? |
||||||||||||||||||||||
| Configuration::ListenerFactoryContext&) override { | ||||||||||||||||||||||
| return [](Network::ListenerFilterManager& filter_manager) -> void { | ||||||||||||||||||||||
| filter_manager.addAcceptFilter(std::make_unique<OriginalDstTestFilter>()); | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
@@ -2767,57 +2749,6 @@ TEST_F(ListenerManagerImplWithRealFiltersTest, OriginalDstTestFilter) { | |||||||||||||||||||||
| EXPECT_TRUE(filterChainFactory.createListenerFilterChain(manager)); | ||||||||||||||||||||||
| EXPECT_TRUE(socket.localAddressRestored()); | ||||||||||||||||||||||
| EXPECT_EQ("127.0.0.2:2345", socket.localAddress()->asString()); | ||||||||||||||||||||||
| EXPECT_NE(fd, -1); | ||||||||||||||||||||||
| io_handle_tmp->close(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| TEST_F(ListenerManagerImplWithRealFiltersTest, OriginalDstTestFilterOptionFail) { | ||||||||||||||||||||||
| class OriginalDstTestConfigFactory : public Configuration::NamedListenerFilterConfigFactory { | ||||||||||||||||||||||
| public: | ||||||||||||||||||||||
| // NamedListenerFilterConfigFactory | ||||||||||||||||||||||
| Network::ListenerFilterFactoryCb | ||||||||||||||||||||||
| createFilterFactoryFromProto(const Protobuf::Message&, | ||||||||||||||||||||||
| Configuration::ListenerFactoryContext& context) override { | ||||||||||||||||||||||
| auto option = std::make_unique<Network::MockSocketOption>(); | ||||||||||||||||||||||
| EXPECT_CALL(*option, setOption(_, envoy::api::v2::core::SocketOption::STATE_PREBIND)) | ||||||||||||||||||||||
| .WillOnce(Return(false)); | ||||||||||||||||||||||
| context.addListenSocketOption(std::move(option)); | ||||||||||||||||||||||
| return [](Network::ListenerFilterManager& filter_manager) -> void { | ||||||||||||||||||||||
| filter_manager.addAcceptFilter(std::make_unique<OriginalDstTestFilter>()); | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ProtobufTypes::MessagePtr createEmptyConfigProto() override { | ||||||||||||||||||||||
| return std::make_unique<Envoy::ProtobufWkt::Empty>(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| std::string name() override { return "testfail.listener.original_dst"; } | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Static registration for the original dst filter. @see RegisterFactory. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| static Registry::RegisterFactory<OriginalDstTestConfigFactory, | ||||||||||||||||||||||
| Configuration::NamedListenerFilterConfigFactory> | ||||||||||||||||||||||
| registered_; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const std::string yaml = TestEnvironment::substitute(R"EOF( | ||||||||||||||||||||||
| name: "socketOptionFailListener" | ||||||||||||||||||||||
| address: | ||||||||||||||||||||||
| socket_address: { address: 127.0.0.1, port_value: 1111 } | ||||||||||||||||||||||
| filter_chains: {} | ||||||||||||||||||||||
| listener_filters: | ||||||||||||||||||||||
| - name: "testfail.listener.original_dst" | ||||||||||||||||||||||
| config: {} | ||||||||||||||||||||||
| )EOF", | ||||||||||||||||||||||
| Network::Address::IpVersion::v4); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| EXPECT_CALL(listener_factory_, createListenSocket(_, _, _, true)); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| EXPECT_THROW_WITH_MESSAGE(manager_->addOrUpdateListener(parseListenerFromV2Yaml(yaml), "", true), | ||||||||||||||||||||||
| EnvoyException, | ||||||||||||||||||||||
| "MockListenerComponentFactory: Setting socket options failed"); | ||||||||||||||||||||||
| EXPECT_EQ(0U, manager_->listeners().size()); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class OriginalDstTestFilterIPv6 | ||||||||||||||||||||||
|
|
@@ -2829,30 +2760,12 @@ class OriginalDstTestFilterIPv6 | |||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| TEST_F(ListenerManagerImplWithRealFiltersTest, OriginalDstTestFilterIPv6) { | ||||||||||||||||||||||
| // Static scope required for the io_handle to be in scope for the lambda below | ||||||||||||||||||||||
| // and for the final check at the end of this test. | ||||||||||||||||||||||
| static int fd; | ||||||||||||||||||||||
| fd = -1; | ||||||||||||||||||||||
| // temporary io_handle to test result of socket creation | ||||||||||||||||||||||
| Network::IoHandlePtr io_handle_tmp = std::make_unique<Network::IoSocketHandleImpl>(0); | ||||||||||||||||||||||
| EXPECT_CALL(*listener_factory_.socket_, ioHandle()).WillOnce(ReturnRef(*io_handle_tmp)); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class OriginalDstTestConfigFactory : public Configuration::NamedListenerFilterConfigFactory { | ||||||||||||||||||||||
| public: | ||||||||||||||||||||||
| // NamedListenerFilterConfigFactory | ||||||||||||||||||||||
| Network::ListenerFilterFactoryCb | ||||||||||||||||||||||
| createFilterFactoryFromProto(const Protobuf::Message&, | ||||||||||||||||||||||
| Configuration::ListenerFactoryContext& context) override { | ||||||||||||||||||||||
| auto option = std::make_unique<Network::MockSocketOption>(); | ||||||||||||||||||||||
| EXPECT_CALL(*option, setOption(_, envoy::api::v2::core::SocketOption::STATE_PREBIND)) | ||||||||||||||||||||||
| .WillOnce(Return(true)); | ||||||||||||||||||||||
| EXPECT_CALL(*option, setOption(_, envoy::api::v2::core::SocketOption::STATE_BOUND)) | ||||||||||||||||||||||
| .WillOnce(Invoke( | ||||||||||||||||||||||
| [](Network::Socket& socket, envoy::api::v2::core::SocketOption::SocketState) -> bool { | ||||||||||||||||||||||
| fd = socket.ioHandle().fd(); | ||||||||||||||||||||||
| return true; | ||||||||||||||||||||||
| })); | ||||||||||||||||||||||
| context.addListenSocketOption(std::move(option)); | ||||||||||||||||||||||
| Configuration::ListenerFactoryContext&) override { | ||||||||||||||||||||||
| return [](Network::ListenerFilterManager& filter_manager) -> void { | ||||||||||||||||||||||
| filter_manager.addAcceptFilter(std::make_unique<OriginalDstTestFilterIPv6>()); | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
@@ -2910,57 +2823,6 @@ TEST_F(ListenerManagerImplWithRealFiltersTest, OriginalDstTestFilterIPv6) { | |||||||||||||||||||||
| EXPECT_TRUE(filterChainFactory.createListenerFilterChain(manager)); | ||||||||||||||||||||||
| EXPECT_TRUE(socket.localAddressRestored()); | ||||||||||||||||||||||
| EXPECT_EQ("[1::2]:2345", socket.localAddress()->asString()); | ||||||||||||||||||||||
| EXPECT_NE(fd, -1); | ||||||||||||||||||||||
| io_handle_tmp->close(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| TEST_F(ListenerManagerImplWithRealFiltersTest, OriginalDstTestFilterOptionFailIPv6) { | ||||||||||||||||||||||
| class OriginalDstTestConfigFactory : public Configuration::NamedListenerFilterConfigFactory { | ||||||||||||||||||||||
| public: | ||||||||||||||||||||||
| // NamedListenerFilterConfigFactory | ||||||||||||||||||||||
| Network::ListenerFilterFactoryCb | ||||||||||||||||||||||
| createFilterFactoryFromProto(const Protobuf::Message&, | ||||||||||||||||||||||
| Configuration::ListenerFactoryContext& context) override { | ||||||||||||||||||||||
| auto option = std::make_unique<Network::MockSocketOption>(); | ||||||||||||||||||||||
| EXPECT_CALL(*option, setOption(_, envoy::api::v2::core::SocketOption::STATE_PREBIND)) | ||||||||||||||||||||||
| .WillOnce(Return(false)); | ||||||||||||||||||||||
| context.addListenSocketOption(std::move(option)); | ||||||||||||||||||||||
| return [](Network::ListenerFilterManager& filter_manager) -> void { | ||||||||||||||||||||||
| filter_manager.addAcceptFilter(std::make_unique<OriginalDstTestFilterIPv6>()); | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ProtobufTypes::MessagePtr createEmptyConfigProto() override { | ||||||||||||||||||||||
| return std::make_unique<Envoy::ProtobufWkt::Empty>(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| std::string name() override { return "testfail.listener.original_dstipv6"; } | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Static registration for the original dst filter. @see RegisterFactory. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| static Registry::RegisterFactory<OriginalDstTestConfigFactory, | ||||||||||||||||||||||
| Configuration::NamedListenerFilterConfigFactory> | ||||||||||||||||||||||
| registered_; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const std::string yaml = TestEnvironment::substitute(R"EOF( | ||||||||||||||||||||||
| name: "socketOptionFailListener" | ||||||||||||||||||||||
| address: | ||||||||||||||||||||||
| socket_address: { address: ::0001, port_value: 1111 } | ||||||||||||||||||||||
| filter_chains: {} | ||||||||||||||||||||||
| listener_filters: | ||||||||||||||||||||||
| - name: "testfail.listener.original_dstipv6" | ||||||||||||||||||||||
| config: {} | ||||||||||||||||||||||
| )EOF", | ||||||||||||||||||||||
| Network::Address::IpVersion::v6); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| EXPECT_CALL(listener_factory_, createListenSocket(_, _, _, true)); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| EXPECT_THROW_WITH_MESSAGE(manager_->addOrUpdateListener(parseListenerFromV2Yaml(yaml), "", true), | ||||||||||||||||||||||
| EnvoyException, | ||||||||||||||||||||||
| "MockListenerComponentFactory: Setting socket options failed"); | ||||||||||||||||||||||
| EXPECT_EQ(0U, manager_->listeners().size()); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Validate that when neither transparent nor freebind is not set in the | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little concerned that we are losing some test coverage that matters here. Are you positive that this is not being used by existing listener filters? I'm not convinced. Can you see who added these tests and ask them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove the two functions from
ListenerFactoryContextand the build is successful. That's the proof that no listener filter in the code tree is using it. Unfortunately I can never verify if private code is using ... and that is the linked issue for