Application status down, when mongo is down with spring boot actuator Application status down, when mongo is down with spring boot actuator mongodb mongodb

Application status down, when mongo is down with spring boot actuator


application.properties

management.health.mongo.enabled=falseendpoints.mongo.enabled=true

MongoDBHealthCheckEndPoint.java

@ConfigurationProperties(prefix = "endpoints.mongo", ignoreUnknownFields =     true)@Componentpublic class MongoDBHealthCheckEndPoint extends    AbstractEndpoint<Map<String, String>>  {@InjectMongoTemplate mongoTemplate;private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());private static final Map<String, String> UP = new HashMap<String, String>() {{    put("mongo.status", "UP");}};private static final Map<String, String> DOWN = new HashMap<String, String>() {{    put("mongo.status", "DOWN");}};public MongoDBHealthCheckEndPoint() {    super("mongo", false);}public MongoDBHealthCheckEndPoint(Map<String, ? extends Object> mongo) {    super("mongo", false);}public Map<String, String> invoke() {    try {        return (new MongoHealthIndicator(mongoTemplate).health().getStatus().equals(Status.UP)) ? UP : DOWN;    } catch (Exception e) {        log.error("mongo database is down", e);        return DOWN;    }}


Spring Boot Actuator uses HealthIndicatorAutoconfiguration to configure various health related beans. One of the beans is called healthAggregator which uses the implementation or OrderedHealthAggregator. It will use the lowest status of all the health indicators to provide overall application status (that's why you're getting DOWN for overall app.

You can either turn off MongoDb monitoring (management.health.mongo.enabled=false) or write your own implementation of AbstractHealthAggregator that will ignore MongoDb being down for example and provide it in your config:

    @Bean    public MyHealthAggregator healthAggregator() {        return new MyHealthAggregator();    }