Skip to content

Commit

Permalink
feat(devops): readiness probe to give build and release info
Browse files Browse the repository at this point in the history
KK-1334.

The development team has decided that the readiness probe should
response with some refined server release and build information. Copied
the readiness probe implementation from Notification Service to make the
Kukkuu consistent with other apps.

Reference:
https://github.com/City-of-Helsinki/notification-service-api/blob/master/notification_service/urls.py
  • Loading branch information
nikomakela committed Dec 12, 2024
1 parent 1dcc0ff commit f8db348
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions kukkuu/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import subprocess
from datetime import datetime

import environ
import sentry_sdk
Expand Down Expand Up @@ -88,6 +89,7 @@
BROWSER_TEST_GROUP_NAME=(str, "Browser test"),
BROWSER_TEST_AD_GROUP_NAME=(str, "kukkuu_browser_test"),
KUKKUU_DEFAULT_LOGGING_LEVEL=(str, "INFO"),
APP_RELEASE=(str, ""),
)

if os.path.exists(env_file):
Expand Down Expand Up @@ -399,6 +401,11 @@

HELUSERS_BACK_CHANNEL_LOGOUT_ENABLED = env("HELUSERS_BACK_CHANNEL_LOGOUT_ENABLED")

# release information
APP_RELEASE = env("APP_RELEASE")
# get build time from a file in docker image
APP_BUILD_TIME = datetime.fromtimestamp(os.path.getmtime(__file__))

# local_settings.py can be used to override environment-specific settings
# like database and email that differ between development and production.
local_settings_path = os.path.join(checkout_dir(), "local_settings.py")
Expand Down
12 changes: 10 additions & 2 deletions kukkuu/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.conf.urls.static import static
from django.http import HttpResponse
from django.http import JsonResponse
from django.urls import include, path, re_path
from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
Expand All @@ -10,6 +10,7 @@

from common.utils import get_api_version
from custom_health_checks.views import HealthCheckJSONView
from kukkuu import __version__
from kukkuu.views import SentryGraphQLView
from reports.api import ChildViewSet, EventGroupViewSet, EventViewSet, VenueViewSet

Expand Down Expand Up @@ -51,7 +52,14 @@


def readiness(*args, **kwargs):
return HttpResponse(status=200)
response_json = {
"status": "ok",
"release": settings.APP_RELEASE,
"packageVersion": __version__,
"commitHash": settings.REVISION,
"buildTime": settings.APP_BUILD_TIME.strftime("%Y-%m-%dT%H:%M:%S.000Z"),
}
return JsonResponse(response_json, status=200)


urlpatterns += [
Expand Down

0 comments on commit f8db348

Please sign in to comment.