I am using spring actuator to monitor my webflux api request count, but I find that MetricsWebFilter doesn't work sometimes.
It's my pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
It's my webflux controller:
@RestController
public class DemoController {
@GetMapping("/test1")
public Mono<String> test() {
return Mono.just("test1");
}
@GetMapping("/test2")
public Mono<String> test2() {
return Mono.just("test2")
.publishOn(Schedulers.elastic());
}
}
And I run this webflux application on IntelliJ IDEA (windows 10), I find that actuator does not count the /test1
api when I use Postman to request this api, but actuator works when I request the /test2
api.
It's a response of /actuator/prometheus
api after I send some requests:
# HELP http_server_requests_seconds
# TYPE http_server_requests_seconds summary
http_server_requests_seconds_count{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 11.0
http_server_requests_seconds_sum{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 0.9375212
http_server_requests_seconds_count{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/test2",} 3.0
http_server_requests_seconds_sum{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/test2",} 0.0093845
# HELP http_server_requests_seconds_max
# TYPE http_server_requests_seconds_max gauge
http_server_requests_seconds_max{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 0.0478851
http_server_requests_seconds_max{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/test2",} 0.0
See, actuator does not work on the /test1
api, and I think it can be reproduced simply.
So how can I fix this problem, or how to use actuator correctly in webflux application, thanks!
Comment From: snicoll
What makes you think that it does not work? Have you tried to plug a prometheus instance to this app and look at what it stores. If you don't see test1
in that output, it might just as well because there wasn't a (super) recent activity on that endpoint.
Comment From: wilkinsona
This looks like a duplicate of #17103 to me.
Comment From: haicoder
thanks, @wilkinsona , I have to downgrade reactor-netty to 0.8.6, it works correctly.
And I will pay attention to https://github.com/reactor/reactor-netty/issues/741
Comment From: snicoll
Arg, sorry @haicoder, I got confused more than once by the output of the /actuator/prometheus
endpoint (not showing stuff because of a lack of recent activity) and wrongly assumed that could have been the case for you as well. Glad you've a workaround for the issue in the mean time.
Comment From: rishabsri91
http_server_requests_seconds_count{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/test2",} 3.0 http_server_requests_seconds_sum{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/test2",} 0.0093845
referring to above bug, how the request response time is so less, only 0.0093845 ms.
@snicoll @haicoder can you please suggest how to track the exact time the requests are taking?