Skip to content

WebClient's URI_TEMPLATE_ATTRIBUTE ignored by MicrometerStatsLoadBalancerLifecycle #1302

Closed
@JaroslawDembek

Description

@JaroslawDembek

Version: 4.0.4

Problem

When spring.cloud.loadbalancer.stats.micrometer.enabled: true using WebClient with loadbalancing can lead to generation of huge number of metrics when path contains params, e.g. /test/{somePerCallId}/... what eventually with high workload can cause even OOM.

Common approach

Spring metrics collectors for WebClient uses URI_TEMPLATE_ATTRIBUTE (which contains placeholder instead of actual param value) to overcome problem mention above.

Solution:

Make MicrometerStatsLoadBalancerLifecycle URI_TEMPLATE_ATTRIBUTE aware.
Now this logic is hidden in LoadBalancerTags utility class.

private static String getPath(RequestData requestData) {
     return requestData.getUrl() != null ? requestData.getUrl().getPath() : UNKNOWN;
}

Possibly MicrometerStatsLoadBalancerLifecycle could be aware of client type.

Alternative:

Set spring.cloud.loadbalancer.stats.micrometer.enabled: false and deliver you own metrics collector as bean implementing LoadBalancerLifecycle to override LoadBalancerTags.getPath with e.g.

private static String getPath(RequestData requestData) {
   if (requestData.getAttributes() != null) {
	var uriTemplate = (String) requestData.getAttributes().get(URI_TEMPLATE_ATTRIBUTE);
	if (uriTemplate != null) {
		return uriTemplate;
	}
  }
  return requestData.getUrl() != null ? requestData.getUrl().getPath() : UNKNOWN;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions