Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override Spring Boot health response codes

How to override actuator's default /health response status code based on its state:DOWN, UP, UNKNOWN so and so ? For example, if the health state is "UP", the response code should be 200. If DOWN: 400, unknown 300. Is there any work around to achieve this ?

Note: I do not want my own health endpoint. Instead, the existing one needs to be overriden .

like image 842
Débora Avatar asked Feb 18 '18 10:02

Débora


2 Answers

In Spring boot 2.x these are the built in status and their defaults, which you can override to the relevant code you want.

management.endpoint.health.status.http-mapping.UP=200
management.endpoint.health.status.http-mapping.UNKNOWN=200
management.endpoint.health.status.http-mapping.DOWN=503
management.endpoint.health.status.http-mapping.OUT_OF_SERVICE=503

or a custom mapping

management.endpoint.health.status.http-mapping.DOWN=400

or in yaml,

management: 
   endpoint:
       health:
          status:
            http-mapping:
              UP: 200
              UNKNOWN: 200
              DOWN: 503
              OUT_OF_SERVICE: 503

In Spring boot 1.x these are the properties with custom status applied,

endpoints.health.mapping.DOWN=400
endpoints.health.mapping.UP=200
endpoints.health.mapping.UNKNOWN=300

or in yaml,

endpoints:
   health:
      mapping:
         UP: 200
         DOWN: 400
         UNKNOWN: 300

Spring Boot Current Actuator Health Documentation

like image 178
Darren Forsythe Avatar answered Sep 29 '22 22:09

Darren Forsythe


It seems the documentation has been updated again (second time). The current properties for Health Check status mappings are:

management.health.status.http-mapping.DOWN=503
management.health.status.http-mapping.UP=200
like image 33
Erik Pragt Avatar answered Sep 29 '22 21:09

Erik Pragt