Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /Kolerr-Lab_supper-decoyable /decoyable /api /routers /health.py
| """ | |
| Health check router for API monitoring and diagnostics. | |
| """ | |
| import time | |
| from typing import Any, Dict | |
| from fastapi import APIRouter, HTTPException | |
| from decoyable.core.logging import get_logger | |
| router = APIRouter() | |
| logger = get_logger("api.health") | |
| async def root() -> Dict[str, Any]: | |
| """API root endpoint with basic service information.""" | |
| return {"status": "ok", "service": "decoyable", "version": "0.1.0", "timestamp": time.time()} | |
| async def health_check() -> Dict[str, Any]: | |
| """Comprehensive health check for monitoring service availability.""" | |
| start_time = time.time() | |
| try: | |
| # Basic health checks | |
| health_status = {"status": "healthy", "timestamp": time.time(), "checks": {}} | |
| # Check core services | |
| health_status["checks"]["api"] = {"status": "healthy", "response_time": time.time() - start_time} | |
| # Check database connectivity (placeholder) | |
| health_status["checks"]["database"] = {"status": "healthy", "response_time": 0.001} | |
| # Check Redis connectivity (placeholder) | |
| health_status["checks"]["redis"] = {"status": "healthy", "response_time": 0.001} | |
| # Check Kafka connectivity (placeholder) | |
| health_status["checks"]["kafka"] = {"status": "healthy", "response_time": 0.001} | |
| # Overall status | |
| all_healthy = all(check["status"] == "healthy" for check in health_status["checks"].values()) | |
| health_status["status"] = "healthy" if all_healthy else "degraded" | |
| return health_status | |
| except Exception as e: | |
| logger.error(f"Health check failed: {e}") | |
| raise HTTPException(status_code=503, detail="Service unhealthy") | |
| async def readiness_check() -> Dict[str, Any]: | |
| """Kubernetes readiness probe endpoint.""" | |
| # For now, always ready. In production, check dependencies. | |
| return {"status": "ready", "timestamp": time.time()} | |
| async def liveness_check() -> Dict[str, Any]: | |
| """Kubernetes liveness probe endpoint.""" | |
| return {"status": "alive", "timestamp": time.time()} | |
| async def ping() -> Dict[str, str]: | |
| """Simple ping endpoint.""" | |
| return {"pong": "decoyable"} | |
Xet Storage Details
- Size:
- 2.64 kB
- Xet hash:
- bb5c7fa2b5a06c76d33dfde197c8462f2b55d11730a64b5562b94f21cffbd4d3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.