prometheusmetricsdropwizardspring-webclientreactor-netty

Is it feasible to publish metrics for Reactor-Netty more on connections?


In one of our spring-reactive projects, I exposed the default HTTP-Client metrices. This gives me some insider information about upstream. But, now I need a breakdown of the response time as we see in Postman. I would like to know if it is possible to expose it using the current implementation or through a third-party library.

Here I have attached a piece of code, through which I am exposing some WebClient attributes.

            HttpClient client = HttpClient.create(ConnectionProvider.builder("fixed")
                        .maxConnections(700)
                        .maxIdleTime(Duration.ofMillis(config.getPoolMaxIdleTime()))
                        .maxLifeTime(Duration.ofMillis(config.getPoolMaxLifeTime()))
                        .metrics(true) //metrices exposed here
                        .build())
                .option(ChannelOption.SO_TIMEOUT, config.getSocketTimeout())
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeout())
                .doOnConnected(connection -> connection
                        .addHandler(new ReadTimeoutHandler(config.getReadTimeout(), TimeUnit.MILLISECONDS))
                        .addHandler(new WriteTimeoutHandler(config.getWriteTimeout(), TimeUnit.MILLISECONDS))
                );

This is how Postman breakdown response time in their tool.

enter image description here


Solution

  • You enabled the metrics only on the Connection Pool level, but what you need actually is all HttpClient metrics.

    You can do it like this:

    HttpClient.create(...)
              .metrics(true, ...)
    

    Using the code above, you will be able to see metrics on the Connection Pool level, metrics related to request/response, memory metrics. More about all of this can be found in the Reference Documentation.

    UPDATE

    Here is how your code should look like

                HttpClient client = HttpClient.create(ConnectionProvider.builder("fixed")
                        .maxConnections(700)
                        .maxIdleTime(Duration.ofMillis(config.getPoolMaxIdleTime()))
                        .maxLifeTime(Duration.ofMillis(config.getPoolMaxLifeTime()))
                        .build())
                .option(ChannelOption.SO_TIMEOUT, config.getSocketTimeout())
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeout())
                .doOnConnected(connection -> connection
                        .addHandler(new ReadTimeoutHandler(config.getReadTimeout(), TimeUnit.MILLISECONDS))
                        .addHandler(new WriteTimeoutHandler(config.getWriteTimeout(), TimeUnit.MILLISECONDS))
                )
                .metrics(true, s -> s);