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

http: add ability to add/remove query parameters #33977

Closed

Conversation

derekargueta
Copy link
Member

Commit Message: Add ability to add/remove query parameters.
Additional Description:
Risk Level: Low
Testing: Included
Docs Changes: Included
Release Notes: Included
Platform Specific Features: N/A
Fixes: #2098

Signed-off-by: Derek Argueta darguetap@gmail.com

Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @mattklein123
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #33977 was opened by derekargueta.

see: more, trace.

Signed-off-by: Derek Argueta <darguetap@gmail.com>
@derekargueta
Copy link
Member Author

derekargueta commented May 7, 2024

some TODOs I'd like to get into this PR:

  • support command substitution, e.g. populate query params with request header value, environment variable, metadata, etc.
  • looks like we probably want the same APPEND/OVERWRITE-type options as header manipulation so there's clearly defined behavior if you add a query parameter and value(s) for it already exist

@wbpcode
Copy link
Member

wbpcode commented May 8, 2024

Rather than to implement this in our core code path (and core route API), considering we have a full featured L7 filter chain, I will prefer to implement this in a filter like header_mutation.

/wait-any

@wbpcode wbpcode self-assigned this May 8, 2024
@derekargueta
Copy link
Member Author

@wbpcode I had asked about that here as I began working on this: #2098 (comment)

@derekargueta
Copy link
Member Author

I don't disagree though, if that's the desired direction I can pivot.

@wbpcode
Copy link
Member

wbpcode commented May 8, 2024

@derekargueta sorry, I forgot to check the original issue and related comments and different maintainers may have different ideas.

IMO, I will still recommend to implement it as part of HTTP filter. (I think you can implement it the exist header_mutation filter directly, because the envoy treat the query as part of :path header, you can wrap these query change as one single header evaluator). Here are my reasons:

  1. The route is fairly complex. (I think I shared same idea with you in this point).
  2. The issue was opened at 2017. It's almost 7 years ago. I agree it's a reasonable requirement, but I will assume it's not a very common requirement or most users may have their own solutions. It would be better to implement it in our extensions rather the core code base.

cc @mattklein123 for more inputs.

@derekargueta
Copy link
Member Author

derekargueta commented May 8, 2024

@wbpcode no worries! yeah after sleeping on it another advantage that came to mind might be ability to modify query parameters before/after certain filters. I don't have a concrete use-case in mind but might be useful to add parameters after certain operations e.g. auth/rate-limiting to compose higher level functionality by controlling the order of filters.

I think you can implement it the exist header_mutation filter directly

interesting thought, I was initially thinking of just a new query_parameter_mutation filter since, while it is technically a :path header I feel path is generally thought of as its own construct in a request but you're right

@mattklein123
Copy link
Member

I don't feel that strongly about it. If you both feel it would be better to do it as a filter that is fine with me. I just figured all the rest of this stuff is already in the router but this doesn't have to be.

Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
@wbpcode
Copy link
Member

wbpcode commented Jun 14, 2024

See #34550 for our latest common API for all these map-like mutations. :)

To use the new common API, I think you only need only to change the type of proto and needn't much change to the code.

Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Copy link
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Oh, thanks for the update. Some comments to the API is added.

bytes value = 2;
string value = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Please no. bytes is used here by design.

Copy link
Member Author

@derekargueta derekargueta Jul 11, 2024

Choose a reason for hiding this comment

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

doh, left an unsent github comment. I was wondering about the use of bytes? IIUC this makes command substitution a no-go which is the primary use-case I have in mind (appending a query param from metadata). It also seems inconsistent - elsewhere I see an option for a value string and a raw_value bytes.

Copy link
Member

Choose a reason for hiding this comment

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

IIUC this makes command substitution a no-go which is the primary use-case I have in mind (appending a query param from metadata).

The bytes is used to support non-UTF8. But I think it's also OK to use it as a command formatter for Envoy. But it may not be Okay for non-C++ xDS clients.

@htuch WDYT? should we use string value as value with command formatter and use bytes value as raw value?

Copy link
Member

@htuch htuch Jul 16, 2024

Choose a reason for hiding this comment

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

Strings/bytes on the wire are identical. How we opt to use them then comes down to the Envoy implementation. Can you elaborate on how "command substitution" is working here? It looks like regular header or parameter append operation etc.

Copy link
Member

@wbpcode wbpcode Jul 23, 2024

Choose a reason for hiding this comment

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

It's same as the HeaderValue message. The value field may be a string with substitution formatter like %REQ(CUSTOM-KEY)%. bytes should be fine for C++ xDS client like Envoy in this scenario, because bytes and string has no essential difference in C++. But not sure if it's OK for non-C++ client, like go gRPC proxy.

cc @htuch

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +42 to +45
const auto value_option = mutation.append();
const auto key = value_option.entry().key();
const auto value = value_option.entry().value();
const auto formatter = std::make_unique<Formatter::FormatterImpl>(value, true);
Copy link
Member

Choose a reason for hiding this comment

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

Please initialize the formatter when loading configuration to avoid do this at runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

The formatter needs the value?

Copy link
Member

@wbpcode wbpcode Jul 16, 2024

Choose a reason for hiding this comment

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

Yeah, you need to parse the value when you constructing QueryParamsEvaluator. Creating the formatter will bring big overhead and my throw exception. It's not allowed to do that at key data path.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is problem is still not be resolved.

We should load/create the formatter when loading configuration.

You can take the header mutations implemention as an example.

/lgtm api

/wait

Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
@wbpcode
Copy link
Member

wbpcode commented Jul 16, 2024

/wait

Signed-off-by: Derek Argueta <darguetap@gmail.com>
@soulxu
Copy link
Member

soulxu commented Aug 2, 2024

@wbpcode gentle ping, also @derekargueta it seems need a merge with main also

@wbpcode
Copy link
Member

wbpcode commented Aug 2, 2024

I have to say sorry to the @derekargueta .

Now, this is blocked by the API. We may did incorrect decision in past about the API.

And I will try give a final conclusion next week early.

@wbpcode
Copy link
Member

wbpcode commented Aug 8, 2024

/wait-any

Temporary label and well update it tomorrow.

Copy link

github-actions bot commented Sep 8, 2024

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale stalebot believes this issue/PR has not been touched recently label Sep 8, 2024
Copy link

This pull request has been automatically closed because it has not had activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot closed this Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale stalebot believes this issue/PR has not been touched recently waiting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Support adding/removing query params
7 participants