Skip to content

http: add composite filter allowing dynamic filter selection#15198

Merged
htuch merged 62 commits intoenvoyproxy:mainfrom
snowp:composite-filter
Apr 14, 2021
Merged

http: add composite filter allowing dynamic filter selection#15198
htuch merged 62 commits intoenvoyproxy:mainfrom
snowp:composite-filter

Conversation

@snowp
Copy link
Copy Markdown
Contributor

@snowp snowp commented Feb 25, 2021

Adds a new filter that makes use of the new matching API to allow specifying a filter configuration to use for specific match
results. Once a configuration is selected, the desired filter is created and all callbacks delegated to the specific filter.

Risk Level: Low, new filter
Testing: IT + UT
Docs Changes: Inline proto comments
Release Notes: wip

Snow Pettersen added 25 commits December 17, 2020 02:31
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
wip
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
wip
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
wip
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
wip
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
API shepherd assignee is @lizan
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #15198 was opened by snowp.

see: more, trace.

Snow Pettersen added 2 commits March 8, 2021 18:09
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Snow Pettersen added 3 commits April 5, 2021 17:50
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Snow Pettersen added 3 commits April 5, 2021 18:39
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
@mattklein123
Copy link
Copy Markdown
Member

I think there are a few open comment threads. Are you still making changes? LMK when it's ready to review again.

/wait-any

Snow Pettersen added 2 commits April 9, 2021 13:50
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Copy link
Copy Markdown
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.

Super awesome. Just some small comments and then I think we can ship!

/wait

// headers. This makes it possible to use different filters or filter configurations based on the
// incoming request.
//
// This is intended to used with
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// This is intended to used with
// This is intended to be used with

this, in order to delegate all the data to the specified filter, the decision must be made based
on just the request headers.

Delegation can fail for a few reasons: the match result was not ready in time for the filter
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can't happen anymore given that we require only request headers, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, will rephrase

Conditional Filter Configuration
--------------------------------

There is some support for having the filter configuration used to change based on the incoming
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
There is some support for having the filter configuration used to change based on the incoming
There is some support for having the filter configuration used change based on the incoming

auto requirements = std::make_unique<
envoy::extensions::filters::common::dependency::v3::MatchingRequirements>();

requirements->mutable_data_input_allow_list()->add_type_url(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a small human readable comment on what this does?

// Helper that returns `filter->func(args...)` if the filter is not null, returning `rval`
// otherwise.
template <class FilterPtrT, class FuncT, class RValT, class... Args>
RValT delegateFilterAction(FilterPtrT& filter, FuncT func, RValT rval, Args&&... args) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I might call this delegateFilterActionOr to match similar things like value_or in optional, etc.

Comment on lines +69 to +73
// Use these to track whether we are allowed to insert a specific kind of filter. These mainly
// serve to surface an easier to understand error, as attempting to insert a filter at a later
// time will result in various FM assertions firing.
// TODO(snowp): Instead of validating this via ASSERTs, we should be able to validate that the
// match tree is only going to fire when we can actually inject a filter.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is partially fixed, right? I was actually going to ask for ASSERTs also, so IMO it's not terrible to just keep this but should the comment be updated?

Comment on lines +84 to +90
if (!wrapper.errors_.empty()) {
stats_.filter_delegation_error_.inc();
ENVOY_LOG(debug, "failed to create delegated filter {}",
accumulateToString<absl::Status>(
wrapper.errors_, [](const auto& status) { return status.ToString(); }));
return;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe this is an issue with the matching engine that needs to be fixed, but shouldn't this return an error code which should tell the engine to actually do something like fail the request? We can discuss later about fail open vs. fail closed, but it seems like it shouldn't just be a nop? wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a good point, I think in the short term we could local reply here with a 500 or something, but maybe it would be nicer with direct integration with the matching framework? Or maybe just a success bool so that we can avoid calling decodeHeaders etc. if matching resulted in a local reply?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO I would have it be built-in to the matching engine with a return code vs. void, but fine if you want to TODO here to fix that later and for now just do a local reply.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Turns out we can't do a local reply here since the associated filter callback is invoked:

[2021-04-12 20:53:43.183][48][error][envoy_bug] [source/common/http/filter_manager.cc:523] envoy bug failure: !continue_iteration || !state_.local_complete_. Details: Filter did not return StopAll or StopIteration after sending a local reply.

Seems like we need some HCM changes to make this work, wdyt about landing this as is with a TODO and then follow up once we improve the onMatchCallback API?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure that's fine, thanks for checking.

Snow Pettersen added 3 commits April 12, 2021 18:01
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Copy link
Copy Markdown
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.

Thanks!

@snowp
Copy link
Copy Markdown
Contributor Author

snowp commented Apr 13, 2021

@htuch you have pending changes requested, ptal

@htuch htuch merged commit d31ba23 into envoyproxy:main Apr 14, 2021
douglas-reid pushed a commit to douglas-reid/envoy that referenced this pull request Apr 19, 2021
…oxy#15198)

Adds a new filter that makes use of the new matching API to allow specifying a filter configuration to use for specific match
results. Once a configuration is selected, the desired filter is created and all callbacks delegated to the specific filter.

Risk Level: Low, new filter
Testing: IT + UT
Docs Changes: Inline proto comments

Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Douglas Reid <douglas-reid@users.noreply.github.com>
Monkeyanator pushed a commit to Monkeyanator/envoy that referenced this pull request Apr 20, 2021
…oxy#15198)

Adds a new filter that makes use of the new matching API to allow specifying a filter configuration to use for specific match
results. Once a configuration is selected, the desired filter is created and all callbacks delegated to the specific filter.

Risk Level: Low, new filter
Testing: IT + UT
Docs Changes: Inline proto comments

Signed-off-by: Snow Pettersen <snowp@lyft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants