Débora
Débora

Reputation: 5952

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 .

Upvotes: 12

Views: 12208

Answers (4)

Gayan Weerakutti
Gayan Weerakutti

Reputation: 13715

By default, OUT_OF_SERVICE and DOWN map to 503. Any unmapped health statuses, including UP, map to 200.

These values can be overridden as mentioned in other answers.

Upvotes: 0

OrangeDog
OrangeDog

Reputation: 38777

The status codes are configured via application properties. These are the defaults:

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

For Spring Boot 1.x the property is endpoints.health.mapping instead.

It's a bad idea to use the codes you suggest, because they already mean other things. A reasonable change is to set UNKNOWN: 500 if you want your upstream system to treat it differently to UP.

Upvotes: 6

Darren Forsythe
Darren Forsythe

Reputation: 11411

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

Upvotes: 11

Erik Pragt
Erik Pragt

Reputation: 14617

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

Upvotes: 2

Related Questions