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

Use unexpanded URI for Webclient metrics #474

Closed
ben-r opened this issue Jun 5, 2022 · 2 comments
Closed

Use unexpanded URI for Webclient metrics #474

ben-r opened this issue Jun 5, 2022 · 2 comments

Comments

@ben-r
Copy link

ben-r commented Jun 5, 2022

Client metrics are recorded based on expanded URI templates which creates a new time series for every new value encountered (cardinality explosion), which is harmful for time series based databases like Prometheus.

Example

@RequestLine("GET /api/test/{id}/response")
fun getRequest(@Param("id") id: String, @QueryMap params: Query): Mono<String> // id = 1; params = {"param": "hello"}

should produce a metric like
http_client_requests_seconds_count{uri="/api/test/{id}/response}

Instead it produces
http_client_requests_seconds_count{uri="/api/test/1/response?param=hello}

which makes it impossible to group metrics for this endpoint.

I didn't dig deeper into the code, but I'm pretty sure it goes into the same direction as this PR in the OpenFeign project: OpenFeign/feign#1493

The recommended way to build the request to achieve correct metrics looks like this

val id = 1
webClient
        .get()
        .uri("/api/test/{id}/response") { uriBuilder ->
            uriBuilder
                .queryParam("param", "hello")
                .build(id)

You can find a sample project showcasing the issue here: https://github.com/ben-r/reactive-feign-metrics-example

@kptfh
Copy link
Collaborator

kptfh commented Aug 3, 2022

Here is the micrometer metrics autoconfiguration that should fit you

@Bean
	@ConditionalOnMissingBean
	@ConditionalOnClass(name = "io.micrometer.core.instrument.MeterRegistry")
	@ConditionalOnProperty(name = "reactive.feign.metrics.enabled", havingValue = "true")
	public MicrometerReactiveLogger metricsReactiveLogger() {
		return MicrometerReactiveLogger.basicTimer();
	}

Check MicrometerReactiveLogger and MetricsTag for available tags

@kptfh
Copy link
Collaborator

kptfh commented Aug 3, 2022

Feel free to reopen issue if we need to tune MicrometerReactiveLogger

@kptfh kptfh closed this as completed Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants