Skip to content

feat: add health endpoints for Kubernetes probes#5

Draft
thenav56 wants to merge 7 commits into
mainfrom
feature/health-endpoints
Draft

feat: add health endpoints for Kubernetes probes#5
thenav56 wants to merge 7 commits into
mainfrom
feature/health-endpoints

Conversation

@thenav56

Copy link
Copy Markdown
Member

No description provided.

thenav56 and others added 7 commits June 15, 2026 19:34
Add HealthProbeMiddleware serving dependency-free /healthz/live/ and
/healthz/ready/ endpoints for Kubernetes liveness/readiness probes.

The middleware short-circuits probe requests before any other middleware
runs, keeping the checks cheap and bypassing the ALLOWED_HOSTS check so
the kubelet can hit the pod by IP. Both endpoints check only pod-local
health -- shared dependencies (DB, Redis, S3) are deliberately not
checked, since a shared-dependency outage would fail every pod's
readiness at once and drain the Service. Paths are overridable via the
BANJO_HEALTH_PROBE_LIVE_URL / BANJO_HEALTH_PROBE_READY_URL settings.

Also expose reusable helpers for keeping probe traffic out of Sentry
tracing (which instruments at the WSGI/ASGI layer, outside Django
middleware): is_health_probe_path(),
extract_sentry_request_health_probe_path() and
make_sentry_traces_sampler_with_health_probe_ignore().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Liveness probes for the non-HTTP celery worker and beat processes,
mirroring the pod-local, dependency-free philosophy of HealthProbeMiddleware.

- banjo_utils.celery_probe: stdlib-only heartbeat-file reader, installed as
  the `banjo-celery-probe` console script for use as a kubelet exec probe.
  Exits non-zero when the heartbeat file is stale or missing. No broker
  round-trip (avoids the false-positive restarts of `celery inspect ping`).
- banjo_utils.celery_health.worker: a StartStopStep bootstep that touches the
  worker heartbeat on the worker Timer every 30s. setup_worker_heartbeat(app)
  is the one-line public API. Safe under the prefork pool.
- banjo_utils.celery_health: HeartbeatSchedulerMixin (base-agnostic), plus
  HeartbeatPersistentScheduler and HeartbeatDatabaseScheduler for the beat
  --scheduler flag. The scheduler touches the file after tick() completes.

celery and django-celery-beat are dev-only dependencies; they are not added to
the banjo-utils runtime requirements.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a celery-version axis to the test matrix (5.3 -> 5.6, one per existing
python/django row) so the celery_health probes are exercised across the
supported celery range. celery 5.6 requires Python >=3.9, so the py3.8 row
caps at 5.5.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Record the decision to use a pod-local heartbeat file (touched by the worker
bootstep and beat scheduler tick, read by an exec probe) for celery liveness,
over `celery inspect ping` (broker round-trip, false positives under load) and
a PID-file check (cannot detect a wedge). First record in a new docs/adr log.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
banjo-utils only uses Django's abstract cache API, never importing
django_redis, so a redis-backed consumer supplies django-redis
themselves (it brings the redis client transitively). Mirrors how
celery/django-celery-beat are handled.

- pyproject: drop django-redis from runtime deps, add bare to dev group
- wait_for_resources: guard the redis.exceptions import inside
  wait_for_redis() with a friendly ImportError, so --db/--minio no
  longer require redis and --redis fails actionably when it is absent
- README: note --redis needs a consumer-supplied redis client
- regenerate uv.lock

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
--cache exercises Django's cache abstraction (not redis directly), so the
flag now names its role. Add --celery-broker: waits on CELERY_BROKER_URL via
a lazily-imported kombu Connection (connect_timeout=5, RetryHelper backoff),
with a friendly ImportError when kombu is absent and a skip when no broker
URL is set. Neither redis nor kombu is a banjo-utils runtime dependency.

BREAKING CHANGE: --redis is removed; use --cache instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@thenav56 thenav56 force-pushed the feature/health-endpoints branch from d414fa0 to 395c8ca Compare July 6, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant