4
votes

Is there any way to support multiple health endpoints on a Spring Boot application?

Here's why: The standard actuator health check is great, built in checks are great, customization options are great - for a single use case: reporting on general application health.

But I'd like something I can call from an AWS Elastic Load Balancer / AutoScaling Group. By default, if an instance fails a health check, the ELB/ASG will terminate it and replace it with a fresh instance. The problem is some of the health checks, like DataSourceHealthIndicator, will report DOWN if the database is down, but my application instance is otherwise perfectly healthy. If I use the default behavior, AWS will throw out perfectly healthy instances until the database comes back up, and this will run up my bill.

I could get rid of the DataSourceHealthIndicator, but I like having it around for general health checking purposes. So what I really want is two separate endpoints for two different purposes, such as:

/health - General application health /ec2Health - Ignores aspects unrelated to the EC2 instance, such as a DB outage.

Hope that makes sense.

1
What version of spring boot are you on? IF you're looking to just check the App is able to respond to HTTP requests and none of its external resources are down its fairly simple to write your own health check - Darren Forsythe

1 Answers

1
votes

Spring Boot Actuator has a feature called Health Groups which allows you to configure multiple health indicators.

In application.properties you configure the groups that you want:

management.endpoints.web.path-mapping.health=probes

management.endpoint.health.group.health.include=*
management.endpoint.health.group.health.show-details=never

management.endpoint.health.group.detail.include=*
management.endpoint.health.group.detail.show-details=always

management.endpoint.health.group.other.include=diskSpace,ping
management.endpoint.health.group.other.show-details=always

Output:

$ curl http://localhost:8080/actuator/probes
{"status":"UP","groups":["detail","health","other"]}

$ curl http://localhost:8080/actuator/probes/health
{"status":"UP"}

$ curl http://localhost:8080/actuator/probes/detail
{"status":"UP","components":{"diskSpace":{"status":"UP","details":{"total":0,"free":0,"threshold":0,"exists":true}},"ping":{"status":"UP"},"rabbit":{"status":"UP","details":{"version":"3.6.16"}}}}

$ curl http://localhost:8080/actuator/probes/other
{"status":"UP","components":{"diskSpace":{"status":"UP","details":{"total":0,"free":0,"threshold":0,"exists":true}},"ping":{"status":"UP"}}}