最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Spring boot 3.4+ webclient reactive depracated metrics filter alternative - Stack Overflow

programmeradmin3浏览0评论

I have spring boot 3.4+ reactive webflux app

we have been using below config to get prometheus metrics (Spring Boot 2.x)

    private ExchangeFilterFunction metricsWebClientFilterFunction(String name) {
        log.info("Register filter function with name: {}", name);
        return new MetricsWebClientFilterFunction(meterRegistry, new DefaultWebClientExchangeTagsProvider(), name, AutoTimer.ENABLED);
    }

But due to new spring boot version with observability API this is not working anymore,

We have tried using below config

WebClient.builder()
                .observationRegistry(registry)
    

Also tried various NamingConventionConfig classes, @Observable but it doesn't help.

We need metrics populated like below

Correct

http_client_requests_seconds{error="none",status="200",uri="/endpoint/",quantile="0.9"} 0.0

We're getting unknown uri metrics like below

http_server_requests_active_seconds_bucket{exception="none",method="GET",outcome="SUCCESS",status="200",uri="UNKNOWN",le="274.877906944"} 1

I have spring boot 3.4+ reactive webflux app

we have been using below config to get prometheus metrics (Spring Boot 2.x)

    private ExchangeFilterFunction metricsWebClientFilterFunction(String name) {
        log.info("Register filter function with name: {}", name);
        return new MetricsWebClientFilterFunction(meterRegistry, new DefaultWebClientExchangeTagsProvider(), name, AutoTimer.ENABLED);
    }

But due to new spring boot version with observability API this is not working anymore,

We have tried using below config

WebClient.builder()
                .observationRegistry(registry)
    

Also tried various NamingConventionConfig classes, @Observable but it doesn't help.

We need metrics populated like below

Correct

http_client_requests_seconds{error="none",status="200",uri="/endpoint/",quantile="0.9"} 0.0

We're getting unknown uri metrics like below

http_server_requests_active_seconds_bucket{exception="none",method="GET",outcome="SUCCESS",status="200",uri="UNKNOWN",le="274.877906944"} 1
Share Improve this question edited Mar 11 at 12:34 donm asked Mar 11 at 12:09 donmdonm 1,2301 gold badge14 silver badges20 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

See this comment on GitHub from Brian: https://github/spring-projects/spring-framework/issues/30322#issuecomment-1597240920

Figured out a way to achieve similar metrics with spring boot 3.4+ with below configs

private final ObservationRegistry registry;
public WebClientConfig(ObservationRegistry registry) {
    this.registry = registry;
}
public WebClient webClient(String webClientName, String host) {
    HttpClient httpClient = configureHttpClient();
    return WebClient.builder()
            .baseUrl(host)
            .observationRegistry(registry)
            .observationConvention(new DefaultClientRequestObservationConvention(webClientName))
            .clientConnector(new ReactorClientHttpConnector(httpClient))
            .build();
}

And then in the connector class using below code to call external service where

@Autowired
@Qualifier("{qualifierName}")
private WebClient webClient;

@Value("${endpoint from yaml}")
private String endpoint;

public Mono<TargetType> getReq(Integer reqNumber) {
    return webClient.get()
            .uri(endpoint, reqNumber)
            .retrieve()
            .bodyToFlux(TargetType.class)
            .next()
}

This produces correct metrics with right URI including {reqNumber}, status, method

发布评论

评论列表(0)

  1. 暂无评论