From 022980e854834ac12bab433a1e1a358c4a881c97 Mon Sep 17 00:00:00 2001 From: asadeg02 Date: Mon, 7 Apr 2025 14:23:42 -0400 Subject: [PATCH 1/3] fix: update MongoDB health check to ensure compatibility with AWS task health checks --- backend/backend/apis/bwwc.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/backend/apis/bwwc.py b/backend/backend/apis/bwwc.py index 17f111e..d3a0ada 100644 --- a/backend/backend/apis/bwwc.py +++ b/backend/backend/apis/bwwc.py @@ -305,14 +305,16 @@ def backup(req: HttpRequest) -> HttpResponse: @csrf_exempt -def mongo_health(req: HttpRequest) -> HttpResponse: - if req.method == "GET": - if not engine.is_mongodb_running(): - return HttpResponseBadRequest("MongoDB is down") +def mongo_health(req: HttpRequest) -> JsonResponse: + if req.method != "GET": + return JsonResponse({"status": "Method Not Allowed"}, status=405) + try: + if engine.is_mongodb_running(): + return JsonResponse({"status": "ok"}, status=200) else: - return HttpResponse("MongoDB is up") - else: - return HttpResponseBadRequest("Invalid request method") + return JsonResponse({"status": "error", "message": "MongoDB is down"}, status=503) + except Exception as e: + return JsonResponse({"status": "error", "message": str(e)}, status=503) def get_urlpatterns(): From 351b246b011dac98f91456a4a7de02fa2a6ffce3 Mon Sep 17 00:00:00 2001 From: asadeg02 Date: Tue, 8 Apr 2025 13:31:12 -0400 Subject: [PATCH 2/3] feat: add relaxed health check endpoint --- backend/backend/apis/bwwc.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/backend/apis/bwwc.py b/backend/backend/apis/bwwc.py index d3a0ada..93be996 100644 --- a/backend/backend/apis/bwwc.py +++ b/backend/backend/apis/bwwc.py @@ -306,15 +306,17 @@ def backup(req: HttpRequest) -> HttpResponse: @csrf_exempt def mongo_health(req: HttpRequest) -> JsonResponse: - if req.method != "GET": - return JsonResponse({"status": "Method Not Allowed"}, status=405) - try: - if engine.is_mongodb_running(): - return JsonResponse({"status": "ok"}, status=200) + if req.method == "GET": + if not engine.is_mongodb_running(): + return HttpResponseBadRequest("MongoDB is down") else: - return JsonResponse({"status": "error", "message": "MongoDB is down"}, status=503) - except Exception as e: - return JsonResponse({"status": "error", "message": str(e)}, status=503) + return HttpResponse("MongoDB is up") + else: + return HttpResponseBadRequest("Invalid request method") + +@csrf_exempt +def app_health_check(req: HttpRequest) -> HttpResponse: + return HttpResponse("OK") def get_urlpatterns(): @@ -331,4 +333,5 @@ def get_urlpatterns(): path("api/bwwc/get_submission_history/", get_submission_history), path("api/bwwc/backup/", backup), path("api/bwwc/health/", mongo_health), + path("/api/bwwc/healthz/", app_health_check), ] From afcff82c00b42d344eb0af2664f387a71b8b280c Mon Sep 17 00:00:00 2001 From: asadeg02 Date: Wed, 9 Apr 2025 18:06:13 -0400 Subject: [PATCH 3/3] fix: fix the issue with aws health endpoint --- backend/backend/apis/bwwc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/backend/apis/bwwc.py b/backend/backend/apis/bwwc.py index 419e965..c8318b9 100644 --- a/backend/backend/apis/bwwc.py +++ b/backend/backend/apis/bwwc.py @@ -308,7 +308,7 @@ def backup(req: HttpRequest) -> HttpResponse: def mongo_health(req: HttpRequest) -> HttpResponse: if req.method == "GET": if not engine.is_mongodb_running(): - return HttpResponseBadRequest(f"MongoDB is down at: {engine.mongo_uri}") + return HttpResponseBadRequest(f"MongoDB is downnn at: mongodb://{engine.mongo_user}:{engine.mongo_password}@{engine.mongo_host}:{engine.mongo_port}/{engine.mongo_db}?{engine.mongo_params}") else: return HttpResponse("MongoDB is up") else: @@ -333,5 +333,5 @@ def get_urlpatterns(): path("api/bwwc/get_submission_history/", get_submission_history), path("api/bwwc/backup/", backup), path("api/bwwc/health/", mongo_health), - path("/api/bwwc/healthz/", app_health_check), + path("api/bwwc/healthz/", app_health_check), ]