Skip to content

Commit

Permalink
chore(server): add healthcheck ep and to Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
brucetony committed Feb 29, 2024
1 parent 9976ca1 commit c46d05e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ COPY ./gateway/ ./gateway/
EXPOSE 5000

ENTRYPOINT ["python", "-m", "gateway.cli", "serve"]

HEALTHCHECK CMD curl --fail http://localhost:5000/health || exit 1
6 changes: 6 additions & 0 deletions gateway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@


# Method models
class HealthCheck(BaseModel):
"""Response model to validate and return when performing a health check."""

status: str = "OK"


class User(BaseModel):
"""Example User output"""

Expand Down
35 changes: 23 additions & 12 deletions gateway/server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Methods for verifying auth."""
import uvicorn
from fastapi import FastAPI, Security
from fastapi import FastAPI
from starlette import status

from gateway.auth import idp_settings, oauth2_scheme
from gateway.auth import idp_settings
from gateway.models import HealthCheck
from gateway.routers.k8s import k8s_router
from gateway.routers.results import results_router

Expand Down Expand Up @@ -36,16 +38,25 @@
# )


@app.get("/unsecure")
async def unsecure_test() -> dict:
"""Default greeting."""
return {"message": "Howdy anonymous"}


@app.get("/secure")
async def secure_test(token: str = Security(oauth2_scheme)):
"""Secured response greeting."""
return token
@app.get(
"/health",
tags=["healthcheck"],
summary="Perform a Health Check",
response_description="Return HTTP Status Code 200 (OK)",
status_code=status.HTTP_200_OK,
response_model=HealthCheck,
)
def get_health() -> HealthCheck:
"""
## Perform a Health Check
Endpoint to perform a healthcheck on. This endpoint can primarily be used Docker
to ensure a robust container orchestration and management is in place. Other
services which rely on proper functioning of the API service will not deploy if this
endpoint returns any other HTTP status code except 200 (OK).
Returns:
HealthCheck: Returns a JSON response with the health status
"""
return HealthCheck(status="OK")


app.include_router(
Expand Down

0 comments on commit c46d05e

Please sign in to comment.