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

feat: Add a health check. #4

Merged
merged 4 commits into from
Aug 30, 2024
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
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ COPY --from=builder /opt/venv /opt/venv
ENV PATH=/opt/venv/bin:$PATH

# Download space models.
RUN mkdir -p /opt/models && \
RUN mkdir -p /var/log/uvicorn /opt/models && \
python3 -m spacy download en_core_web_sm && \
python3 -m spacy download es_core_news_sm && \
python3 -m spacy download fr_core_news_sm
Expand Down
22 changes: 22 additions & 0 deletions html/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ class Response(BaseModel):

#------------------------------------------------------------------------------#

class HealthCheckResponse(BaseModel):
"""
Health check response.

Attributes:
status (str): the health status of the app, defaults to "ok".
"""
status: str

# Health check endpoint.
@app.get('/status', status_code=200)
def health_status() -> HealthCheckResponse:
"""
A very simple health check endpoint.

Returns:
HealthCheckResponse: the health check response.
"""
return HealthCheckResponse(status="ok")

#------------------------------------------------------------------------------#

class TextSplitRequest(Request):
"""
A text splitting request.
Expand Down
38 changes: 38 additions & 0 deletions html/log_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: 1
disable_existing_loggers: False
formatters:
default:
"()": uvicorn.logging.DefaultFormatter
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
access:
"()": uvicorn.logging.AccessFormatter
format: "[%(asctime)s %(process)d:%(threadName)s] %(name)s - %(levelname)s - %(message)s | %(filename)s:%(lineno)d"

handlers:
default:
class: logging.FileHandler
level: INFO
formatter: default
filename: /var/log/uvicorn/uvicorn.log
encoding: utf8
mode: a

access:
formatter: access
class: logging.FileHandler
level: INFO
formatter: default
filename: /var/log/uvicorn/access.log
encoding: utf8
mode: a

loggers:
uvicorn.error:
level: INFO
handlers: [default]
propagate: no

uvicorn.access:
level: INFO
handlers: [access]
propagate: no
1 change: 1 addition & 0 deletions html/server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
uvicorn app:app \
--host ${SERVER_HOST:-0.0.0.0} \
--port ${SERVER_PORT:-80} \
--log-config=log_config.yaml \
--reload