Skip to content

Conversation

@eecavanna
Copy link
Collaborator

@eecavanna eecavanna commented Dec 16, 2025

On this branch, I implemented a dedicated health check API endpoint, which is at /api/health. Unlike the /version API endpoint, this new endpoint checks whether the FastAPI app can talk to the Postgres server. I plan to use this new endpoint for Cloudflare health checks and for Kubernetes readinessProbes.

The reason the HealthResponse (Pydantic model) class's definition is in the api.py file is that the models.py file seemed to me to contain only SQLAlchemy models—not Pydantic models—and the Pydantic models I saw elsewhere were in the same files as the functions that use them. The only function that uses this Pydantic model is in api.py.

An analogous endpoint in nmdc-runtime was introduced into that application here.

Screenshots

When database connection is healthy, the endpoint returns an HTTP 200 response with both properties set to true.

image

When database connection is unhealthy, the endpoint returns an HTTP 503 response with the database property set to false.

image

Related issues

Fixes: #1889

This comment was marked as outdated.

Copy link
Collaborator

@pkalita-lbl pkalita-lbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one suggestion about where HeathResponse might be defined.

@eecavanna eecavanna merged commit 686745f into main Dec 16, 2025
2 checks passed
@eecavanna eecavanna deleted the 1889-implement-health-check-api-endpoint-that-checks-database-connection branch December 16, 2025 23:16
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.

Implement health check API endpoint that checks database connection

3 participants