[BUG][Java][spring][webclient] webclient metrics contains actual query parameters, resulting in OOM
Created by: cdmatta
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Generate the spring webclient implementation for an open api endpoint which is using query parameters. Use the generated ApiClient to make calls to the endpoint with different query parameters in a spring webflux application (with micrometer metrics).
Check the uri tag for the metric http_client_requests. This uri tag contains the query parameter. This will continue to grow as different values are used. Eventually, leading to an OutOfMemory error.
openapi-generator version
openapi-generator version: 4.3.1
This is not a regression.
OpenAPI declaration file content or url
This can be reproduced with the sample petstore fake endpoints yaml file in the project
Steps to reproduce
- Generate the spring webclient implementation for the yaml
- Use it in a Spring boot project with actuator and metrics
- Call the endpoint with query parameters
Actual
Expected
- Query parameters values must not be present in the metrics.
Suggest a fix
Solution for this is available in spring framework 5.2 webclient
I could provide a PR, but that means the minimum required version of spring framework will be 5.2. Or, we need to make rules in the template to add the following code on spring 5.2+ only, hence leaving it for you to decide.
Here is the fix to the ApiClient.mustache template required to fix this. webclient-ApiClient.patch.txt
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache
index 98f4bfb2..080b6fbd 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache
@@ -564,11 +564,13 @@ public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
updateParamsForAuth(authNames, queryParams, headerParams, cookieParams);
final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath).path(path);
- if (queryParams != null) {
- builder.queryParams(queryParams);
- }
- final WebClient.RequestBodySpec requestBuilder = webClient.method(method).uri(builder.build(false).toUriString(), pathParams);
+ final WebClient.RequestBodySpec requestBuilder = webClient.method(method).uri(builder.build(false).toUriString(), uriBuilder -> {
+ if (queryParams == null) {
+ return uriBuilder.build(pathParams);
+ }
+ return uriBuilder.queryParams(queryParams).build(pathParams);
+ });
if(accept != null) {
requestBuilder.accept(accept.toArray(new MediaType[accept.size()]));
}