Sub topic 3
Reading and configuring the health endpoint
This chapter assumes you have a Spring Boot application with spring-boot-starter-actuator on the classpath. It also assumes you know how to expose endpoints over HTTP (management.endpoints.web.exposure.include) and can read YAML configuration.
What the health endpoint reports
The health endpoint answers one question: is this application able to do its job? Spring Boot collects the answer from many HealthIndicator beans. Each one checks a single part of the system, such as the database, disk space, or a message broker. The endpoint then combines their results into one overall status.
With the default settings, a request to /actuator/health returns only the overall status:
{"status":"UP"}The common statuses are UP, DOWN, OUT_OF_SERVICE, and UNKNOWN. A DOWN or OUT_OF_SERVICE result makes the endpoint return HTTP 503. Every other status returns HTTP 200. Load balancers and orchestrators rely on this status code, so you rarely need to parse the body.
How the statuses are combined
The overall status is the most severe status among all components. The default severity order, from worst to best, is DOWN, OUT_OF_SERVICE, UP, UNKNOWN. If the database is DOWN and everything else is UP, the application reports DOWN.
Showing details
Details are hidden by default because they can reveal internal hostnames, database products, and file paths. Two properties control them:
management.endpoint.health.show-detailscontrols the details of each component.management.endpoint.health.show-componentscontrols only the list of component names and statuses. If you don't set it, it followsshow-details.
Each property accepts one of three values:
| Value | Behavior |
|---|---|
| `never` | Details are never shown. This is the default. |
| `when-authorized` | Details are shown only to authenticated users who hold the roles in `management.endpoint.health.roles`. |
| `always` | Details are shown to everyone who can reach the endpoint. |
This configuration shows details only to authorized users:
management:
endpoints:
web:
exposure:
include: health,info
endpoint:
health:
show-details: when-authorized
roles: ACTUATORAn authorized user then sees a response like this one:
{
"status": "UP",
"components": {
"db": {
"status": "UP",
"details": { "database": "PostgreSQL", "validationQuery": "isValid()" }
},
"diskSpace": {
"status": "UP",
"details": { "total": 499963174912, "free": 91300069376, "threshold": 10485760 }
},
"ping": { "status": "UP" }
}
}An unauthenticated caller still gets the short {"status":"UP"} form. The use of when-authorized depends on Spring Security being configured, which a later chapter covers.
Turning indicators off
Spring Boot registers indicators automatically when the matching infrastructure is present. A DataSource bean adds db, and a Redis connection adds redis. You can disable a single indicator with a property:
management:
health:
redis:
enabled: false
diskspace:
enabled: falseCommon errors
- Overall
DOWNbecause of an optional service. A non-critical dependency, such as a mail server, can take the whole application out of rotation. Disable that indicator, or keep it out of the group your orchestrator checks (covered in the chapter on health groups). - Missing
componentsin the response. The caller is not authorized, orshow-detailsis stillnever. Check the property and the caller's roles. - 404 on
/actuator/health. The endpoint is not exposed over HTTP, or a different base path or management port is in use. - Slow health responses. Indicators run on the request thread. An indicator that waits on a slow dependency makes every health call slow, and a probe may time out and report a false failure.
Exercise
A caller without credentials requests /actuator/health and gets only {"status":"UP"}, although the database indicator is registered. Which property value explains this, and what would you change so that an authenticated user with the ACTUATOR role sees the details?
Show answer
show-details is still never (the default), so component details are hidden. Set management.endpoint.health.show-details to when-authorized and set management.endpoint.health.roles to ACTUATOR. Unauthenticated callers will still see only the overall status.