Skip to content
Draft
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
7 changes: 7 additions & 0 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ async def root():
return HTMLResponse(file.read())


@app.get("/health")
async def health():
"""Health endpoint handler"""
metrics.add("http_requests_total", 1)
return {"status": "ok", "service": "KernelCI API"}


# -----------------------------------------------------------------------------
# Users

Expand Down
6 changes: 3 additions & 3 deletions doc/local-instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ It can take a few minutes to build the images from scratch the first time.
Then the services should be up and running. To confirm the API is available:

```
$ curl http://localhost:8001/latest/
{"message":"KernelCI API"}
$ curl http://localhost:8001/latest/health
{"status":"ok","service":"KernelCI API"}
```

> **Port numbers** for the services exposed by `docker-compose` can be
Expand All @@ -101,7 +101,7 @@ $ curl http://localhost:8001/latest/
Following the `curl` command from the example above, the container log should
show:
```
kernelci-api | INFO: 172.20.0.1:49228 - "GET / HTTP/1.1" 200 OK
kernelci-api | INFO: 172.20.0.1:49228 - "GET /latest/health HTTP/1.1" 200 OK
```

### Bootstrap the initial admin user
Expand Down
14 changes: 13 additions & 1 deletion tests/e2e_tests/test_root_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ async def test_root_endpoint(test_async_client):
"""Test root handler"""
response = await test_async_client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "KernelCI API"}
assert response.headers["content-type"].startswith("text/html")
assert "KernelCI API Server" in response.text


@pytest.mark.asyncio
async def test_health_endpoint(test_async_client):
"""Test health handler"""
response = await test_async_client.get("health")
assert response.status_code == 200
assert response.json() == {
"status": "ok",
"service": "KernelCI API",
}
20 changes: 18 additions & 2 deletions tests/unit_tests/test_root_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,24 @@ def test_root_endpoint(test_client):
Test Case : Test KernelCI API root endpoint
Expected Result :
HTTP Response Code 200 OK
JSON with 'message' key
HTML landing page
"""
response = test_client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "KernelCI API"}
assert response.headers["content-type"].startswith("text/html")
assert "KernelCI API Server" in response.text


def test_health_endpoint(test_client):
"""
Test Case : Test KernelCI API health endpoint
Expected Result :
HTTP Response Code 200 OK
JSON with health status
"""
response = test_client.get("health")
assert response.status_code == 200
assert response.json() == {
"status": "ok",
"service": "KernelCI API",
}