1

I am trying to add custom functionality to health check endpoint. Created class according to this post :

@Component
public class CustomHealthCheck extends AbstractHealthIndicator {
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        boolean someValue = true;
        if (someValue) {
            builder.withDetail("MyCustomField", "MyValue");
            builder.up();
        } else {
            builder.down();
        }
    }
} 

But when accessing to health endpoint via postman or via browser (/actuator/health) I got response

{
    "status": "UP"
} 

i.e. custom field was not added to the response I also see in debugger , that doHealthCheck method of CustomHealthCheck was executed

Here are relevant definitions from application.properties :

management.endpoints.enabled-by-default=true
management.endpoint.health.enabled=true
management.endpoint.info.enabled=true
management.endpoints.web.exposure.include=health,info

Is there something missing in the code or definitions ? Thanks in advance

eng
  • 443
  • 1
  • 4
  • 10
lm.
  • 4,033
  • 4
  • 25
  • 37

1 Answers1

1

By providing a bean implementing HealthIndicator, you contribute a custom health indicator, rather than overriding some default. The base /actuator/health then returns an aggregate over all registered beans, including yours.

Try naming your bean CustomHealthIndicator and you should be able to see your detail under /actuator/health/custom.

crizzis
  • 9,978
  • 2
  • 28
  • 47