-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Improve query params in uri KeyValue with HTTP interface client #34176
Comments
Hi Florian, @Override
public RequestBodySpec uri(String uriTemplate, Map<String, ?> uriVariables) {
UriBuilder uriBuilder = uriBuilderFactory.uriString(uriTemplate);
attribute(URI_TEMPLATE_ATTRIBUTE, uriBuilder.toUriString());
return uri(DefaultRestClient.this.uriBuilderFactory.expand(uriTemplate, uriVariables));
} This is where the URI_TEMPLATE_ATTRIBUTE is set, and the only place it's used is for metrics in observatonContext. @Override
public RequestBodySpec uri(String uriTemplate, Map<String, ?> uriVariables) {
TemplateBuilder templateBuilder = templateBuilderFactory.uriTemplateWithVars(uriTemplate, uriVariables); // new template builder instead of uriBuilder
attribute(URI_TEMPLATE_ATTRIBUTE, templateBuilder.toUriString());
return uri(DefaultRestClient.this.uriBuilderFactory.expand(uriTemplate, uriVariables));
} With this approach the URI_TEMPLATE_ATTRIBUTE would look like /api/response/{id}?bar={bar} instead of /api/response/{id}?{queryParam0}={queryParam0[0]}. @bclozel Do you think this feature is necessary? If so, I'd be happy to contribute and implement it. |
uri
tag handling of query parameters
Thanks for the report @cj-florian-akos-szabo - I have reproduced this successfully with the HTTP interface client support. This does not happen when using the The HTTP interface client support creates proxies that look at interface method signatures and create the relevant HTTP requests accordingly. In this case, the There are several key aspects to consider here:
I have prepared a commit that will change the generated URI templates to:
This still adds a bit of ceremony but this should work. I have considered changing the implementation to producing |
Prior to this commit, the HTTP interface client would create URI templates and name query params like so: "?{queryParam0}={queryParam0[0]}". While technically correct, the URI template is further used in observations as a KeyValue. This means that several service methods could result in having the exact same URI template even if they produce a different set of query params. This commit improves the naming of query params in the generated URI templates for better observability integration. Closes spring-projectsgh-34176
Thanks @bclozel for the quick turnaround on this issue, and for reproducing the issue locally. In hindsight, I could have provided more originally to help with that part of the effort. With this change you implemented, do I get it right that it would also affect and fix this for WebClient, since |
No worries your issue was complete enough. Yes, this should cover WebClient as well. You can test SNAPSHOT versions if you would like to ensure that this is working for you before the release. |
I have a project where I noticed a behavior in the
http.client.requests
metric coming fromRestClient
that's defined via such interface:resulting in
http.client.requests
metric with suchuri
tags:depending on how many of the optional query params are non-null.
My issue is mainly with the cryptic names of the query params:
queryParam0
&queryParam1
. Could it be somehow possible to default these to use thename
orvalue
passed in theRequestParam
annotation, and only use these basic placeholder names if custom name/value is not available? So in this case I'd expect theuri
tag to include such items:And currently, to work around this issue I am considering adding such a custom ClientRequestObservationConvention when I build the RestClient:
The text was updated successfully, but these errors were encountered: