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

[BUG][JAVA] ApiClient is not compatible with spring-web 6 Observation API #15143

Closed
ferblaca opened this issue Apr 6, 2023 · 1 comment · Fixed by #15421
Closed

[BUG][JAVA] ApiClient is not compatible with spring-web 6 Observation API #15143

ferblaca opened this issue Apr 6, 2023 · 1 comment · Fixed by #15421

Comments

@ferblaca
Copy link

ferblaca commented Apr 6, 2023

Description

We have detected an issue related to the openapi-generator client and the spring-web 6 Observation API introduced in spring-boot 3.

The problem is that the generated ApiClient class, in the invokeAPI method when creating the BodyBuilder with the RequestEntity.method(method, uri) method, without params overloading, so that the uriTemplate field of the BodyBuilder object is always null.

On the other hand, the spring-web 6 Observation API gets the keyValue URI, with which the uri TAG of the http_client_requests metric is given value, for the uriTemplate value of the response. As the uriTemplate is null, the uri TAG always has the value NONE.

openapi-generator version
  • Openapi-generator 6.5.0
  • Spring-Web 6.0.7
  • Spring-boot 3.0.5
OpenAPI declaration file content or url
Generation Details

Modifying the original ApiClient.mustache template so that the requestBuilder is created based on the URI passing the arguments to resolve with the method:

final BodyBuilder requestBuilder requestBuilder = RequestEntity.method(method, UriComponentsBuilder.fromHttpUrl(basePath).toUriString() + finalUri, uriParams);

with this method if the TemplateURI fields are set and therefore from the Observation API if it is able to retrieve it and add it with TAG to the http.client.request metrics.

Currently the ApiClient generated with openapi-generator always uses the method:

final BodyBuilder requestBuilder requestBuilder = RequestEntity.method(method, uri);

where uri is the URL already resolved with the arguments and the request will never report the TemplateUri field.

Steps to reproduce

I have left a demo here where you can reproduce it with the following steps:

  1. mvn clean install
  2. Start the application
  3. Invoke the endpoint http://localhost:8080/app-rest/invoke-api-client-templatized
  4. Display the metrics generated by the Prometheus endpoint http://localhost:8080/actuator/prometheus

As can be seen, the generated http_client_requests metrics always have the tag uri="none", when they should have the request path: /pet2/{petId}.

 HELP http_client_client_requests_seconds  
# TYPE http_client_requests_seconds summary
http_client_requests_seconds_count{client_name="localhost",error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="none",} 1.0
http_client_requests_seconds_sum{client_name="localhost",error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="none",} 0.139118975
# HELP http_client_requests_seconds_max  
# TYPE http_client_requests_seconds_max gauge
http_client_requests_seconds_max{client_name="localhost",error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="none",} 0.139118975
Related issues/PRs
Suggest a fix

Modify the original ApiClient.mustache template with:

final BodyBuilder requestBuilder requestBuilder = RequestEntity.method(method, UriComponentsBuilder.fromHttpUrl(basePath).toUriString() + finalUri, uriParams);

instead:

final BodyBuilder requestBuilder requestBuilder = RequestEntity.method(method, uri);
@mystarrocks
Copy link

mystarrocks commented Oct 16, 2023

This change makes the v6.6.0 incompatible with Spring 5.x. What's the recommendation if a Spring upgrade isn't viable — fall back to a previous version of the generator or use a custom template? Are there any other options?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants