diff --git a/backend/backend/base_urls.py b/backend/backend/base_urls.py index 1d235aad6..3a37717ab 100644 --- a/backend/backend/base_urls.py +++ b/backend/backend/base_urls.py @@ -22,4 +22,5 @@ f"{settings.API_DEPLOYMENT_PATH_PREFIX}/pipeline/", include("pipeline_v2.public_api_urls"), ), + path("", include("health.urls")), ] diff --git a/backend/backend/public_urls_v2.py b/backend/backend/public_urls_v2.py index dee9b28df..366fc695f 100644 --- a/backend/backend/public_urls_v2.py +++ b/backend/backend/public_urls_v2.py @@ -33,6 +33,8 @@ path("flags/", include("feature_flag.urls")), # Pipeline path("pipeline/", include("pipeline_v2.public_api_urls")), + # health checks + path("", include("health.urls")), ] if settings.ADMIN_ENABLED: # Admin URLs diff --git a/backend/backend/settings/base.py b/backend/backend/settings/base.py index 025da5eb5..c9614c1dc 100644 --- a/backend/backend/settings/base.py +++ b/backend/backend/settings/base.py @@ -224,6 +224,8 @@ def get_required_setting( "django_celery_beat", # For additional helper commands "commands", + # health checks + "health", ) v2_apps = ( "migrating.v2", @@ -446,6 +448,8 @@ def get_required_setting( # White lists workflow-api-deployment path WHITELISTED_PATHS.append(f"/{API_DEPLOYMENT_PATH_PREFIX}") +# Whitelisting health check API +WHITELISTED_PATHS.append("/health") # API Doc Generator Settings # https://drf-yasg.readthedocs.io/en/stable/settings.html diff --git a/backend/health/__init__.py b/backend/health/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/backend/health/apps.py b/backend/health/apps.py new file mode 100644 index 000000000..e860540e5 --- /dev/null +++ b/backend/health/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class HealthConfig(AppConfig): + name = "health" diff --git a/backend/health/urls.py b/backend/health/urls.py new file mode 100644 index 000000000..7e4143c84 --- /dev/null +++ b/backend/health/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from rest_framework.urlpatterns import format_suffix_patterns + +from .views import health_check + +urlpatterns = format_suffix_patterns( + [path("health", health_check, name="health-check")] +) diff --git a/backend/health/views.py b/backend/health/views.py new file mode 100644 index 000000000..715b17902 --- /dev/null +++ b/backend/health/views.py @@ -0,0 +1,15 @@ +import logging + +from django.views.decorators.http import require_http_methods +from rest_framework.decorators import api_view +from rest_framework.request import Request +from rest_framework.response import Response + +logger = logging.getLogger(__name__) + + +@api_view(["GET"]) +@require_http_methods(["GET"]) +def health_check(request: Request) -> Response: + logger.debug("Verifying backend health..") + return Response(status=200) diff --git a/prompt-service/src/unstract/prompt_service/main.py b/prompt-service/src/unstract/prompt_service/main.py index 7942ff292..617453b9f 100644 --- a/prompt-service/src/unstract/prompt_service/main.py +++ b/prompt-service/src/unstract/prompt_service/main.py @@ -83,6 +83,11 @@ def wrapper(*args: Any, **kwargs: Any) -> Any: return wrapper +@app.route("/health", methods=["GET"], endpoint="health_check") +def health_check() -> str: + return "OK" + + @app.route( "/answer-prompt", endpoint="answer_prompt",