diff --git a/agents-api/agents_api/routers/healthz/__init__.py b/agents-api/agents_api/routers/healthz/__init__.py new file mode 100644 index 000000000..dcac6579b --- /dev/null +++ b/agents-api/agents_api/routers/healthz/__init__.py @@ -0,0 +1,3 @@ +# ruff: noqa: F401 +from .check_health import check_health +from .router import router diff --git a/agents-api/agents_api/routers/healthz/check_health.py b/agents-api/agents_api/routers/healthz/check_health.py new file mode 100644 index 000000000..08d1da026 --- /dev/null +++ b/agents-api/agents_api/routers/healthz/check_health.py @@ -0,0 +1,18 @@ +from uuid import UUID + +from ...autogen.openapi_model import Agent, ListResponse +from ...models.agent.list_agents import list_agents as list_agents_query +from .router import router + + +@router.get("/healthz", tags=["healthz"]) +async def check_health() -> dict: + try: + # Check if the database is reachable + agents = list_agents_query( + developer_id=UUID("00000000-0000-0000-0000-000000000000"), + ) + except Exception as e: + return {"status": "error", "message": str(e)} + + return {"status": "ok"} \ No newline at end of file diff --git a/agents-api/agents_api/routers/healthz/router.py b/agents-api/agents_api/routers/healthz/router.py new file mode 100644 index 000000000..5c3ec9311 --- /dev/null +++ b/agents-api/agents_api/routers/healthz/router.py @@ -0,0 +1,3 @@ +from fastapi import APIRouter + +router: APIRouter = APIRouter() diff --git a/agents-api/agents_api/web.py b/agents-api/agents_api/web.py index 8e2e7da54..21fd2f1eb 100644 --- a/agents-api/agents_api/web.py +++ b/agents-api/agents_api/web.py @@ -33,6 +33,7 @@ sessions, tasks, users, + healthz, ) if not sentry_dsn: @@ -188,6 +189,7 @@ async def scalar_html(): app.include_router(docs.router, dependencies=[Depends(get_api_key)]) app.include_router(tasks.router, dependencies=[Depends(get_api_key)]) app.include_router(internal.router) +app.include_router(healthz.router) # TODO: CORS should be enabled only for JWT auth # diff --git a/gateway/traefik.yml.template b/gateway/traefik.yml.template index 28ed51de8..c5eb5654b 100644 --- a/gateway/traefik.yml.template +++ b/gateway/traefik.yml.template @@ -46,8 +46,17 @@ http: middlewares: - agents-api-strip-prefix-api service: service-agents-api - priority: 2 - + priority: 2 + + agents-api-healthz: + entryPoints: + - web + rule: Path(`/api/healthz`) + middlewares: + - agents-api-strip-prefix-api + service: service-agents-api + priority: 3 + agents-api-redirect-to-docs: entryPoints: - web