73 lines
1.7 KiB
Python
73 lines
1.7 KiB
Python
"""Health check router for monitoring endpoints."""
|
|
|
|
from fastapi import APIRouter
|
|
|
|
router = APIRouter(tags=["health"])
|
|
|
|
|
|
@router.get("/health")
|
|
def health_check() -> dict[str, str]:
|
|
"""
|
|
Health check endpoint for container orchestration.
|
|
|
|
Returns 200 if the service is alive and able to handle requests.
|
|
"""
|
|
return {"status": "healthy"}
|
|
|
|
|
|
@router.get("/ready")
|
|
def readiness_check() -> dict[str, str]:
|
|
"""
|
|
Readiness check endpoint for container orchestration.
|
|
|
|
Returns 200 if the service is ready to accept traffic.
|
|
This can include checks for database connectivity, external services, etc.
|
|
"""
|
|
# Add dependency checks here if needed (database, cache, etc.)
|
|
# For now, simple readiness check
|
|
return {"status": "ready"}
|
|
|
|
|
|
@router.get("/info")
|
|
def service_info() -> dict:
|
|
"""
|
|
Get service information including available features.
|
|
|
|
Useful for verifying which optional dependencies are installed.
|
|
"""
|
|
import os
|
|
|
|
# Check which optional dependencies are available
|
|
features = {
|
|
"redis": False,
|
|
"postgresql": False,
|
|
}
|
|
|
|
try:
|
|
import redis # noqa: F401
|
|
|
|
features["redis"] = True
|
|
except ImportError:
|
|
pass
|
|
|
|
try:
|
|
import psycopg2 # noqa: F401
|
|
|
|
features["postgresql"] = True
|
|
except ImportError:
|
|
pass
|
|
|
|
# Check current configuration
|
|
config = {
|
|
"environment": os.getenv("ENVIRONMENT", "production"),
|
|
"data_dir": os.getenv("DATA_DIR", "/data"),
|
|
"redis_configured": bool(os.getenv("REDIS_URI")),
|
|
}
|
|
|
|
return {
|
|
"service": "baby-monitor",
|
|
"version": "0.1.0",
|
|
"features": features,
|
|
"config": config,
|
|
}
|