0
votes

I am using Spring Boot Actuator module in my project which exposes REST endpoint URLs to monitor & manage application usages in production environment, without coding & configuration for any of them.

By default, only /health and /info endpoints are exposed.

I am customising the endpoints via application.properties file as per my use case.

application.properties.

#To expose all endpoints
management.endpoints.web.exposure.include=*
 
#To expose only selected endpoints
management.endpoints.jmx.exposure.include=health,info,env,beans

I want to understand, where exactly does Spring Boot create actual endpoints for /health and /info and how does it expose them over HTTP?

1
Also have a look at the Javadoc of Endpoint and the related/ linked classes: docs.spring.io/spring-boot/docs/current/api/org/springframework/… - Puce
Its not clear what are you trying to solve. Do you want to see the source code of spring-boot-actuator? Its available here: github.com/spring-projects/spring-boot/tree/master/…, check it out and see in the IDE who uses @Endpoint Annotation. You'll see EndpointRequestMatcher that in turn is called by the actuator engine, but I doubt that this information is enough to resolve the issue you face (whatever it is :) ) - Mark Bramnik
Thanks Puce and Mark Bramnik for pointing me into the right direction. Appreciate the guidance! I have added an answer as a solution to my problem, in case folks need something similar in future. - Amit kumar

1 Answers

1
votes

Thanks @Puce and @MarkBramnik for helping me out with the reference docs & code repository.

I wanted to understand how the endpoints were working and how they were exposed over HTTP, so that I could create custom endpoints to leverage in my application.

One of the great features of Spring Framework is that it’s very easy to extend, and I was able to achieve the same.

To create a custom actuator endpoints, Use @Endpoint annotation on a class. Then leverage @ReadOperation / @WriteOperation / @DeleteOperation annotations on the methods to expose them as actuator endpoint bean as needed.

Reference Doc : Implementing Custom Endpoints

Reference Example :

@Endpoint(id="custom_endpoint")
@Component
public class MyCustomEndpoint {

    @ReadOperation
    @Bean
    public String greet() {
        return "Hello from custom endpoint";
    }
}

The endpoint id i.e custom_endpoint needs to be configured in the list of actuator endpoints to be enabled.

application.properties :

management.endpoints.web.exposure.include=health,info,custom_endpoint

After a restart, endpoint works like a charm!