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

Health check API for backend & Prompt Sevice #1048

Merged
merged 5 commits into from
Jan 7, 2025
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
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
Loading