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

Adding QueryParam matching to HTTPRoute #631

Merged
merged 1 commit into from
Apr 27, 2021

Conversation

robscott
Copy link
Member

What type of PR is this?
/kind feature
/kind api-change

What this PR does / why we need it:
This adds query param matching to HTTPRoute

Which issue(s) this PR fixes:
Fixes #259

Does this PR introduce a user-facing change?:

HTTPRoute now supports matching query parameters

/cc @bowei @danehans @hbagdi @jpeach @youngnick

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 23, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: robscott

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 23, 2021
Copy link
Contributor

@hbagdi hbagdi left a comment

Choose a reason for hiding this comment

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

We should get more eyes on this before this lands in.
Overall, this looks good and is in the right direction. Thanks for your work on this!

apis/v1alpha1/httproute_types.go Outdated Show resolved Hide resolved
apis/v1alpha1/httproute_types.go Outdated Show resolved Hide resolved
// QueryParamMatchType constants.
const (
QueryParamMatchExact HeaderMatchType = "Exact"
QueryParamMatchPresence HeaderMatchType = "Presence"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not very familiar with query parameter matching myself, is Presence a commonly supported or asked one?

Copy link
Contributor

Choose a reason for hiding this comment

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

https://www.envoyproxy.io/docs/envoy/latest/operations/admin#post--drain_listeners is one example in the wild where a Presence could be useful?

It does seem inconsistent with Header at least.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be more clear, I mean there should probably be one common way to describe this in the API. So add Presence to Header or do something else, but they should be consistent.

I think you could express it with regex of "" possibly.

For a prior art, Istio has ~everything as the same StringMatch type: https://istio.io/latest/docs/reference/config/networking/virtual-service/#StringMatch

Copy link
Contributor

Choose a reason for hiding this comment

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

So add Presence to Header or do something else, but they should be consistent.

But then Presence as PathType makes little sense.
I think it is okay to have different match types for different metadata pieces like query string, header, path, etc because they have different properties and uses.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree they don't need to be the exact same type, but they should be consistent where it makes sense? Presence in path definitely would be odd. I see headers and query params as pretty similar so I would envision them having the same options

Copy link
Contributor

Choose a reason for hiding this comment

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

they should be consistent where it makes sense?

We need to dig deeper into what consistency means here.

I agree that they should be consistent for the end-user - kubectl user, meaning having a RegularExpression match on path/header/query param should do the same thing and not surprise the user.
For the implementers, I think having separate Go types and different subsets is okay and good because that makes this API (our go package) easy to use.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that makes sense, I'm fine with dropping Presence from this PR to keep it smaller in scope. We can add it later to both if there's interest.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was only talking about the yaml API surface. Whether we use a single or different go type I don't have a strong opinion, dedicated types seems reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep agree that we should still use separate Go types, kept those in place while dropping "Presence"

// Please read the implementation's documentation to determine the supported
// dialect.
//
// HTTP query parameter matching MUST be case-sensitive.
Copy link
Contributor

Choose a reason for hiding this comment

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

Both key and value? If yes, let's be precise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, clarified that both key and value should be case-sensitive. This is based on the following guidance from the RFC (emphasis mine):

The scheme and host are case-insensitive and normally provided in lowercase; all other components are compared in a case-sensitive manner.

https://tools.ietf.org/html/rfc7230#page-19

Copy link
Contributor

Choose a reason for hiding this comment

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

Case-sensitive is a source of confusion and conflict usually, although I'm not sure how much of that is a problem with query param matching.
Can we include the link to the RFC and mention the section which states the case-sensitiveness?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in #636

@hbagdi
Copy link
Contributor

hbagdi commented Apr 27, 2021

Looks good to me.
We should merge with one or two more +1 given how core this is.

Copy link
Contributor

@youngnick youngnick left a comment

Choose a reason for hiding this comment

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

/lgtm

with a couple of small doc nits, just to head off incompatible implementations before we end up there.

Type *QueryParamMatchType `json:"type,omitempty"`

// Values is a map of HTTP query parameters to be matched. It MUST contain
// at least one entry.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: If this must contain at least one entry, should we set the validation minimum?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately it does not look like it's possible to validate that with annotations. It does seem like something we should catch with the webhook though (for both this and header matching).

// query parameter is the map value.
//
// Multiple match values are ANDed together, meaning, a request must match
// all the specified query parameters to select the route.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I feel like we should be clear that, even if you specify one of the ImplementationSpecific matches, we shouldn't allow regexes or other craziness in the query param name, just the value?

Something like:

Suggested change
// all the specified query parameters to select the route.
// all the specified query parameters to select the route.
//
// Note that the query param type matching MUST only be used for the query param value, not the query param name.

Copy link
Contributor

Choose a reason for hiding this comment

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

More direct would be (don't refer to param matching type to avoid indirection):

Query parameter key is must be an exact match (string comparison).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call, added in #636

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 27, 2021
@k8s-ci-robot k8s-ci-robot merged commit 980552d into kubernetes-sigs:master Apr 27, 2021
robscott added a commit to robscott/gateway-api that referenced this pull request Apr 28, 2021
This is a small follow up to kubernetes-sigs#631 that addresses some of the tiny nits
that were leftover on that PR.
robscott added a commit to robscott/gateway-api that referenced this pull request Apr 28, 2021
This is a small follow up to kubernetes-sigs#631 that addresses some of the tiny nits
that were leftover on that PR.

// QueryParamMatchType constants.
const (
QueryParamMatchExact QueryParamMatchType = "Exact"
Copy link
Contributor

@jpeach jpeach Apr 28, 2021

Choose a reason for hiding this comment

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

These need godoc comments for the generated API reference.

@robscott robscott deleted the query-params branch January 8, 2022 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Query Param Matching
7 participants