Skip to content

docs: document API health and readiness endpoints - #10

Closed
JacobusTheOne wants to merge 12 commits into
Azure-Samples:mainfrom
JacobusTheOne:feature/document-api-health-checks
Closed

JacobusTheOne wants to merge 12 commits into
Azure-Samples:mainfrom
JacobusTheOne:feature/document-api-health-checks

Conversation

@JacobusTheOne

Copy link
Copy Markdown

Summary

  • Document the /health endpoint and its liveness purpose.

  • Document the /ready endpoint and its database connectivity check.

  • Explain the distinction between liveness and readiness checks.

Testing

  • Reviewed endpoint implementations in src/app/main.py.

  • Verified documented HTTP status codes and JSON responses against the implementation.

  • git diff --check passed.

JacobusTheOne and others added 12 commits October 31, 2026 12:59
The deploy job ran `az containerapp update --image`, which only patches the
image. Bicep also declared the image, so the next template deployment rolled
it back, and configuration the template declares (probes, identity) was
never applied. Deploy api.bicep instead, passing the tag just pushed, so the
template is the single source of truth. The template lives in the deployment
repo, checked out with DEPLOY_REPO_TOKEN.

Add /ready, which runs SELECT 1 and returns 503 when the database is
unreachable. /health answers as soon as the process is listening, which is
what a liveness probe wants, but using it for readiness tells the ingress a
replica can serve /albums before SQL is reachable. The two probes are wired
to the matching endpoints in api.bicep, with failureThreshold allowing a
60s grace period for a database resume.

Liveness deliberately stays off the database so a transient SQL failure
cannot restart an otherwise healthy replica.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
albumdb is serverless with a 60 minute auto-pause, so a container starting
after an idle period hits a database that refuses connections for a minute
or more while it resumes. Alembic opened that connection with no retry, so
startup failed before migrations or seeding could run.

Retry the connection Alembic actually goes on to use, rather than probing
availability and then opening a second connection. Only the connect is
retried: a failure in the caller's own work propagates untouched, because
replaying a partially applied migration is more dangerous than failing
loudly.

Catch InterfaceError as well as OperationalError. A failed TCP connect
surfaces as the latter, but pyodbc reports a login rejected by a resuming
database as the former, which would otherwise escape the retry.

Replaces wait_for_database, which was never called from anywhere.

Needs the startup probe added to api.bicep in the deployment repo: the
retry budget of roughly 134s exceeds the liveness budget of roughly 70s, so
without it the platform restarts the container mid-resume and loops.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@JacobusTheOne
JacobusTheOne deleted the feature/document-api-health-checks branch November 4, 2026 19:12
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