forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Header to metadata filter (envoyproxy#2436)
Add support for extracting dynamic metadata from requests. This can then be used as static metadata would be used (e.g.: for subset load balancer metadata matches, logging, etc). Risk Level: Low Testing: unit-test Docs Changes: Basic docs, more later. Release Notes: N/A Signed-off-by: Raul Gutierrez Segales <[email protected]>
- Loading branch information
Raul Gutierrez Segales
committed
Jun 14, 2018
1 parent
7ca1882
commit 9a4c44c
Showing
19 changed files
with
805 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,9 @@ | ||
load("//bazel:api_build_system.bzl", "api_proto_library") | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
api_proto_library( | ||
name = "header_to_metadata", | ||
srcs = ["header_to_metadata.proto"], | ||
deps = [], | ||
) |
42 changes: 42 additions & 0 deletions
42
api/envoy/config/filter/http/header_to_metadata/v2/header_to_metadata.proto
This file contains 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,42 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.config.filter.http.header_to_metadata.v2; | ||
|
||
enum ValueType { | ||
STRING = 0; | ||
NUMBER = 1; | ||
} | ||
|
||
message KeyValuePair { | ||
// The namespace. If this is empty, the filter's namespace will be used. | ||
string metadata_namespace = 1; | ||
|
||
// The key — must be present. | ||
string key = 2; | ||
|
||
// The value — may be absent. | ||
string value = 3; | ||
|
||
// The type. | ||
ValueType type = 4; | ||
} | ||
|
||
message Rule { | ||
// The header from which to extract a value. | ||
string header = 1; | ||
|
||
// The metadata key with which the extracted value will be paired. | ||
KeyValuePair on_header_present = 2; | ||
|
||
// If the header is not present — and this is set — insert this key/value pair instead. | ||
KeyValuePair on_header_missing = 3; | ||
|
||
// Whether or not to remove the header after it's been copied to metadata. By allowing the | ||
// configuration to express header removal, we easily prevent internal metadata from leaking. | ||
bool remove = 4; | ||
} | ||
|
||
message Config { | ||
repeated Rule request_rules = 1; | ||
repeated Rule response_rules = 2; | ||
} |
This file contains 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 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 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 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
14 changes: 14 additions & 0 deletions
14
docs/root/configuration/http_filters/header_to_metadata_filter.rst
This file contains 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,14 @@ | ||
.. _config_http_filters_header_to_metadata: | ||
|
||
Envoy Header-To-Metadata Filter | ||
================================ | ||
|
||
This filter enables matching against present or missing headers and transforming | ||
those matches into dynamic metadata that can then be used for load balancing | ||
decisions or consumed from logs. | ||
|
||
Configuration | ||
------------- | ||
* :ref:`v2 API reference <envoy_api_msg_config.filter.http.header_to_metadata.v2.HeaderToMetadata>` | ||
|
||
TODO(rgs) |
This file contains 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 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 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 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,34 @@ | ||
licenses(["notice"]) # Apache 2 | ||
# HTTP L7 filter that transforms request data into dynamic metadata | ||
# Public docs: docs/root/configuration/http_filters/header_to_metadata_filter.rst | ||
|
||
load( | ||
"@envoy//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_package", | ||
) | ||
|
||
envoy_package() | ||
|
||
envoy_cc_library( | ||
name = "header_to_metadata_filter_lib", | ||
srcs = ["header_to_metadata_filter.cc"], | ||
hdrs = ["header_to_metadata_filter.h"], | ||
deps = [ | ||
"//include/envoy/server:filter_config_interface", | ||
"//source/extensions/filters/http:well_known_names", | ||
"@envoy_api//envoy/config/filter/http/header_to_metadata/v2:header_to_metadata_cc", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "config", | ||
srcs = ["config.cc"], | ||
hdrs = ["config.h"], | ||
deps = [ | ||
"//include/envoy/registry", | ||
"//source/common/protobuf:utility_lib", | ||
"//source/extensions/filters/http:well_known_names", | ||
"//source/extensions/filters/http/header_to_metadata:header_to_metadata_filter_lib", | ||
], | ||
) |
57 changes: 57 additions & 0 deletions
57
source/extensions/filters/http/header_to_metadata/config.cc
This file contains 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,57 @@ | ||
#include "config.h" | ||
|
||
#include <string> | ||
#include <tuple> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "envoy/config/filter/http/header_to_metadata/v2/header_to_metadata.pb.h" | ||
#include "envoy/json/json_object.h" | ||
#include "envoy/registry/registry.h" | ||
|
||
#include "common/protobuf/utility.h" | ||
|
||
#include "filter.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace HttpFilters { | ||
namespace HeaderToMetadataFilter { | ||
|
||
Http::FilterFactoryCb | ||
HeaderToMetadataConfig::createFilterFactory(const Json::Object&, const std::string&, | ||
Server::Configuration::FactoryContext&) { | ||
throw new EnvoyException("No support for the v1 API"); | ||
} | ||
|
||
Http::FilterFactoryCb | ||
HeaderToMetadataConfig::createFilterFactoryFromProto(const Protobuf::Message& proto_config, | ||
const std::string&, | ||
Server::Configuration::FactoryContext&) { | ||
const auto& typed_config = dynamic_cast< | ||
const envoy::config::filter::http::header_to_metadata::v2::HeaderToMetadataConfig&>( | ||
proto_config); | ||
ConfigSharedPtr filter_config(std::make_shared<Config>(typed_config)); | ||
|
||
return [filter_config](Http::FilterChainFactoryCallbacks& callbacks) -> void { | ||
callbacks.addStreamFilter( | ||
Http::StreamFilterSharedPtr{new HeaderToMetadataFilter(filter_config)}); | ||
}; | ||
} | ||
|
||
ProtobufTypes::MessagePtr HeaderToMetadataConfig::createEmptyConfigProto() { | ||
return ProtobufTypes::MessagePtr{ | ||
new envoy::config::filter::http::header_to_metadata::v2::HeaderToMetadataConfig()}; | ||
} | ||
|
||
/** | ||
* Static registration for the header-to-metadata filter. @see RegisterFactory. | ||
*/ | ||
static Registry::RegisterFactory<HeaderToMetadataConfig, | ||
Server::Configuration::NamedHttpFilterConfigFactory> | ||
register_; | ||
|
||
} // namespace HeaderToMetadataFilter | ||
} // namespace HttpFilters | ||
} // namespace Extensions | ||
} // namespace Envoy |
32 changes: 32 additions & 0 deletions
32
source/extensions/filters/http/header_to_metadata/config.h
This file contains 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,32 @@ | ||
#pragma once | ||
|
||
#include "envoy/server/filter_config.h" | ||
|
||
#include "extensions/filters/http/well_known_names.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace HttpFilters { | ||
namespace HeaderToMetadataFilter { | ||
|
||
/** | ||
* Config registration for the header-to-metadata filter. @see NamedHttpFilterConfigFactory. | ||
*/ | ||
class HeaderToMetadataConfig : public Server::Configuration::NamedHttpFilterConfigFactory { | ||
public: | ||
Http::FilterFactoryCb createFilterFactory(const Json::Object&, const std::string&, | ||
Server::Configuration::FactoryContext&) override; | ||
|
||
Http::FilterFactoryCb | ||
createFilterFactoryFromProto(const Protobuf::Message&, const std::string&, | ||
Server::Configuration::FactoryContext&) override; | ||
|
||
ProtobufTypes::MessagePtr createEmptyConfigProto() override; | ||
|
||
std::string name() override { return HttpFilterNames::get().HEADER_TO_METADATA; } | ||
}; | ||
|
||
} // namespace HeaderToMetadataFilter | ||
} // namespace HttpFilters | ||
} // namespace Extensions | ||
} // namespace Envoy |
Oops, something went wrong.