diff --git a/app/api/health.py b/app/api/health.py deleted file mode 100644 index dd36852..0000000 --- a/app/api/health.py +++ /dev/null @@ -1,50 +0,0 @@ -"""health check api""" - -from datetime import datetime -import platform -import sys -from typing import Any, Dict -from fastapi import APIRouter, status - - -router = APIRouter(prefix="/health", tags=["Health Check"]) - - -@router.get("", status_code=status.HTTP_200_OK) -async def health_check() -> Dict[str, Any]: - """ - Basic Health Check - Is System work properly? - """ - return { - "status": "healthy", - "timestamp": datetime.now().isoformat(), - "service": "LLearn API", - "version": "1.0.0", - } - - -@router.get("/detailed", status_code=status.HTTP_200_OK) -async def detailed_health_check() -> Dict[str, Any]: - """ - End point for detail health check - system info with dependency status - """ - return { - "status": "healthy", - "timestamp": datetime.now().isoformat(), - "service": { - "name": "LLearn API", - "version": "1.0.0", - "environment": "development", # TODO: 환경 설정에서 가져오기 - }, - "system": { - "platform": platform.system(), - "python_version": sys.version, - "architecture": platform.machine(), - }, - "dependencies": { - "database": "connected", # TODO: 실제 DB 연결 상태 확인 - "llm_service": "available", # TODO: 실제 LLM 서비스 상태 확인 - }, - } diff --git a/app/api/health_check.py b/app/api/health_check.py new file mode 100644 index 0000000..489d18f --- /dev/null +++ b/app/api/health_check.py @@ -0,0 +1,59 @@ +"""health check api""" + +from datetime import datetime, timezone +import platform +import sys +from typing import Any, Dict +from fastapi import APIRouter, status + +from app.core.config import settings +from app.schemas.health_check import ( + BasicHealthCheckResponse, + DependencyStatus, + DetailedHealthCheckResponse, + ServiceInfo, + SystemInfo, +) + + +router = APIRouter(prefix="/health", tags=["Health Check"]) + + +@router.get("", status_code=status.HTTP_200_OK) +async def health_check() -> BasicHealthCheckResponse: + """ + Basic Health Check + Is System work properly? + """ + return BasicHealthCheckResponse( + status="healthy", + timestamp=datetime.now(timezone.utc), + service=settings.service_name, + version=settings.service_version, + ) + + +@router.get("/detailed", status_code=status.HTTP_200_OK) +async def detailed_health_check() -> DetailedHealthCheckResponse: + """ + End point for detail health check + system info with dependency status + """ + return DetailedHealthCheckResponse( + status="healthy", + timestamp=datetime.now(timezone.utc), + service=ServiceInfo( + name=settings.service_name, + version=settings.service_version, + environment=settings.environment, + ), + system=SystemInfo( + platform=platform.system(), + python_version=sys.version, + architecture=platform.machine(), + ), + dependencies=DependencyStatus( + database="connected", # TODO: 실제 DB 연결 상태 확인 + llm_service="available", # TODO: 실제 LLM 서비스 상태 확인 + ), + ) diff --git a/app/core/config.py b/app/core/config.py index 2f23aac..3ad7f60 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -1,14 +1,15 @@ from pydantic_settings import BaseSettings, SettingsConfigDict + class Settings(BaseSettings): """Setting for Apps (Dependency)""" environment: str = "development" # 기본값만 넣어둠 openai_api_key: str = "" - model_config = SettingsConfigDict( - env_file=".env", - extra="allow" - ) + service_name: str = "LLearn API" + service_version: str = "1.0.0" + model_config = SettingsConfigDict(env_file=".env", extra="allow") + settings = Settings() diff --git a/app/main.py b/app/main.py index 1fca405..60f74f6 100644 --- a/app/main.py +++ b/app/main.py @@ -1,7 +1,7 @@ from fastapi import FastAPI # clean architectgure Framework layer from fastapi.middleware.cors import CORSMiddleware from app.api.errors import register_exception_handlers -from app.api.health import router as health_router +from app.api.health_check import router as health_router print(f"Health router: {health_router}") print(f"Health router routes: {health_router.routes}") diff --git a/app/schemas/health_check.py b/app/schemas/health_check.py new file mode 100644 index 0000000..73e382c --- /dev/null +++ b/app/schemas/health_check.py @@ -0,0 +1,38 @@ +from datetime import datetime +from pydantic import BaseModel, Field + + +class ServiceInfo(BaseModel): + name: str = Field(..., description="App Name") + version: str = Field(..., description="App Version") + environment: str = Field( + ..., description="실행 환경 (development/production/staging)" + ) + + +class SystemInfo(BaseModel): + platform: str = Field(..., description="OS 환경 (windows/iOS/Linux)") + python_version: str = Field(..., description="Python Version") + architecture: str = Field(..., description="시스템 아키텍처 (x86_64/arm64/etc)") + + +class DependencyStatus(BaseModel): + database: str = Field( + ..., description="database connection status (connected/disconnected)" + ) + llm_service: str = Field(..., description="llm_service(openai) available") + + +class BasicHealthCheckResponse(BaseModel): + status: str + timestamp: datetime + service: str + version: str + + +class DetailedHealthCheckResponse(BaseModel): + status: str + timestamp: datetime + service: ServiceInfo + system: SystemInfo + dependencies: DependencyStatus diff --git a/tests/unit/app/api/test_health_check.py b/tests/unit/app/api/test_health_check.py index 5b221e7..078007c 100644 --- a/tests/unit/app/api/test_health_check.py +++ b/tests/unit/app/api/test_health_check.py @@ -2,7 +2,7 @@ from fastapi.testclient import TestClient from fastapi import FastAPI -from app.api.health import router +from app.api.health_check import router @pytest.fixture @@ -22,7 +22,7 @@ def test_basic_health_check_returns_200(self, client: TestClient) -> None: response = client.get("/health") assert response.status_code == 200 - def testr_basic_health_check_response_structure(self, client: TestClient) -> None: + def test_basic_health_check_response_structure(self, client: TestClient) -> None: response = client.get("/health") data = response.json()