Skip to content

Commit 1949694

Browse files
committed
feat: use django-helsinki-health-endpoints for readiness and healthz
Make use of django-helsinki-health-endpoints library to publish readiness and healthz endpoints. Add SENTRY_RELEASE to django settings from env for the library. Refs: KEH-242
1 parent 7ff61ce commit 1949694

5 files changed

Lines changed: 20 additions & 16 deletions

File tree

atv/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
if os.path.exists(env_file):
6868
env.read_env(env_file)
6969

70+
# Django helsinki health endpoints
71+
SENTRY_RELEASE = env.str("SENTRY_RELEASE")
72+
7073
SENTRY_TRACES_SAMPLE_RATE = env("SENTRY_TRACES_SAMPLE_RATE")
7174
SENTRY_TRACES_IGNORE_PATHS = env("SENTRY_TRACES_IGNORE_PATHS")
7275

@@ -89,7 +92,7 @@ def sentry_traces_sampler(sampling_context: SamplingContext) -> float:
8992
sentry_sdk.init(
9093
dsn=env("SENTRY_DSN"),
9194
environment=env("SENTRY_ENVIRONMENT"),
92-
release=env("SENTRY_RELEASE"),
95+
release=SENTRY_RELEASE,
9396
integrations=[DjangoIntegration()],
9497
traces_sampler=sentry_traces_sampler,
9598
profile_session_sample_rate=env("SENTRY_PROFILE_SESSION_SAMPLE_RATE"),
@@ -161,6 +164,7 @@ def sentry_traces_sampler(sampling_context: SamplingContext) -> float:
161164
"audit_log",
162165
"logger_extra",
163166
"resilient_logger",
167+
"helsinki_health_endpoints",
164168
]
165169

166170
MIDDLEWARE = [

atv/tests/test_endpoints.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
def test_healthz_and_readiness_endpoints(client):
1+
import pytest
2+
3+
4+
def test_healthz_endpoint(client):
25
response = client.get("/healthz")
36
assert response.status_code == 200
47

8+
9+
@pytest.mark.django_db
10+
def test_readiness_endpoint(client):
511
response = client.get("/readiness")
612
assert response.status_code == 200

atv/urls.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from django.conf import settings
22
from django.contrib import admin
3-
from django.http import HttpResponse
43
from django.urls import include, path
54
from drf_spectacular.views import (
65
SpectacularAPIView,
@@ -60,17 +59,6 @@
6059
),
6160
]
6261

63-
#
64-
# Kubernetes liveness & readiness probes
65-
#
66-
67-
68-
def healthz(*args, **kwargs):
69-
return HttpResponse(status=200)
70-
7162

72-
def readiness(*args, **kwargs):
73-
return HttpResponse(status=200)
74-
75-
76-
urlpatterns += [path("healthz", healthz), path("readiness", readiness)]
63+
# Kubernetes liveness & readiness probes
64+
urlpatterns += [path("", include("helsinki_health_endpoints.urls"))]

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ django-environ
44
django-filter
55
django-guardian
66
django-helusers
7+
django-helsinki-health-endpoints
78
django-logger-extra
89
django-resilient-logger
910
django-searchable-encrypted-fields

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ django==5.2.12 \
154154
# django-cors-headers
155155
# django-filter
156156
# django-guardian
157+
# django-helsinki-health-endpoints
157158
# django-helusers
158159
# django-logger-extra
159160
# django-resilient-logger
@@ -178,6 +179,10 @@ django-guardian==3.2.0 \
178179
--hash=sha256:0768565a057988a93fc4a1d93649c4a794abfd7473a8408a079cfbf83c559d77 \
179180
--hash=sha256:9e18ecd2e211b665972690c2d03d27bce0ea4932b5efac24a4bb9d526950a69e
180181
# via -r requirements.in
182+
django-helsinki-health-endpoints==1.0.0 \
183+
--hash=sha256:75670113e99bfd1fc23e317a3a22cff563140f495655c2a5f6ab219389dafd52 \
184+
--hash=sha256:eebf1baa6917d7b0e11123aec191df773883102ec1653025a86d7037dba389e2
185+
# via -r requirements.in
181186
django-helusers==0.14.0 \
182187
--hash=sha256:424f97e7aa6792ae255de56344f765795444849ea82e9d4e01666494c28e960c \
183188
--hash=sha256:79b922d51278a9e9793a00279782e5455b72e9e9d0f261dd17be2f0dbcbaa1f9

0 commit comments

Comments
 (0)