Spring Boot 4 Actuator in production: endpoints, security, custom health indicators
Companion repository for the ankurm.com article. Every transcript in docs/output/ was produced by running this project; scripts/run-all.sh regenerates all of them. Verified against Spring Boot 4.1.1 / Framework 7.0.9 / Security 7.1.1 / Micrometer 1.17.1 / kafka-clients 4.2.1 on Temurin JDK 25.0.4.1+1.
This commit is contained in:
40
scripts/demo-custom-health.sh
Executable file
40
scripts/demo-custom-health.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
# The three custom indicators, and what happens when the upstream goes down.
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
OUT=docs/output/07-custom-health-indicators.txt
|
||||
B=http://localhost:8080
|
||||
{
|
||||
echo "### profile: details (show-details: always, show-components: always)"
|
||||
echo
|
||||
echo "--- upstream UP ---"
|
||||
curl -s -o /dev/null -u ops:ops-password -X POST "$B/stub/upstream/mode?value=up"
|
||||
sleep 1
|
||||
echo "\$ curl -s -o /dev/null -w '%{http_code}' $B/actuator/health"
|
||||
curl -s -o /dev/null -w ' HTTP %{http_code}\n' -u ops:ops-password "$B/actuator/health"
|
||||
curl -s -u ops:ops-password "$B/actuator/health" | python3 -m json.tool
|
||||
echo
|
||||
echo "--- flip the upstream to DOWN, change nothing else ---"
|
||||
echo "\$ curl -s -X POST '$B/stub/upstream/mode?value=down'"
|
||||
curl -s -u ops:ops-password -X POST "$B/stub/upstream/mode?value=down"; echo
|
||||
sleep 1
|
||||
curl -s -o /dev/null -w ' HTTP %{http_code}\n' -u ops:ops-password "$B/actuator/health"
|
||||
curl -s -u ops:ops-password "$B/actuator/health" | python3 -c '
|
||||
import json,sys
|
||||
d=json.load(sys.stdin)
|
||||
print(json.dumps({"status":d["status"],"externalApi":d["components"]["externalApi"]},indent=2))'
|
||||
echo
|
||||
echo " The aggregate went DOWN and /actuator/health now answers 503. If that URL is your"
|
||||
echo " Kubernetes readiness probe, every pod in the deployment has just left the load"
|
||||
echo " balancer because a third party had a bad minute."
|
||||
echo
|
||||
echo "--- a single component, addressed directly ---"
|
||||
echo "\$ curl -s $B/actuator/health/ordersDatabase"
|
||||
curl -s -u ops:ops-password "$B/actuator/health/ordersDatabase" | python3 -m json.tool
|
||||
echo "\$ curl -s $B/actuator/health/kafka"
|
||||
curl -s -u ops:ops-password "$B/actuator/health/kafka" | python3 -m json.tool
|
||||
echo
|
||||
echo "--- restore ---"
|
||||
curl -s -u ops:ops-password -X POST "$B/stub/upstream/mode?value=up"; echo
|
||||
} > "$OUT" 2>&1
|
||||
echo "wrote $OUT"
|
||||
Reference in New Issue
Block a user