#!/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"