liveBook · Manning

Health check

As explained in Quarkus in Action

A health check is an evaluation that reports whether an application or one of its dependencies is functioning correctly, typically with a binary outcome.

A health check reports whether an application or dependency is working. Its UP or DOWN result lets an operator spot a problem and lets an automated platform respond. Unlike a metric, which reports a numeric value, a health check gives a binary status. section 10.0 section 10.3

Choose a check according to the response a failure should prompt:

  • Liveness indicates whether the application can continue running. A failed Kubernetes liveness probe can restart its pod. section 10.2
  • Readiness indicates whether the application can receive traffic now. A failed readiness probe can keep traffic away until the condition clears. section 10.2
  • Startup indicates that initialization has finished. Kubernetes uses its startup probe during initial startup; liveness and readiness take over after it passes. section 10.2
  • Wellness reports less severe problems that do not warrant a restart or traffic hold-off. SmallRye Health adds wellness and custom health groups beyond MicroProfile Health. section 10.2 section 10.8

In Quarkus, add the SmallRye Health extension with `quarkus extension add smallrye-health`. MicroProfile Health checks are exposed over HTTP: `/q/health` returns the combined JSON result, while `/q/health/live`, `/q/health/ready`, `/q/health/started`, and `/q/health/well` select check types. The Dev UI also offers a human-readable Health UI for development. section 10.2.1 section 10.8

Check a database dependency

An Inventory service using a JDBC data source gets a readiness check automatically. With its MySQL connection working, the database check reports UP. Stop the database container and the check reports DOWN with a connection error: the service cannot process requests at that moment. Restart the container to restore the dependency. section 10.2.1

Listing 10.3 Wellness check reporting DOWN if the inventory is empty
package org.acme.inventory.health;

import io.smallrye.health.api.Wellness;
import jakarta.inject.Inject;
import org.acme.inventory.repository.CarRepository;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;

@Wellness
public class CarCountCheck implements HealthCheck {

    @Inject
    CarRepository carRepository;

    @Override
    public HealthCheckResponse call() {
        long carsCount = carRepository.findAll().count();
        boolean wellnessStatus = carsCount > 0;
        return HealthCheckResponse.builder()
            .name("car-count-check")
            .status(wellnessStatus)  #1
            .withData("cars-count", carsCount)  #2
            .build();
    }
}

A custom wellness check implements `HealthCheck`, counts inventory records, and returns a named status plus the count as data. An empty inventory reports DOWN as a wellness concern rather than a reason to restart the pod. section 10.2.1 section 10.2

How Quarkus in Action covers it

How deep it goes
Works through an automatic JDBC readiness check and a custom wellness implementation, without detailing Kubernetes probe configuration.
Examples
Uses an Inventory service’s MySQL connection failure and an inventory-count wellness check.
What it assumes
Assumes a Quarkus service using JDBC while briefly explaining what Kubernetes probes do.
What you can do after
Apply it via Quarkus SmallRye Health to inspect automatic checks and implement a custom wellness check.
How it connects
Connects MicroProfile Health, SmallRye Health, Kubernetes probes, JDBC data sources, and observability.

Also explained in

Compare how 9 books explain health check →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.