Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-31215: Add health check endpoint to the server #3

Merged
merged 1 commit into from
Aug 13, 2021
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
4 changes: 4 additions & 0 deletions alertdb/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def create_server(backend: AlertDatabaseBackend) -> FastAPI:

app = FastAPI()

@app.get("/v1/health")
def healthcheck():
return Response(content=b"OK")

@app.get("/v1/schemas/{schema_id}")
def get_schema(schema_id: str):
try:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def test_get_missing_schema(self):
response = self._get_schema("bogus")
self.assertEqual(response.status_code, 404)

def test_healthcheck(self):
"""Test that the healthcheck endpoint returns 200."""
response = self.client.get("/v1/health")
self.assertEqual(response.status_code, 200)

def _get_alert(self, alert_id: str) -> requests.Response:
return self.client.get(f"/v1/alerts/{alert_id}")

Expand Down
19 changes: 19 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from fastapi.testclient import TestClient

from alertdb.server import create_server
from alertdb.storage import FileBackend


@pytest.fixture
def file_backend(tmp_path):
"""Pytest fixture for a file-based backend"""
yield FileBackend(str(tmp_path))


def test_server_healthcheck(file_backend):
"""Test that the server responds on the healthcheck endpoint."""
server = create_server(file_backend)
client = TestClient(server)
response = client.get("/v1/health")
assert response.status_code == 200