Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion backend/api/v1/endpoints/health.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from datetime import datetime, timezone
from fastapi import APIRouter, HTTPException, status
from fastapi import APIRouter, HTTPException, Response, status
from core.database import get_db
from schemas import HealthResponse

Expand All @@ -14,6 +14,12 @@ def liveness_check():
return {"status": "alive"}


@router.head("/live", include_in_schema=False)
def liveness_head_check():
"""Allow HEAD-based uptime probes without querying the database."""
return Response(status_code=status.HTTP_200_OK)


@router.get("/health", response_model=HealthResponse)
def health_check():
conn = None
Expand Down
12 changes: 12 additions & 0 deletions backend/test_health_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ def fail_if_database_is_used():

assert response.status_code == 200
assert response.json() == {"status": "alive"}


def test_head_liveness_check_does_not_query_database(monkeypatch):
def fail_if_database_is_used():
pytest.fail("liveness check must not open a database connection")

monkeypatch.setattr(health, "get_db", fail_if_database_is_used)

response = client.head("/api/v1/live")

assert response.status_code == 200
assert response.content == b""
Loading