Skip to content

feat(router): keep query string by default for redirects#11493

Merged
mattklein123 merged 11 commits intoenvoyproxy:masterfrom
knight42:feat/path-redirect-keep-query
Jun 29, 2020
Merged

feat(router): keep query string by default for redirects#11493
mattklein123 merged 11 commits intoenvoyproxy:masterfrom
knight42:feat/path-redirect-keep-query

Conversation

@knight42
Copy link
Copy Markdown
Contributor

@knight42 knight42 commented Jun 8, 2020

Signed-off-by: knight42 anonymousknight96@gmail.com

Commit Message: leave query string intact by default(strip_query: false) when performing path redirect.

Additional Description:
I think the current behavior(stripping query by default) is not aligned with the documentation. From the documentation of path_redirect and strip_query field, I am under the impression that query portion is not considered part of path portion. Additionally, even if we want to strip query for path redirects, we can simply set strip_query to true.

Risk Level:
Testing: unit test
Docs Changes:
Release Notes: query string is not stripped by default for path redirects

Fixes #11443

@knight42
Copy link
Copy Markdown
Contributor Author

knight42 commented Jun 8, 2020

/cc @snowp

@knight42 knight42 force-pushed the feat/path-redirect-keep-query branch from f9511e0 to 92091ae Compare June 8, 2020 12:33
Copy link
Copy Markdown
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Thanks! I left a couple comments. Mostly I think we need to carefully consider how this impacts existing configurations.

Also, the release notes section of the pull request template is primarily a prompt to remind developers to consider whether release notes in docs/root/version_history/current.rst need to be updated. I do think we should have a release note for this change. More details are in the PULL_REQUESTS.md file.

Comment thread source/common/router/config_impl.cc Outdated
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.

I think this would be a bit easier to follow if current_path was just declared and used within the !path_redirect_.empty() block.

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.

if path_redirect_ is empty, we would need to set final_path to current_path.

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.

I'm suggesting that in that final else block you can just use final_path = headers.getPathValue(); and then move the declaration of current_path to just before it's remaining uses.

Comment thread source/common/router/config_impl.cc Outdated
@knight42 knight42 force-pushed the feat/path-redirect-keep-query branch from 92091ae to f834250 Compare June 10, 2020 06:53
@knight42 knight42 requested a review from zuercher June 10, 2020 06:57
@knight42 knight42 force-pushed the feat/path-redirect-keep-query branch 2 times, most recently from a53dd16 to 2fd7dd3 Compare June 11, 2020 03:29
Copy link
Copy Markdown
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

I think the changes in the router look good modulo some changes around comments.

We should document the relationship between path_redirect and strip_query in api/envoy/api/v2/route/route_components.proto and api/envoy/config/route/v3/route_components.proto. Basically that path_redirect with a query string overrides strip_query. I believe you'll need to run tools/proto_format/proto_format.sh fix to update some generated code or you'll get CI errors.

Please avoid force pushes unless you're fixing a DCO error -- it sometimes causes github to lose track of comments and makes changes harder to follow. We always squash commits to master so the final git history will be clean.

Comment thread source/common/router/config_impl.cc Outdated
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.

Let's remove this comment.

I do think it's worth having a brief note near here that explains that the path_redirect_ query string, if any, takes precedence over the request's query string.

@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy[\w/]*/(v1alpha\d?|v1|v2alpha\d?|v2))|(api/envoy/type/(matcher/)?\w+.proto).
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/.
CC @envoyproxy/api-watchers: FYI only for changes made to api/.

🐱

Caused by: #11493 was synchronize by knight42.

see: more, trace.

@knight42 knight42 requested a review from zuercher June 12, 2020 06:13
@knight42
Copy link
Copy Markdown
Contributor Author

@zuercher really grateful to your detailed guidance! I have updated the comments, please check again.

Copy link
Copy Markdown
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Sorry. Noticed one more thing. But we have to wait for api shepherds to tag this as approved, anyway.

Comment thread source/common/router/config_impl.cc Outdated
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.

Last pass. I should have realized this earlier, but the value we compute for this variable never changes for a given instance of RouteEntryImplBase. I think this should become a const member variable of RouteEntryImplBase. It'll save us a string search on every request that hits a path redirect.

Comment thread source/common/router/config_impl.cc Outdated
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.

If we have path_redirect_has_query_ we can also split this if statement and skip searching headers.getPathValue() for a ? when we know we're not going to use it.

@knight42 knight42 force-pushed the feat/path-redirect-keep-query branch from a258584 to 2a867e5 Compare June 14, 2020 16:51
@knight42 knight42 requested a review from zuercher June 14, 2020 16:51
@knight42
Copy link
Copy Markdown
Contributor Author

@zuercher that's ok. should I ping someone?

zuercher
zuercher previously approved these changes Jun 15, 2020
Copy link
Copy Markdown
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

cc @envoyproxy/api-shepherds this PR has some comment-only changes to v2 to clarify the change in behavior

@htuch
Copy link
Copy Markdown
Member

htuch commented Jun 16, 2020

/lgtm v2-freeze
/lgtm api

@zuercher
Copy link
Copy Markdown
Member

@mattklein123 do you want a second look at this?

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 a few questions/comments.

/wait

Comment on lines 1180 to 1181
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 some examples here (make sure to add the examples to v3 also)? I've been looking at this for a few minutes and I'm a little confused as to what the current behavior is and what is changing.

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.

Currently the request's query string will be stripped regardless of the value of strip_query.

With this patch, envoy would only strip the request's query string if path_redirect doesn't contain query string and strip_query is set to true.
If path_redirect contains query string, users will be redirected to the specified path with query string no matter what the value of strip_query is.

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.

Thanks can you add some actual examples of real paths and what happens to them?

Comment thread docs/root/version_history/current.rst Outdated
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.

I think even if we think this is the right thing to do, this needs to be runtime guarded (default can be on). Can you please add a runtime feature flag for this?

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.

I am not sure how to add a runtime feature flag and what its name should be, could you please provide an example?

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.

Comment thread source/common/router/config_impl.cc Outdated
Comment on lines 436 to 441
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.

If we have a runtime guard do we need this warning? Should this potentially just be a failure? Again I'm confused as to the behavior.

Comment thread source/common/router/config_impl.cc Outdated
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
// the path_redirect query string, if any, takes precedence over the request's query string,
// The path_redirect query string, if any, takes precedence over the request's query string,

Comment thread source/common/router/config_impl.cc Outdated
Comment on lines 682 to 684
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: const for all

@knight42
Copy link
Copy Markdown
Contributor Author

@mattklein123 do you think I should add a test for the previous behavior(always strip the request's query string)?

knight42 added 8 commits June 28, 2020 19:27
Signed-off-by: knight42 <anonymousknight96@gmail.com>
Signed-off-by: knight42 <anonymousknight96@gmail.com>
Signed-off-by: knight42 <anonymousknight96@gmail.com>
Signed-off-by: knight42 <anonymousknight96@gmail.com>
Signed-off-by: knight42 <anonymousknight96@gmail.com>
Signed-off-by: knight42 <anonymousknight96@gmail.com>
Signed-off-by: knight42 <anonymousknight96@gmail.com>
Signed-off-by: knight42 <anonymousknight96@gmail.com>
@knight42 knight42 force-pushed the feat/path-redirect-keep-query branch from d4ad4ec to 2c28b44 Compare June 28, 2020 11:30
@repokitteh-read-only
Copy link
Copy Markdown

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

🐱

Caused by: #11493 was synchronize by knight42.

see: more, trace.

Signed-off-by: knight42 <anonymousknight96@gmail.com>
@knight42 knight42 force-pushed the feat/path-redirect-keep-query branch from 2c28b44 to 73e3734 Compare June 28, 2020 11:30
@knight42
Copy link
Copy Markdown
Contributor Author

force push to rebase and resolve conflicts.

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.

Thank you makes total sense to me now. Just a few small comments. Also friendly request to please never force push as it breaks reviews. Please just merge main and add commits. Thanks!

/wait

Comment thread source/common/router/config_impl.cc Outdated
Comment on lines +676 to +677
if (Runtime::runtimeFeatureEnabled(
"envoy.reloadable_features.preserve_query_string_in_redirects")) {
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.

Is it possible to not check this twice since you check it during route load? It might not be consistent then. Can we latch the expected behavior in the constructor?

redirect: { host_redirect: new.lyft.com }
- match: { path: "/path/redirect/"}
redirect: { path_redirect: "/new/path-redirect/" }
- match: { path: "/path/redirect/strip-query/true"}
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.

We should have tests for the runtime override set to false also.

knight42 added 2 commits June 29, 2020 16:54
Signed-off-by: knight42 <anonymousknight96@gmail.com>
Add tests for turning off feature `envoy.reloadable_features.preserve_query_string_in_path_redirects`.

Signed-off-by: knight42 <anonymousknight96@gmail.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.

Thank you!

@mattklein123 mattklein123 merged commit 89d6c6c into envoyproxy:master Jun 29, 2020
@knight42 knight42 deleted the feat/path-redirect-keep-query branch June 30, 2020 03:05
aimless404 pushed a commit to aimless404/envoy that referenced this pull request Jun 30, 2020
…11493)

Signed-off-by: knight42 <anonymousknight96@gmail.com>
Signed-off-by: Yifan Yang <needyyang@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

keep query string by default when performing http path_redirect

5 participants