Skip to content

Fix development health check with full catalog data - #757

Merged
jochengcd merged 3 commits into
GrandComicsDatabase:betafrom
DeusExTaco:fix/dev-environment-healthcheck
Sep 19, 2026
Merged

jochengcd merged 3 commits into
GrandComicsDatabase:betafrom
DeusExTaco:fix/dev-environment-healthcheck

Conversation

@DeusExTaco

@DeusExTaco DeusExTaco commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

The Docker web health check currently requests the homepage. With a full catalog dump, that page can take longer than the health check's three-second request timeout, so Compose can report an unhealthy web service even though Django and MySQL are working.

I added a small /health/ endpoint that performs a single SELECT 1 and returns {"status": "ok"}, then pointed the Compose health check at that endpoint. I kept the existing three-second threshold so this checks actual application and database readiness without hiding slow requests behind a longer timeout. Database failures are logged and return a small JSON 503 response rather than Django's exception page.

While validating the first CI run, I also found that the existing mysqladmin ping probe returned exit code 0 even when authentication failed. That could release the migration container before a new MySQL instance finished initialization. I changed the database probe to run an authenticated SELECT 1 against the configured database and added the exact command to the Compose contract test.

I added coverage for the web route, response, direct one-query behavior, full middleware request, database-failure response, and both Compose health-check contracts.

Verification

I tested this against my local production-sized dump:

  • 227 tables / 7.22 GiB
  • docker compose up -d --build --wait completed with the web service healthy
  • /health/: 200 in 0.003-0.008 seconds across three requests
  • homepage: 200 in 4.608 seconds cold, then about 0.55 seconds warm
  • ./bin/dev doctor: Python 3.13.15, Django 5.2.17, MySQL 8.0.46; no system-check issues

I also rehearsed CI's clean-install path with a separate Compose project and fresh empty volume. The authenticated database probe waited for initialization, migrations completed, and the web service became healthy. Invalid database credentials returned exit code 1 instead of a false healthy result.

  • focused tests: 13 passed
  • Compose configuration, flake8, diff check, and migration drift check all passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a dedicated /health/ endpoint for the local development stack, updating the Docker Compose healthcheck and corresponding tests to use this new path. Feedback suggests wrapping the database query in the health view with exception handling to prevent potential information disclosure during database failures, and using the Django test client instead of RequestFactory to verify the endpoint through the full middleware stack.

Comment thread apps/gcd/views/health.py Outdated
Comment thread apps/gcd/tests/test_health.py
@jochengcd
jochengcd merged commit 983bf6a into GrandComicsDatabase:beta Sep 19, 2026
2 checks passed
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.

2 participants