Skip to content

Commit

Permalink
Merge pull request #975 from julep-ai/c/healthz-endpoint
Browse files Browse the repository at this point in the history
chore(agents-api): Add `/healthz` endpoint
  • Loading branch information
creatorrr authored Dec 19, 2024
2 parents 1d4b2c8 + 54b8ff6 commit 3c6c86e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions agents-api/agents_api/routers/healthz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ruff: noqa: F401
from .check_health import check_health
from .router import router
20 changes: 20 additions & 0 deletions agents-api/agents_api/routers/healthz/check_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import logging
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:
logging.error("An error occurred while checking health: %s", str(e))
return {"status": "error", "message": "An internal error has occurred."}

return {"status": "ok"}
3 changes: 3 additions & 0 deletions agents-api/agents_api/routers/healthz/router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from fastapi import APIRouter

router: APIRouter = APIRouter()
2 changes: 2 additions & 0 deletions agents-api/agents_api/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
agents,
docs,
files,
healthz,
internal,
jobs,
sessions,
Expand Down Expand Up @@ -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
#
Expand Down
13 changes: 11 additions & 2 deletions gateway/traefik.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3c6c86e

Please sign in to comment.