I'm continuing my journey on getting more familiar with HTTP APIs by reading related Request For Comments. This time, I read the Health Check Response Format for HTTP APIs on the suggestion of Stefano Fago. In this post, I'd like to summarize my reading.
Note that it's a draft. Moreover, it has been dormant for nearly two years and, thus, has been automatically expired. However, it's the closest to a specification on health checks and thus deserves some love.
Even though it's not a long read, it's a bit "dry". Fortunately, the specification offers a JSON sample. I copy-pasted it in PlantUML, and presto, it shows a visual representation of it:
Let's have a look at the proposed structure element by element.
At its simplest, the response is a JSON object with a mandatory status
property:
Values can be:
pass
for healthy status. The value can also be ok
(for NodeJS) and up
(for Spring Boot) to account for existing health check libraries. The HTTP status code must be in the range from 2xx to 3xx.warn
for healthy status but with concerns with the same HTTP status range.fail
to indicate unhealthy status. Possible alternative values include error
(NodeJS) and down
(Spring Boot). The HTTP status code must be in the range from 4xx to 5xx.
One can add additional optional values:
version
: public version of the servicereleaseId
: internal version of the service. For example, the version
would be incremented for non-compatible change, while the releaseId
could be the commit hash or a semantic version.serviceId
: the unique identifier of the servicedescription
: self-explanatorynotes
: array of non-structured notesoutput
: plain error message in case of pass
or warn
. The field should be left blank for pass
.links
objectsThe links
object consists of object pairs. Values are URIs, while keys can be URIs or common/registered ones: see RFC5988 for common values, e.g., self
.
checks
objectsKeys of checks
objects consist of two terms separated by a colon, component name, and measurement name. The latter can be either:
utilization
, responseTime
, connections
, or uptime
Values consist of one of the following keys:
componentId
: unique id of this componentcomponentType
:
component
, datastore
, or system
observedValue
: any valid JSON valueobservedUnit
: unit of measurementstatus
: as the parent object's status, but for this component, onlyaffectedEndpoints
: if the component is not pass
, lists all affected endpointstime
: date-time in ISO8601 format of the observationoutput
: as the parent object's output, but for this component, onlylinks
: see the previous section
I tried implementing the above with Spring Boot using a custom HealthIndicator
. Here's the best I could come up with:
The current structure of the JSON response needs to be (easily?) customizable. You'd need to create your endpoint. I hope the Spring Boot team provides the option to generate a compatible structure.
The Healthcheck IETF draft is a great initiative to standardize health checks across the industry. It would allow monitoring tools to rely on HTTP status and response body without ad-hoc configuration on each service.
Unfortunately, the draft is expired because of a lack of activity. I'd love to see it revived, though.
To go further:
Originally published at A Java Geek on May 28th, 2023