Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get micrometer prometheus metrics working for Flux?

For Spring Framework 5.0.1.RELEASE and Spring Boot 2.0.0.M6 We want to use the micrometer application monitoring, so wie included:

compile('org.springframework.boot:spring-boot-starter-actuator')
compile('io.micrometer:micrometer-registry-prometheus')

Into our dependency set and create a controller with the following rest endpoints:

@RestController
@Timed
public class MyController {

    @Autowired
    private MyService service;

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public void test() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping(value = "/test/flux", method = RequestMethod.GET, produces = "application/stream+json")
    public Flux<MyItem> getMyItems(@RequestParam Map<String, String> params) {
        return this.service.getMyItems(params);
    }
}

So we got the /test endpoint which is just waiting two seconds and we got the /test/flux endpoint which is returning a list of itmes.

Bot requests work. The only difference is that for the /test endpoint I get prometheus metrics and for the /test/flux endpoint I do not get any metrics:

http_server_requests_duration_seconds_count{exception="None",method="GET",status="200",uri="/get/test",} 1.0
http_server_requests_duration_seconds_sum{exception="None",method="GET",status="200",uri="/get/test",} 2.002811046
http_server_requests_duration_seconds_max{exception="None",method="GET",status="200",uri="/get/test",} 0.0

Do I have to configure something else to get that working for requests which are returning a Flux or is Flux yet not supported?

like image 576
Mulgard Avatar asked Oct 27 '25 10:10

Mulgard


1 Answers

Autoconfiguration of WebFlux endpoints is included in Boot 2 RC2!

like image 146
Jonathan Schneider Avatar answered Oct 29 '25 01:10

Jonathan Schneider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!