Hey all,
I have a custom endpoint that is accessible only under the admin actuator port and I would like to expose some useful micrometer metrics when calling that endpoint.
I was trying to configure it the same way I am doing for regular @RestController classes.
This is the sample code I tried:
...
import io.micrometer.core.annotation.Timed;
...
@Component
@Timed(histogram = true)
@RestControllerEndpoint(id = "tenant")
public class TenantEndpoint {
@GetMapping("/customer/{id}")
public String getTenantById(@PathVariable("id") String customerId) {
return "Tenant_" + customerId;
}
}
However, when configuring the same example via @RestController there are metrics about request duration:
http_server_requests_seconds_bucket{exception="ApiException",method="GET",outcome="CLIENT_ERROR",status="404",uri="/customer/{id}",le="0.001",} 0.0
...
http_server_requests_seconds_bucket{exception="ApiException",method="GET",outcome="CLIENT_ERROR",status="404",uri="/customer/{id}",le="22.906492245",} 10.0
http_server_requests_seconds_bucket{exception="ApiException",method="GET",outcome="CLIENT_ERROR",status="404",uri="/customer/{id}",le="28.633115306",} 10.0
http_server_requests_seconds_bucket{exception="ApiException",method="GET",outcome="CLIENT_ERROR",status="404",uri="/customer/{id}",le="30.0",} 10.0
http_server_requests_seconds_bucket{exception="ApiException",method="GET",outcome="CLIENT_ERROR",status="404",uri="/customer/{id}",le="+Inf",} 10.0
http_server_requests_seconds_count{exception="ApiException",method="GET",outcome="CLIENT_ERROR",status="404",uri="/customer/{id}",} 10.0
http_server_requests_seconds_sum{exception="ApiException",method="GET",outcome="CLIENT_ERROR",status="404",uri="/customer/{id}",} 0.158057834
# HELP http_server_requests_seconds_max Duration of HTTP server request handling
# TYPE http_server_requests_seconds_max gauge
http_server_requests_seconds_max{exception="ApiException",method="GET",outcome="CLIENT_ERROR",status="404",uri="/customer/{id}",} 0.089274792
Would it be possible to support the same metircs for Customer Acutator endpoint?
Comment From: jonatan-ivanov
Could you please provide the version you are using?
Comment From: vladimirsvicevicsrb
Hey @jonatan-ivanov , I am using 2.7.12 spring boot version.
Comment From: jonatan-ivanov
Spring Boot does not instrument @ControllerEndpoint and @RestControllerEndpoint, you can either create a @Controller/@RestController or instrument your endpoint manually or migrate to Spring Boot 3.x where instrumentation is in Spring Framework and endpoints are instrumented too.