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

WI-15: Add health check for site status #919

Merged
merged 5 commits into from
Dec 12, 2023
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
5 changes: 5 additions & 0 deletions server/portal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from django.views.generic.base import TemplateView
from django.urls import path, re_path, include
from impersonate import views as impersonate_views
from portal.views.views import health_check
admin.autodiscover()

urlpatterns = [
Expand Down Expand Up @@ -112,4 +113,8 @@
# version check.
path('version/', portal_version),

# health check
path('core/health-check', health_check)


] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
7 changes: 7 additions & 0 deletions server/portal/views/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests
import json


# route to be used for testing purposes
API_ROUTE = '/api/system-monitor/'

Expand Down Expand Up @@ -110,3 +111,9 @@ def test_exception(client, api_method_mock):
response = client.get(API_ROUTE)
assert response.status_code == 500
assert json.loads(response.content) == {'message': 'Something went wrong here...'}


def test_health_check(client):
response = client.get('/core/health-check')
assert response.status_code == 200
assert json.loads(response.content) == {'status': 'healthy'}
7 changes: 6 additions & 1 deletion server/portal/views/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from django.http import HttpResponse
from django.http import HttpResponse, JsonResponse

logger = logging.getLogger(__name__)

Expand All @@ -23,3 +23,8 @@ def project_version(request):
version = 'UNKNOWN'

return HttpResponse(version, content_type='text/plain')


def health_check(request):
health_status = {'status': 'healthy'}
return JsonResponse(health_status)