Skip to content

Commit

Permalink
WI-15: Add health check for site status
Browse files Browse the repository at this point in the history
/core/health-check endpoint will provide ping status to validate nginx, uwsgi, django worker is up or not.
  • Loading branch information
chandra-tacc committed Dec 12, 2023
1 parent f7bdb55 commit 35c210a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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 @@ -5,6 +5,8 @@
from portal.libs.exceptions import PortalLibException
import requests
import json
from portal.views.views import health_check


# route to be used for testing purposes
API_ROUTE = '/api/system-monitor/'
Expand Down Expand Up @@ -110,3 +112,8 @@ 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'}
6 changes: 5 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,7 @@ 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)

0 comments on commit 35c210a

Please sign in to comment.