feat: add infrastructure status to health endpoint
This commit is contained in:
@@ -421,7 +421,8 @@ def _log_audit(
|
|||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
@router.get("/health", response_model=HealthResponse)
|
@router.get("/health", response_model=HealthResponse)
|
||||||
def health_check(
|
async def health_check(
|
||||||
|
request: Request,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
storage: S3Storage = Depends(get_storage),
|
storage: S3Storage = Depends(get_storage),
|
||||||
):
|
):
|
||||||
@@ -449,11 +450,30 @@ def health_check(
|
|||||||
|
|
||||||
overall_status = "ok" if (storage_healthy and database_healthy) else "degraded"
|
overall_status = "ok" if (storage_healthy and database_healthy) else "degraded"
|
||||||
|
|
||||||
return HealthResponse(
|
# Build response with optional infrastructure status
|
||||||
status=overall_status,
|
response_data = {
|
||||||
storage_healthy=storage_healthy,
|
"status": overall_status,
|
||||||
database_healthy=database_healthy,
|
"storage_healthy": storage_healthy,
|
||||||
)
|
"database_healthy": database_healthy,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add HTTP pool status if available
|
||||||
|
if hasattr(request.app.state, 'http_client'):
|
||||||
|
http_client = request.app.state.http_client
|
||||||
|
response_data["http_pool"] = {
|
||||||
|
"pool_size": http_client.pool_size,
|
||||||
|
"worker_threads": http_client.executor_max,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add cache status if available
|
||||||
|
if hasattr(request.app.state, 'cache'):
|
||||||
|
cache = request.app.state.cache
|
||||||
|
response_data["cache"] = {
|
||||||
|
"enabled": cache.enabled,
|
||||||
|
"connected": await cache.ping() if cache.enabled else False,
|
||||||
|
}
|
||||||
|
|
||||||
|
return HealthResponse(**response_data)
|
||||||
|
|
||||||
|
|
||||||
# --- Authentication Routes ---
|
# --- Authentication Routes ---
|
||||||
|
|||||||
@@ -493,6 +493,8 @@ class HealthResponse(BaseModel):
|
|||||||
version: str = "1.0.0"
|
version: str = "1.0.0"
|
||||||
storage_healthy: Optional[bool] = None
|
storage_healthy: Optional[bool] = None
|
||||||
database_healthy: Optional[bool] = None
|
database_healthy: Optional[bool] = None
|
||||||
|
http_pool: Optional[Dict[str, Any]] = None
|
||||||
|
cache: Optional[Dict[str, Any]] = None
|
||||||
|
|
||||||
|
|
||||||
# Garbage collection schemas
|
# Garbage collection schemas
|
||||||
|
|||||||
Reference in New Issue
Block a user