initial commit
This commit is contained in:
commit
88c14b627e
224 files changed
+17204
No files matched your search
@@ -0,0 +1 @@
|
||||
"""Operational scaffold for the Lincodex ML service."""
|
||||
@@ -0,0 +1 @@
|
||||
"""HTTP endpoints for the ML service."""
|
||||
@@ -0,0 +1,33 @@
|
||||
from fastapi import APIRouter, Response, status
|
||||
|
||||
from lincodex_ml.api.models import MLHealthResponse, MLReadinessResponse
|
||||
|
||||
router = APIRouter(tags=["health"])
|
||||
|
||||
|
||||
@router.get(
|
||||
"/healthz",
|
||||
operation_id="GetMLHealthz",
|
||||
response_model=MLHealthResponse,
|
||||
status_code=status.HTTP_200_OK,
|
||||
summary="Check whether the ML process is responding.",
|
||||
)
|
||||
async def get_healthz() -> MLHealthResponse:
|
||||
return MLHealthResponse(status="ok")
|
||||
|
||||
|
||||
@router.get(
|
||||
"/readyz",
|
||||
operation_id="GetMLReadyz",
|
||||
response_model=MLReadinessResponse,
|
||||
responses={
|
||||
status.HTTP_503_SERVICE_UNAVAILABLE: {
|
||||
"model": MLReadinessResponse,
|
||||
"description": "No inference runtime is available.",
|
||||
}
|
||||
},
|
||||
summary="Check whether an inference runtime is available.",
|
||||
)
|
||||
async def get_readyz(response: Response) -> MLReadinessResponse:
|
||||
response.status_code = status.HTTP_503_SERVICE_UNAVAILABLE
|
||||
return MLReadinessResponse(status="not_ready")
|
||||
@@ -0,0 +1,20 @@
|
||||
# generated by datamodel-codegen:
|
||||
# filename: openapi.bundle.yml
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class MLHealthResponse(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
extra="forbid",
|
||||
)
|
||||
status: Literal["ok"]
|
||||
|
||||
|
||||
class MLReadinessResponse(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
extra="forbid",
|
||||
)
|
||||
status: Literal["ready", "not_ready"]
|
||||
@@ -0,0 +1 @@
|
||||
"""Service infrastructure adapters."""
|
||||
@@ -0,0 +1,28 @@
|
||||
import json
|
||||
import logging
|
||||
from datetime import UTC, datetime
|
||||
from typing import override
|
||||
|
||||
|
||||
class JsonFormatter(logging.Formatter):
|
||||
@override
|
||||
def format(self, record: logging.LogRecord) -> str:
|
||||
return json.dumps(
|
||||
{
|
||||
"timestamp": datetime.now(UTC).isoformat(),
|
||||
"level": record.levelname.lower(),
|
||||
"logger": record.name,
|
||||
"message": record.getMessage(),
|
||||
},
|
||||
ensure_ascii=False,
|
||||
separators=(",", ":"),
|
||||
)
|
||||
|
||||
|
||||
def configure_logging() -> None:
|
||||
handler = logging.StreamHandler()
|
||||
handler.setFormatter(JsonFormatter())
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.handlers.clear()
|
||||
root_logger.addHandler(handler)
|
||||
root_logger.setLevel(logging.INFO)
|
||||
@@ -0,0 +1,17 @@
|
||||
from fastapi import FastAPI
|
||||
from prometheus_client import REGISTRY, make_asgi_app
|
||||
|
||||
from lincodex_ml.api.health import router as health_router
|
||||
from lincodex_ml.infra.logging import configure_logging
|
||||
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
configure_logging()
|
||||
application = FastAPI(title="Lincodex ML Operational API", version="0.1.0")
|
||||
application.openapi_version = "3.1.2"
|
||||
application.include_router(health_router)
|
||||
application.mount("/metrics", make_asgi_app(registry=REGISTRY))
|
||||
return application
|
||||
|
||||
|
||||
app = create_app()
|
||||
Reference in new issue
Block a user