Skip to content
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
50 changes: 0 additions & 50 deletions app/api/health.py

This file was deleted.

59 changes: 59 additions & 0 deletions app/api/health_check.py
Original file line number Diff line number Diff line change
@@ -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 서비스 상태 확인
),
)
9 changes: 5 additions & 4 deletions app/core/config.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -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}")
Expand Down
38 changes: 38 additions & 0 deletions app/schemas/health_check.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tests/unit/app/api/test_health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
Loading