Skip to content

routing: enable routing on query arg match (#2120)#2258

Merged
htuch merged 4 commits intoenvoyproxy:masterfrom
brian-pane:query-routing
Dec 24, 2017
Merged

routing: enable routing on query arg match (#2120)#2258
htuch merged 4 commits intoenvoyproxy:masterfrom
brian-pane:query-routing

Conversation

@brian-pane
Copy link
Copy Markdown
Contributor

Signed-off-by: Brian Pane bpane@pinterest.com

Description:
This change support route selection based on request query string parameters,
implementing the API changes in data-plane-api commit 05384e0.

Risk Level: Medium

Testing:
New unit tests are included in this PR.

Brian Pane added 2 commits December 22, 2017 02:14
Signed-off-by: Brian Pane <bpane@pinterest.com>
Signed-off-by: Brian Pane <bpane@pinterest.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.

Generally looks good, thanks for the contribution.

envoy::api::v2::HeaderMatcher& header_matcher);

/**
* Translate a v1 JSON header matcher object to v2 envoy::api::v2::QueryParameterMatcher.
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: s/header matcher/query parameter matcher/

if (end == std::string::npos) {
end = url.size();
}
auto param = StringUtil::subspan(url, start, end);
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: absl::string_view might be more efficient.

regex_pattern_(value_, std::regex::optimize),
is_regex_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, regex, false)) {}

const std::string name_;
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 some of the inner logic in ConfigUtility::matchQueryParams be moved to a method here?

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.

Sounds good; I've just posted an update that encapsulates the logic in this object. We should probably do the same with struct HeaderData and ConfigUtility::matchHeaders, but I'll make a separate PR for that.

…cient, and improve the encapsulation of QueryParameterMatcher.

Signed-off-by: Brian Pane <bpane@pinterest.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.

Rad, looks good to go after comments.

}

matches &= ConfigUtility::matchHeaders(headers, config_headers_);
if (config_query_parameters_.size() != 0) {
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: if (!config_query_parameters_.empty()) {

absl::string_view param(url.c_str() + start, end - start);

size_t equal = url.find('=', start);
size_t equal = param.find('=');
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 size_t equal = ...

}

{
Http::TestHeaderMapImpl headers = genHeaders("example.com", "/?param=test", "GET");
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 test for multiple query params?

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 put a couple of multi-param tests a bit later in config_impl_test.cc: all parameters match and proper subset of parameters match.

if (end == std::string::npos) {
end = url.size();
}
absl::string_view param(url.c_str() + start, end - start);
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 the idea here to avoid a bug where we could see for the = beyond the next query param? If so, can you add a test 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.

Yes, prior to this, parseQueryString had a bug whereby it would interpret x&y=z as having two key-value variables:

  • key=y, value=z
  • key=x&y, value=z

This PR contains a test for that, on line 1079 of config_impl_test.cc.

Signed-off-by: Brian Pane <bpane@pinterest.com>
@htuch htuch merged commit 0663cbe into envoyproxy:master Dec 24, 2017
@brian-pane brian-pane deleted the query-routing branch January 25, 2018 21:59
jpsim added a commit that referenced this pull request Nov 28, 2022
This pulls in #21070 to update
bazel to `6.0.0-pre.20220414.2` which is the second-most recent 6.x
rolling release.

Bazel release: https://github.com/bazelbuild/bazel/releases/tag/6.0.0-pre.20220414.2
Diff: f17b32f...efbbb04

Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit that referenced this pull request Nov 29, 2022
This pulls in #21070 to update
bazel to `6.0.0-pre.20220414.2` which is the second-most recent 6.x
rolling release.

Bazel release: https://github.com/bazelbuild/bazel/releases/tag/6.0.0-pre.20220414.2
Diff: f17b32f...efbbb04

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