Skip to content

Commit

Permalink
Health check API for backend & Prompt Sevice (#1048)
Browse files Browse the repository at this point in the history
* Health check APIs

* Health Check for prompt service

* removing debugging changes

* Fixing security hotspots

* Changing health check endpoints
  • Loading branch information
harini-venkataraman authored Jan 7, 2025
1 parent 55b3028 commit ae00a49
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/backend/base_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
f"{settings.API_DEPLOYMENT_PATH_PREFIX}/pipeline/",
include("pipeline_v2.public_api_urls"),
),
path("", include("health.urls")),
]
2 changes: 2 additions & 0 deletions backend/backend/public_urls_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions backend/backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def get_required_setting(
"django_celery_beat",
# For additional helper commands
"commands",
# health checks
"health",
)
v2_apps = (
"migrating.v2",
Expand Down Expand Up @@ -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
Expand Down
Empty file added backend/health/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions backend/health/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class HealthConfig(AppConfig):
name = "health"
8 changes: 8 additions & 0 deletions backend/health/urls.py
Original file line number Diff line number Diff line change
@@ -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")]
)
15 changes: 15 additions & 0 deletions backend/health/views.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions prompt-service/src/unstract/prompt_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ae00a49

Please sign in to comment.