From 14e5ee54eb050de714030946e5d3872402e4c228 Mon Sep 17 00:00:00 2001 From: medniy2000 Date: Tue, 30 Sep 2025 12:44:30 +0300 Subject: [PATCH 1/3] improve api health check --- .../interfaces/api/v1/endpoints/debug/resources.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/interfaces/api/v1/endpoints/debug/resources.py b/src/app/interfaces/api/v1/endpoints/debug/resources.py index b981c05..df1ef01 100644 --- a/src/app/interfaces/api/v1/endpoints/debug/resources.py +++ b/src/app/interfaces/api/v1/endpoints/debug/resources.py @@ -1,5 +1,6 @@ from typing import Annotated, Dict - +from fastapi.responses import JSONResponse +from starlette.status import HTTP_200_OK, HTTP_400_BAD_REQUEST from fastapi import APIRouter, Body, Request from src.app.application.container import container as services_container from src.app.interfaces.api.v1.endpoints.debug.schemas.req_schemas import MessageReq @@ -41,7 +42,13 @@ async def send_message( @router.get("/health-check/", status_code=200) async def health_check( request: Request, -) -> Dict[str, str]: +) -> JSONResponse: is_healthy = await services_container.common_service.is_healthy() status = "OK" if is_healthy else "NOT OK" - return {"status": status} + status_code = HTTP_200_OK if is_healthy else HTTP_400_BAD_REQUEST + resp = JSONResponse( + content={"status": status}, + status_code=status_code + ) + + return resp From b074322867df010ae4510851c4b72fe790c3b367 Mon Sep 17 00:00:00 2001 From: medniy2000 Date: Tue, 30 Sep 2025 13:00:02 +0300 Subject: [PATCH 2/3] update grpc health check --- src/app/interfaces/grpc/services/debug_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/interfaces/grpc/services/debug_service.py b/src/app/interfaces/grpc/services/debug_service.py index fee8e1f..0330b87 100644 --- a/src/app/interfaces/grpc/services/debug_service.py +++ b/src/app/interfaces/grpc/services/debug_service.py @@ -27,5 +27,5 @@ async def SendMessage(self, request, context) -> pb2.MessageResp: # type: ignor async def HealthCheck(self, request, context) -> pb2.HealthCheckResp: # type: ignore is_healthy = await services_container.common_service.is_healthy() - status = "OK" if is_healthy else "NOT OK" + status = "SERVING" if is_healthy else "NOT_SERVING" return pb2.HealthCheckResp(status=status) # type: ignore From a0e1165d481869a19dbc4b9c47d2f4965cd49d83 Mon Sep 17 00:00:00 2001 From: medniy2000 Date: Tue, 30 Sep 2025 13:00:56 +0300 Subject: [PATCH 3/3] after beautify --- .../interfaces/api/v1/endpoints/debug/resources.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/app/interfaces/api/v1/endpoints/debug/resources.py b/src/app/interfaces/api/v1/endpoints/debug/resources.py index df1ef01..ded5bde 100644 --- a/src/app/interfaces/api/v1/endpoints/debug/resources.py +++ b/src/app/interfaces/api/v1/endpoints/debug/resources.py @@ -1,11 +1,13 @@ -from typing import Annotated, Dict +from typing import Annotated + +from fastapi import APIRouter, Body, Request from fastapi.responses import JSONResponse from starlette.status import HTTP_200_OK, HTTP_400_BAD_REQUEST -from fastapi import APIRouter, Body, Request + from src.app.application.container import container as services_container -from src.app.interfaces.api.v1.endpoints.debug.schemas.req_schemas import MessageReq from src.app.config.settings import settings from src.app.infrastructure.messaging.mq_client import mq_client +from src.app.interfaces.api.v1.endpoints.debug.schemas.req_schemas import MessageReq router = APIRouter(prefix="/debug") @@ -46,9 +48,6 @@ async def health_check( is_healthy = await services_container.common_service.is_healthy() status = "OK" if is_healthy else "NOT OK" status_code = HTTP_200_OK if is_healthy else HTTP_400_BAD_REQUEST - resp = JSONResponse( - content={"status": status}, - status_code=status_code - ) + resp = JSONResponse(content={"status": status}, status_code=status_code) return resp