Skip to content

Commit

Permalink
Merge pull request #37 from ropable/master
Browse files Browse the repository at this point in the history
Ease healthcheck timing, add Gunicorn, allow 60s response caching
  • Loading branch information
ropable authored Dec 20, 2023
2 parents b06f839 + 3e02e36 commit 3e5216b
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN apt-get update -y \
# Install Python libs using Poetry.
FROM builder_base_healthcheck as python_libs_healthcheck
WORKDIR /app
ARG POETRY_VERSION=1.6.1
ARG POETRY_VERSION=1.7.1
RUN pip install poetry=="${POETRY_VERSION}"
COPY poetry.lock pyproject.toml ./
RUN poetry config virtualenvs.create false \
Expand All @@ -27,9 +27,9 @@ RUN groupadd -g "${GID}" appuser \

# Install the project.
FROM python_libs_healthcheck
COPY status.py ./
COPY gunicorn.py status.py ./
COPY static ./static

USER ${UID}
EXPOSE 8080
CMD ["python", "status.py"]
CMD ["gunicorn", "status:application", "--config", "gunicorn.py"]
14 changes: 14 additions & 0 deletions gunicorn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Gunicorn configuration settings.
import multiprocessing

bind = ":8080"
# Don't start too many workers:
workers = min(multiprocessing.cpu_count(), 4)
# Give workers an expiry:
max_requests = 2048
max_requests_jitter = 256
preload_app = True
# Set longer timeout for workers
timeout = 600
# Disable access logging.
accesslog = None
20 changes: 14 additions & 6 deletions kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ spec:
path: /liveness
port: 8080
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 3
periodSeconds: 15
successThreshold: 1
failureThreshold: 3
timeoutSeconds: 2
timeoutSeconds: 10
readinessProbe:
httpGet:
path: /readiness
port: 8080
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 3
periodSeconds: 15
successThreshold: 1
failureThreshold: 3
timeoutSeconds: 2
timeoutSeconds: 10
securityContext:
runAsNonRoot: true
privileged: false
Expand All @@ -47,4 +47,12 @@ spec:
drop:
- ALL
readOnlyRootFilesystem: true
volumeMounts:
- mountPath: /tmp
name: tmpfs-ram
volumes:
- name: tmpfs-ram
emptyDir:
medium: "Memory"
restartPolicy: Always
terminationGracePeriodSeconds: 180
2 changes: 1 addition & 1 deletion kustomize/overlays/prod/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ labels:
variant: prod
images:
- name: ghcr.io/dbca-wa/healthcheck
newTag: 1.1.13
newTag: 1.1.14
patches:
- path: deployment_patch.yaml
- path: service_patch.yaml
33 changes: 32 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "healthcheck"
version = "1.1.13"
version = "1.1.14"
description = "Internal service endpoint health check for Spatial Support System"
authors = ["ASI <[email protected]>"]

Expand All @@ -10,6 +10,7 @@ bottle = "0.12.25"
requests = "2.31.0"
pytz = "2023.3.post1"
python-dotenv = "1.0.0"
gunicorn = "21.2.0"

[tool.poetry.group.dev.dependencies]
ipython = "^8.10.0"
Expand Down
7 changes: 4 additions & 3 deletions status.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ def healthcheck():
def healthcheck_json():
d = healthcheck()
response.content_type = "application/json"
# Mark response as 'never cache'.
response.set_header("Cache-Control", "private, max-age=0")
# Mark response as "cache for 60 seconds".
response.set_header("Cache-Control", "max-age=60")
return json.dumps(d)


Expand Down Expand Up @@ -514,7 +514,8 @@ def healthcheck_http():
output += "<strong>Finished checks, something is wrong =(</strong>"
output += "</p>"

response.set_header("Cache-Control", "private, max-age=0")
# Mark response as "cache for 60 seconds".
response.set_header("Cache-Control", "max-age=60")
return OUTPUT_TEMPLATE.format(output)


Expand Down

0 comments on commit 3e5216b

Please sign in to comment.