Skip to content

lua: clear route cache if headers are modified in decode path#2093

Merged
htuch merged 3 commits intomasterfrom
lua_clear_route_cache
Nov 22, 2017
Merged

lua: clear route cache if headers are modified in decode path#2093
htuch merged 3 commits intomasterfrom
lua_clear_route_cache

Conversation

@mattklein123
Copy link
Copy Markdown
Member

This allows filters to modify headers such that the router will lookup
the route again.

Risk Level: Low

Testing: UT

Signed-off-by: Matt Klein <mklein@lyft.com>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Neat.

HeaderMapWrapper::create(state, headers_, [this]() { return !headers_continued_; }), true);
headers_wrapper_.reset(HeaderMapWrapper::create(state, headers_,
[this] {
// If we are about to do a modifiable header
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: How come clang-format makes so much indent, so much wow, here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah I don't know. It bothered me also but not sure what I can do about it. It seems like clang-format bug.

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.

OK, no worries.


TestHeaderMapImpl request_headers{{":path", "/"}};
EXPECT_CALL(*filter_, scriptLog(spdlog::level::trace, StrEq("/")));
EXPECT_CALL(decoder_callbacks_, clearRouteCache());
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.

Would a test to check that the reroute actually happens also be useful, or is it overkill?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The only way to do that would be to add a much more complex integration test. I could do it, but probably overkill IMO.

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, no worries, fine as is.

// higher, but this is simple and will get the
// job done for now. This is a NOP on the
// encoder path.
if (!headers_continued_) {
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.

Should this also be done in regular filters? I.e. is there a reason to make Lua behave non-uniform here, such as keeping is simple?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The reason is keeping it simple. It would be a more complex and performance sensitive change to do it in all filters. I can open an issue to track this idea if you like.

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.

Do we have a doc for filter authors that provides advice on how to do things like a rerouting filter? I think just capturing the idioms for Lua vs. C++ would be useful somewhere, issues is fine.

htuch
htuch previously approved these changes Nov 22, 2017
@htuch
Copy link
Copy Markdown
Member

htuch commented Nov 22, 2017

Do you think there could be a change to the filter API that could be done (probably in a followup PR or issue) to make it easier to learn if there has been route change?

Signed-off-by: Matt Klein <mklein@lyft.com>
@mattklein123
Copy link
Copy Markdown
Member Author

@htuch turns out it was pretty easy to add an integration test so I added one.

htuch
htuch previously approved these changes Nov 22, 2017
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Nice!

->mutable_match()
->set_prefix("/test/long/url");

auto new_route = hcm.mutable_route_config()->mutable_virtual_hosts(0)->add_routes();
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.

Very tiny nit: auto* new_route

@mattklein123
Copy link
Copy Markdown
Member Author

Do you think there could be a change to the filter API that could be done (probably in a followup PR or issue) to make it easier to learn if there has been route change?

What do you mean exactly? Like a callback if another filter changes the route?

@htuch
Copy link
Copy Markdown
Member

htuch commented Nov 22, 2017

More like, instead of returning continue, stop+buffer, etc., you could pass additional metadata back to HCM. It would be a bit more abstract/declarative, vs. the current situation where you have to map from (as filter author) "I made a route change, do something with it" to "I made a route change, aha, I need to clear the route cache.".

@mattklein123 mattklein123 mentioned this pull request Nov 22, 2017
2 tasks
@mattklein123
Copy link
Copy Markdown
Member Author

Right. OK. I opened #2097.

Over the holidays I'm going to explore adding the ability to write filters on a Coroutine style in C++. I will think about this during that work.

Signed-off-by: Matt Klein <mklein@lyft.com>
@mattklein123
Copy link
Copy Markdown
Member Author

@htuch updated again

@htuch htuch merged commit 369e63f into master Nov 22, 2017
@htuch htuch deleted the lua_clear_route_cache branch November 22, 2017 20:24
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
* add mixer error details into metadata

Signed-off-by: Lizan Zhou <lizan@tetrate.io>

* format

Signed-off-by: Lizan Zhou <lizan@tetrate.io>

* review

Signed-off-by: Lizan Zhou <lizan@tetrate.io>

* comment

Signed-off-by: Lizan Zhou <lizan@tetrate.io>
jpsim added a commit that referenced this pull request Nov 28, 2022
It was never safe to do a case-sensitive lookup, but this broke in
envoyproxy/envoy-mobile#2088 (comment).

Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit that referenced this pull request Nov 29, 2022
It was never safe to do a case-sensitive lookup, but this broke in
envoyproxy/envoy-mobile#2088 (comment).

Signed-off-by: JP Simard <jp@jpsim.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.

2 participants