Skip to content

Conversation

Elvis339
Copy link

The reason for adding a health endpoint is to enable monitoring and orchestration systems (like Kubernetes, load balancers, and monitoring tools) to verify that our service can actually communicate with its critical dependencies before routing traffic to it. Without this, a service might appear "running" but be unable to serve requests due to database or storage failures.

This PR implements a /health endpoint that monitors the status of external dependencies: PostgreSQL and S3/MinIO storage.

Changes Made

  • Added health check endpoint at /health that returns JSON status for all services
  • Implemented S3/MinIO bucket existence check with minimal bucket_exists() method
  • Added health check functions for each service with timeout handling
  • Returns structured health response with per-service status, response times, and error details

Health Response Format

{
  "status": "healthy|degraded|unhealthy",
  "timestamp": "2025-01-27T10:30:00Z",
  "services": {
    "postgres": {
      "status": "up|down|degraded",
      "response_time_ms": 15,
      "error": null
    },
    "s3": {
      "status": "up",
      "response_time_ms": 45,
      "error": null
    }
  }
}

Test

To test the health endpoint:

cargo run --bin rest_api -- \
  --database-url <DATABASE_URL> \
  --s3-bucket <S3_BUCKET> \
  --s3-access-key <S3_ACCESS_KEY> \
  --s3-secret-key <S3_SECRET_KEY> \
  --s3-url <S3_URL> \
  --s3-region <S3_REGION>

curl http://localhost:${port}/health

Open Question for Maintainers

Should we also include Redis health checks in this endpoint? The current implementation focuses on the core dependencies (Postgres + S3), but Redis support could be added as an optional service if it's part of the infrastructure. This would require:

  • Adding optional Redis client to AppState
  • Redis URL parameter in CLI args
  • Redis-specific health check function

Please advise if Redis monitoring should be included in this PR or handled separately.

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