-
Notifications
You must be signed in to change notification settings - Fork 5.4k
dynamic modules: add asyncDataSource for the module binary using local.filename #43333
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
74ae885
dynamic modules: add remote fetching for the module binary
kanurag94 7f80388
Merge remote-tracking branch 'upstream/main' into dym-loading
kanurag94 810558e
add tests and cleanup
kanurag94 ec4159f
attempt fixing coverage
kanurag94 93caee8
attempt fixing coverage
kanurag94 13d1089
lower coverage percentage for dynamic_modules filter
kanurag94 b708a8f
fix issues related to fetch
kanurag94 ed84cf4
Merge remote-tracking branch 'upstream/main' into dym-loading
kanurag94 d4a09af
Merge remote-tracking branch 'origin/dym-loading' into dym-loading
kanurag94 52c7e77
fix lint
kanurag94 ec9edb5
lower coverage due proto validation not invoking lines
kanurag94 5113c7e
add changelog
kanurag94 b1f5055
Merge remote-tracking branch 'upstream/main' into dym-loading
kanurag94 028fb4d
address review comments: remove cache related code
kanurag94 ce47d78
refactoring: logging and avoid buffer copy
kanurag94 0b63daa
review: remove inline source
kanurag94 b793679
refactor the code
kanurag94 29170e1
fix some failing tests
kanurag94 c186ec4
simpler refactoring
kanurag94 69b6956
Merge remote-tracking branch 'upstream/main' into dym-loading
kanurag94 19cb20a
reuse methods in factory
kanurag94 d134e6a
add exec permissions to temp file
kanurag94 c838d3b
add owner_all permissions to temp file
kanurag94 4568023
try keeping local.filename support only
kanurag94 798b887
move the test files
kanurag94 b611d90
use loadFromYamlAndValidate
kanurag94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,9 @@ syntax = "proto3"; | |
|
|
||
| package envoy.extensions.dynamic_modules.v3; | ||
|
|
||
| import "envoy/config/core/v3/base.proto"; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.dynamic_modules.v3"; | ||
| option java_outer_classname = "DynamicModulesProto"; | ||
|
|
@@ -30,7 +31,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE; | |
| // the ABI is stabilized, this restriction will be revisited. Until then, Envoy checks the hash of | ||
| // the ABI header files to ensure that the dynamic modules are built against the same version of the | ||
| // ABI. | ||
| // [#next-free-field: 6] | ||
| // [#next-free-field: 7] | ||
| message DynamicModuleConfig { | ||
| // The name of the dynamic module. | ||
| // | ||
|
|
@@ -42,9 +43,12 @@ message DynamicModuleConfig { | |
| // try to find the module from a standard system library path (e.g., ``/usr/lib``) following the | ||
| // platform's default behavior for ``dlopen``. | ||
| // | ||
| // This field is optional if the ``module`` field is set. When both ``name`` and ``module`` are | ||
| // specified, the ``module`` field takes precedence. | ||
| // | ||
| // .. note:: | ||
| // There is some remaining work to make the search path configurable via command line options. | ||
| string name = 1 [(validate.rules).string = {min_len: 1}]; | ||
| string name = 1; | ||
|
|
||
| // If true, prevents the module from being unloaded with ``dlclose``. | ||
| // | ||
|
|
@@ -80,4 +84,10 @@ message DynamicModuleConfig { | |
| // | ||
| // Defaults to ``dynamicmodulescustom``. | ||
| string metrics_namespace = 5; | ||
|
|
||
| // The dynamic module binary to load. Currently only supports local file paths | ||
| // via ``local.filename``. | ||
| // | ||
| // When both ``name`` and ``module`` are set, ``module`` takes precedence. | ||
| config.core.v3.AsyncDataSource module = 6; | ||
|
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. I named it |
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| #include "envoy/extensions/filters/http/dynamic_modules/v3/dynamic_modules.pb.h" | ||
| #include "envoy/extensions/filters/http/dynamic_modules/v3/dynamic_modules.pb.validate.h" | ||
|
|
||
| #include "source/common/stats/isolated_store_impl.h" | ||
| #include "source/extensions/filters/http/dynamic_modules/factory.h" | ||
|
|
||
| #include "test/extensions/dynamic_modules/util.h" | ||
| #include "test/mocks/network/mocks.h" | ||
| #include "test/mocks/server/mocks.h" | ||
| #include "test/test_common/environment.h" | ||
| #include "test/test_common/utility.h" | ||
|
|
||
| #include "gmock/gmock.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| using testing::ReturnRef; | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
| namespace Configuration { | ||
|
|
||
| class DynamicModuleFilterConfigTest : public Event::TestUsingSimulatedTime, public testing::Test { | ||
| protected: | ||
| DynamicModuleFilterConfigTest() : api_(Api::createApiForTest(stats_store_)) { | ||
| ON_CALL(context_.server_factory_context_, api()).WillByDefault(ReturnRef(*api_)); | ||
| ON_CALL(context_, scope()).WillByDefault(ReturnRef(stats_scope_)); | ||
| ON_CALL(context_, listenerInfo()).WillByDefault(ReturnRef(listener_info_)); | ||
| ON_CALL(listener_info_, metadata()).WillByDefault(ReturnRef(listener_metadata_)); | ||
| EXPECT_CALL(context_, initManager()).WillRepeatedly(ReturnRef(init_manager_)); | ||
| } | ||
|
|
||
| NiceMock<Network::MockListenerInfo> listener_info_; | ||
| Stats::IsolatedStoreImpl stats_store_; | ||
| Stats::Scope& stats_scope_{*stats_store_.rootScope()}; | ||
| Api::ApiPtr api_; | ||
| envoy::config::core::v3::Metadata listener_metadata_; | ||
| Init::ManagerImpl init_manager_{"init_manager"}; | ||
| Init::ExpectableWatcherImpl init_watcher_; | ||
|
|
||
| NiceMock<Server::Configuration::MockFactoryContext> context_; | ||
| }; | ||
|
|
||
| TEST_F(DynamicModuleFilterConfigTest, LocalFileLoading) { | ||
| const std::string module_path = Extensions::DynamicModules::testSharedObjectPath("no_op", "c"); | ||
|
|
||
| const std::string yaml = TestEnvironment::substitute(absl::StrCat(R"EOF( | ||
| dynamic_module_config: | ||
| module: | ||
| local: | ||
| filename: ")EOF", | ||
| module_path, R"EOF(" | ||
| do_not_close: true | ||
| filter_name: "test_filter" | ||
| )EOF")); | ||
|
|
||
| envoy::extensions::filters::http::dynamic_modules::v3::DynamicModuleFilter proto_config; | ||
| TestUtility::loadFromYamlAndValidate(yaml, proto_config); | ||
|
|
||
| DynamicModuleConfigFactory factory; | ||
| auto cb_or_error = factory.createFilterFactoryFromProto(proto_config, "stats", context_); | ||
| EXPECT_TRUE(cb_or_error.ok()) << cb_or_error.status().message(); | ||
|
|
||
| EXPECT_CALL(init_watcher_, ready()); | ||
| context_.initManager().initialize(init_watcher_); | ||
| EXPECT_EQ(context_.initManager().state(), Init::Manager::State::Initialized); | ||
| } | ||
|
|
||
| TEST_F(DynamicModuleFilterConfigTest, InlineBytesRejected) { | ||
| const std::string yaml = R"EOF( | ||
| dynamic_module_config: | ||
| module: | ||
| local: | ||
| inline_bytes: "AAAA" | ||
| do_not_close: true | ||
| filter_name: "test_filter" | ||
| )EOF"; | ||
|
|
||
| envoy::extensions::filters::http::dynamic_modules::v3::DynamicModuleFilter proto_config; | ||
| TestUtility::loadFromYamlAndValidate(yaml, proto_config); | ||
|
|
||
| DynamicModuleConfigFactory factory; | ||
| auto cb_or_error = factory.createFilterFactoryFromProto(proto_config, "stats", context_); | ||
| EXPECT_FALSE(cb_or_error.ok()); | ||
| EXPECT_THAT(cb_or_error.status().message(), | ||
| testing::HasSubstr("Only local file path is supported")); | ||
| } | ||
|
|
||
| TEST_F(DynamicModuleFilterConfigTest, NoModuleOrName) { | ||
| const std::string yaml = R"EOF( | ||
| dynamic_module_config: | ||
| do_not_close: true | ||
| filter_name: "test_filter" | ||
| )EOF"; | ||
|
|
||
| envoy::extensions::filters::http::dynamic_modules::v3::DynamicModuleFilter proto_config; | ||
| TestUtility::loadFromYamlAndValidate(yaml, proto_config); | ||
|
|
||
| DynamicModuleConfigFactory factory; | ||
| auto cb_or_error = factory.createFilterFactoryFromProto(proto_config, "stats", context_); | ||
| EXPECT_FALSE(cb_or_error.ok()); | ||
| EXPECT_THAT(cb_or_error.status().message(), | ||
| testing::HasSubstr("Either 'name' or 'module' must be specified")); | ||
| } | ||
|
|
||
| TEST_F(DynamicModuleFilterConfigTest, RemoteSourceRejected) { | ||
| const std::string yaml = R"EOF( | ||
| dynamic_module_config: | ||
| module: | ||
| remote: | ||
| http_uri: | ||
| uri: https://example.com/module.so | ||
| cluster: cluster_1 | ||
| timeout: 5s | ||
| sha256: "abc123" | ||
| do_not_close: true | ||
| filter_name: "test_filter" | ||
| )EOF"; | ||
|
|
||
| envoy::extensions::filters::http::dynamic_modules::v3::DynamicModuleFilter proto_config; | ||
| TestUtility::loadFromYamlAndValidate(yaml, proto_config); | ||
|
|
||
| DynamicModuleConfigFactory factory; | ||
| auto cb_or_error = factory.createFilterFactoryFromProto(proto_config, "stats", context_); | ||
| EXPECT_FALSE(cb_or_error.ok()); | ||
| EXPECT_THAT(cb_or_error.status().message(), | ||
| testing::HasSubstr("Only local file path is supported")); | ||
| } | ||
|
|
||
| TEST_F(DynamicModuleFilterConfigTest, InvalidLocalFile) { | ||
| const std::string yaml = R"EOF( | ||
| dynamic_module_config: | ||
| module: | ||
| local: | ||
| filename: "/nonexistent/path/to/module.so" | ||
| do_not_close: true | ||
| filter_name: "test_filter" | ||
| )EOF"; | ||
|
|
||
| envoy::extensions::filters::http::dynamic_modules::v3::DynamicModuleFilter proto_config; | ||
| TestUtility::loadFromYamlAndValidate(yaml, proto_config); | ||
|
|
||
| DynamicModuleConfigFactory factory; | ||
| auto cb_or_error = factory.createFilterFactoryFromProto(proto_config, "stats", context_); | ||
| EXPECT_FALSE(cb_or_error.ok()); | ||
| EXPECT_THAT(cb_or_error.status().message(), testing::HasSubstr("Failed to load dynamic module")); | ||
| } | ||
|
|
||
| // Verify that when both name and module are set, module takes precedence. | ||
| TEST_F(DynamicModuleFilterConfigTest, ModulePrecedenceOverName) { | ||
| const std::string module_path = Extensions::DynamicModules::testSharedObjectPath("no_op", "c"); | ||
|
|
||
| const std::string yaml = TestEnvironment::substitute(absl::StrCat(R"EOF( | ||
| dynamic_module_config: | ||
| name: "nonexistent_module_should_be_ignored" | ||
| module: | ||
| local: | ||
| filename: ")EOF", | ||
| module_path, R"EOF(" | ||
| do_not_close: true | ||
| filter_name: "test_filter" | ||
| )EOF")); | ||
|
|
||
| envoy::extensions::filters::http::dynamic_modules::v3::DynamicModuleFilter proto_config; | ||
| TestUtility::loadFromYamlAndValidate(yaml, proto_config); | ||
|
|
||
| DynamicModuleConfigFactory factory; | ||
| // If name were used, this would fail because "nonexistent_module_should_be_ignored" doesn't | ||
| // exist. Since module takes precedence, it should succeed with the local file. | ||
| auto cb_or_error = factory.createFilterFactoryFromProto(proto_config, "stats", context_); | ||
| EXPECT_TRUE(cb_or_error.ok()) << cb_or_error.status().message(); | ||
| } | ||
|
|
||
| } // namespace Configuration | ||
| } // namespace Server | ||
| } // namespace Envoy |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Removed this validation as we might want to deprecate this in future.
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.
Although I think we won't deprecate it. But your change is correct.
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.
we won't deprecate yeah because of #43696