Skip to content
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

Matchers: Add dynamic metadata to the http inputs #34891

Merged
merged 21 commits into from
Aug 5, 2024

Conversation

vikaschoudhary16
Copy link
Contributor

fixes: #34092
Commit Message: Add dynamic metadata to the http inputs
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @mattklein123
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #34891 was opened by vikaschoudhary16.

see: more, trace.

@vikaschoudhary16 vikaschoudhary16 marked this pull request as draft June 25, 2024 08:31
Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
@zetaab
Copy link

zetaab commented Jul 26, 2024

@vikaschoudhary16 what is still needed to get this forward from draft status?

Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
@vikaschoudhary16 vikaschoudhary16 marked this pull request as ready for review July 29, 2024 09:39
@vikaschoudhary16
Copy link
Contributor Author

@vikaschoudhary16 what is still needed to get this forward from draft status?

tests were pending. Now marked ready

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM. Needs a release note. add @kyessenov to do the code review.

/wait

Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
Copy link
Contributor

@kyessenov kyessenov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good -> mostly minor comments.

@@ -30,6 +30,7 @@ These input functions are available for matching HTTP requests:
* :ref:`Response header value <extension_envoy.matching.inputs.response_headers>`.
* :ref:`Response trailer value <extension_envoy.matching.inputs.response_trailers>`.
* :ref:`Query parameters value <extension_envoy.matching.inputs.query_params>`.
* :ref:`Metadata <extension_envoy.matching.inputs.dynamic_metadata>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Dynamic metadata

@@ -103,3 +103,48 @@ message ApplicationProtocolInput {
message FilterStateInput {
string key = 1 [(validate.rules).string = {min_len: 1}];
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be placed into network inputs? Are you planning to add network input support as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure. Looked at existing filter state which is defined here in network input and being used for both http and network. So thought similar we could do with metadata.
Yeah, I would add network input support as well in follow-up

name = "metadata_input_lib",
srcs = ["meta_input.cc"],
hdrs = ["meta_input.h"],
extra_visibility = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete extra visibility, also why skip on windows?

class MetadataMatchData : public ::Envoy::Matcher::CustomMatchData {
public:
explicit MetadataMatchData(const ProtobufWkt::Value& value) : value_(value) {}
const ProtobufWkt::Value& value_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to myself: this is a dangerous capture by reference. I see CEL does the same thing, but we probably need to audit for potential dangling references.

public:
DynamicMetadataInput(
const envoy::extensions::matching::common_inputs::network::v3::DynamicMetadataInput&
inputConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: inputConfig -> input_config

const auto& matcher_config = MessageUtil::downcastAndValidate<
const envoy::extensions::matching::input_matchers::metadata::v3::Metadata&>(
config, factory_context.messageValidationVisitor());
const auto& v = matcher_config.value();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: v -> value

const envoy::extensions::matching::input_matchers::metadata::v3::Metadata&>(
config, factory_context.messageValidationVisitor());
const auto& v = matcher_config.value();
auto value_matcher = Envoy::Matchers::ValueMatcher::create(v, factory_context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two should be const

: value_matcher_(value_matcher), invert_(invert) {}

bool Matcher::match(const Envoy::Matcher::MatchingDataType& input) {
if (absl::holds_alternative<absl::monostate>(input)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed with get_if?

if (auto* ptr = absl::get_if<std::shared_ptr<::Envoy::Matcher::CustomMatchData>>(&input);
ptr != nullptr) {
Matching::Http::MetadataInput::MetadataMatchData* match_data =
dynamic_cast<Matching::Http::MetadataInput::MetadataMatchData*>((*ptr).get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(*ptr).get() is odd -> doesn't ptr work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with only ptr, I get

error: 'std::shared_ptrEnvoy::Matcher::CustomMatchData' is not polymorphic

Changed to ptr->get() though

@@ -0,0 +1,34 @@
load(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test directory should match the source: dyn_meta_matcher -> metadata

Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
@mattklein123 mattklein123 removed their assignment Jul 31, 2024
@mattklein123
Copy link
Member

/api lgtm

mattklein123
mattklein123 previously approved these changes Jul 31, 2024
kyessenov
kyessenov previously approved these changes Jul 31, 2024
Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary <[email protected]>
@yanavlasov yanavlasov merged commit 520d88e into envoyproxy:main Aug 5, 2024
50 of 51 checks passed
martinduke pushed a commit to martinduke/envoy that referenced this pull request Aug 8, 2024
fixes: envoyproxy#34092

---------

Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Martin Duke <[email protected]>
asingh-g pushed a commit to asingh-g/envoy that referenced this pull request Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support metadata input in Mathching API
5 participants