4
votes

I'm trying to integrate Spring Boot Actuator with my companies existing infrastructure. To do this I need to be able to customize the status message. For instance if the app is up and running correctly I need to return a 200 and a plain text body of "HAPPY" from the health actuator endpoint.

Is such customization currently possible? Since the Status class is final I can't extend it, but I think that would work.

1

1 Answers

0
votes

Spring Boot uses a HealthAggregator to aggregate all of the statuses from the individual health indicators into a single health for the entire application. You can plug in a custom aggregator that delegates to Boot's default aggregator, OrderedHealthAggregator, and then maps UP to HAPPY:

@Bean
public HealthAggregator healthAggregator() {
    return new HappyHealthAggregator(new OrderedHealthAggregator());
}

static class HappyHealthAggregator implements HealthAggregator {

    private final HealthAggregator delegate;

    HappyHealthAggregator(HealthAggregator delegate) {
        this.delegate = delegate;
    }

    @Override
    public Health aggregate(Map<String, Health> healths) {
        Health result = this.delegate.aggregate(healths);
        if (result.getStatus() == Status.UP) {
            return new Health.Builder(new Status("HAPPY"), result.getDetails())
                    .build();
        }
        return result;
    }

}

If you want to take complete control over the format of the response, then you'll need to write your own MVC endpoint implementation. You could use the existing HealthMvcEndpointclass in Spring Boot as a super class and override its invoke method.