-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Set-Metadata HTTP filter #16400
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
Set-Metadata HTTP filter #16400
Changes from all commits
46024aa
9d26ca2
acb5e25
7540c2a
4e846f0
d13f111
56ea00f
d001646
cfad084
d139579
45ca933
c113bb2
0469f86
d82b20a
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
|
||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_package( | ||
| deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.filters.http.set_metadata.v3; | ||
|
|
||
| import "google/protobuf/struct.proto"; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
| import "udpa/annotations/versioning.proto"; | ||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.filters.http.set_metadata.v3"; | ||
| option java_outer_classname = "SetMetadataProto"; | ||
| option java_multiple_files = true; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: Set-Metadata Filter] | ||
| // | ||
| // This filters adds or updates dynamic metadata with static data. | ||
| // | ||
| // [#extension: envoy.filters.http.set_metadata] | ||
|
|
||
| message Config { | ||
| // The metadata namespace. | ||
| string metadata_namespace = 1 [(validate.rules).string = {min_len: 1}]; | ||
|
|
||
| // The value to update the namespace with. See | ||
| // :ref:`the filter documentation <config_http_filters_set_metadata>` for | ||
| // more information on how this value is merged with potentially existing | ||
| // ones. | ||
| google.protobuf.Struct value = 2; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| .. _config_http_filters_set_metadata: | ||
|
|
||
| Set Metadata | ||
| ============ | ||
| * :ref:`v3 API reference <envoy_v3_api_msg_extensions.filters.http.set_metadata.v3.Config>` | ||
| * This filter should be configured with the name *envoy.filters.http.set_metadata*. | ||
|
|
||
| This filters adds or updates dynamic metadata with static data. | ||
|
|
||
| Dynamic metadata values are updated with the following scheme. If a key | ||
|
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. @envoyproxy/api-shepherds this differs from |
||
| does not exists, it's just copied into the current metadata. If the key exists | ||
| but has a different type, it is replaced by the new value. Otherwise: | ||
|
|
||
| * for scalar values (null, string, number, boolean) are replaced with the new value | ||
| * for lists: new values are added to the current list | ||
| * for structures: recursively apply this scheme | ||
|
|
||
| For instance, if the namespace already contains this structure: | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| myint: 1 | ||
| mylist: ["a"] | ||
| mykey: ["val"] | ||
| mytags: | ||
| tag0: 1 | ||
|
|
||
| and the value to set is: | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| myint: 2 | ||
| mylist: ["b","c"] | ||
| mykey: 1 | ||
| mytags: | ||
| tag1: 1 | ||
|
|
||
| After applying this filter, the namespace will contain: | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| myint: 2 | ||
| mylist: ["a","b","c"] | ||
| mykey: 1 | ||
| mytags: | ||
| tag0: 1 | ||
| tag1: 1 | ||
|
|
||
| Statistics | ||
| ---------- | ||
|
|
||
| Currently, this filter generates no statistics. | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_extension", | ||
| "envoy_cc_library", | ||
| "envoy_extension_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_extension_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "set_metadata_filter_lib", | ||
| srcs = ["set_metadata_filter.cc"], | ||
| hdrs = ["set_metadata_filter.h"], | ||
| deps = [ | ||
| "//include/envoy/server:filter_config_interface", | ||
| "//source/common/http:utility_lib", | ||
| "//source/common/protobuf:utility_lib", | ||
| "//source/extensions/filters/http:well_known_names", | ||
| "//source/extensions/filters/http/common:pass_through_filter_lib", | ||
| "@envoy_api//envoy/extensions/filters/http/set_metadata/v3:pkg_cc_proto", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_extension( | ||
| name = "config", | ||
| srcs = ["config.cc"], | ||
| hdrs = ["config.h"], | ||
| category = "envoy.filters.http", | ||
| security_posture = "robust_to_untrusted_downstream_and_upstream", | ||
| deps = [ | ||
| "//include/envoy/registry", | ||
| "//source/common/protobuf:utility_lib", | ||
| "//source/extensions/filters/http:well_known_names", | ||
| "//source/extensions/filters/http/common:factory_base_lib", | ||
| "//source/extensions/filters/http/set_metadata:set_metadata_filter_lib", | ||
| "@envoy_api//envoy/extensions/filters/http/set_metadata/v3:pkg_cc_proto", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include "extensions/filters/http/set_metadata/config.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "envoy/extensions/filters/http/set_metadata/v3/set_metadata.pb.h" | ||
| #include "envoy/extensions/filters/http/set_metadata/v3/set_metadata.pb.validate.h" | ||
| #include "envoy/registry/registry.h" | ||
|
|
||
| #include "common/protobuf/utility.h" | ||
|
|
||
| #include "extensions/filters/http/set_metadata/set_metadata_filter.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace SetMetadataFilter { | ||
|
|
||
| Http::FilterFactoryCb SetMetadataConfig::createFilterFactoryFromProtoTyped( | ||
htuch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const envoy::extensions::filters::http::set_metadata::v3::Config& proto_config, | ||
| const std::string&, Server::Configuration::FactoryContext&) { | ||
| ConfigSharedPtr filter_config(std::make_shared<Config>(proto_config)); | ||
|
|
||
| return [filter_config](Http::FilterChainFactoryCallbacks& callbacks) -> void { | ||
| callbacks.addStreamDecoderFilter( | ||
| Http::StreamDecoderFilterSharedPtr{new SetMetadataFilter(filter_config)}); | ||
| }; | ||
| } | ||
|
|
||
| REGISTER_FACTORY(SetMetadataConfig, Server::Configuration::NamedHttpFilterConfigFactory); | ||
|
|
||
| } // namespace SetMetadataFilter | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/extensions/filters/http/set_metadata/v3/set_metadata.pb.h" | ||
| #include "envoy/extensions/filters/http/set_metadata/v3/set_metadata.pb.validate.h" | ||
|
|
||
| #include "extensions/filters/http/common/factory_base.h" | ||
| #include "extensions/filters/http/well_known_names.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace SetMetadataFilter { | ||
|
|
||
| /** | ||
| * Config registration for the header-to-metadata filter. @see NamedHttpFilterConfigFactory. | ||
| */ | ||
| class SetMetadataConfig | ||
| : public Common::FactoryBase<envoy::extensions::filters::http::set_metadata::v3::Config> { | ||
| public: | ||
| SetMetadataConfig() : FactoryBase(HttpFilterNames::get().SetMetadata) {} | ||
|
|
||
| private: | ||
| Http::FilterFactoryCb createFilterFactoryFromProtoTyped( | ||
| const envoy::extensions::filters::http::set_metadata::v3::Config& proto_config, | ||
| const std::string& stats_prefix, Server::Configuration::FactoryContext& context) override; | ||
| }; | ||
|
|
||
| } // namespace SetMetadataFilter | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
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.
Need to update https://github.com/envoyproxy/envoy/blob/main/CODEOWNERS
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 tried to added myself, but it asked for a second maintainer. Who should I add? @snowp as he is sponsoring it :) ?
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.
Yes, Snow and you.
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.
Sorry missed this answer. Done in d139579 !