diff --git a/fixbackend/app.py b/fixbackend/app.py index fe7cd3db..c85aa48e 100644 --- a/fixbackend/app.py +++ b/fixbackend/app.py @@ -49,6 +49,7 @@ from httpx import AsyncClient, Limits, Timeout from prometheus_fastapi_instrumentator import Instrumentator from redis.asyncio import Redis +from sqlalchemy import select from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine from starlette.exceptions import HTTPException @@ -574,6 +575,22 @@ async def load_app_from_cdn() -> bytes: @app.get("/health", tags=["system"]) async def health() -> Response: + try: + pong = await deps.readonly_redis.ping() + if not pong: + log.error("Redis did not respond to ping") + return Response(status_code=500) + + async with deps.session_maker() as session: + result = await session.execute(select(1)) + if result.scalar_one() != 1: + log.error("MySQL did not return 1 from select 1") + return Response(status_code=500) + + except Exception as e: + log.error("Health check failed", exc_info=e) + return Response(status_code=500) + return Response(status_code=200) @app.get("/ready", tags=["system"]) diff --git a/pyproject.toml b/pyproject.toml index 2febc347..23ef5d4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,4 +83,4 @@ omit = [ [tool.coverage.report] show_missing = true -fail_under = 80 +fail_under = 70