question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][Java][spring][webclient] webclient metrics contains actual query parameters, resulting in OOM

See original GitHub issue

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

/fake/body-with-query-params

Steps to reproduce
  1. Generate the spring webclient implementation for the yaml
  2. Use it in a Spring boot project with actuator and metrics
  3. Call the endpoint with query parameters

Actual

  • Query parameter values are present in the http_client_requests metric Screenshot from 2020-11-08 13-17-35

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()]));
         }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
admoca60commented, Jun 30, 2021

Go ahead!! Maybe your solution could be very familiar for me!!! xD

1reaction
admoca60commented, Dec 2, 2020

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

Maybe the right label should be “Client: Spring” because this affect to the client. The client can be used in a Server (with Spring obviously) or in Batch process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring WebClient Requests with Parameters - Baeldung
Learn how to reactively consume REST API endpoints with WebClient from Spring Webflux.
Read more >
Expose Metrics of Spring WebClient using Spring Boot Actuator
Learn how to expose metrics of your HTTP client using Spring WebClient: e.g. request URI, response codes, duration of request...
Read more >
reactor/reactor-netty - Gitter
Quick question, i have configured webclient(keepalive, readtimeout, writetimeout handler etc) for outbound traffic but nothing done from inbound connections.
Read more >
Agile Product Lifecycle Management - Oracle Help Center
Manuals in both Agile Web Client and Agile Java Client. ... Bug ID 13478875: SEARCH ON LIST VALUES CONTAINING SPECIAL CHARACTER.
Read more >
Challenges & Solutions for Migrating Java Apps to Reactive
During a recent innovation sprint at Capital One, my coworker and I migrated one of our team's Spring Boot applications to use WebFlux....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found