mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-25 22:20:43 +00:00
* test(integration): update two spend tests left stale by the rust spend log writer The pool-connection shutdown test turns the ledger off, so its proxy reserves no spend log writer connections and Prisma got four instead of the two the test blocks. The spend log outage test now waits for Prisma to reconnect on every worker before cleanup, since the Rust writer lands the rows first. * test(integration): wait on an uncached Prisma probe after the spend log outage The readiness route caches a connected database for 15 seconds, so the wait passed on a fast runner while Prisma was still disconnected.
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
import asyncio
|
|
import os
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
from typing import Final
|
|
|
|
from fastapi import Response
|
|
from fastapi.responses import JSONResponse
|
|
from pydantic import TypeAdapter
|
|
|
|
READINESS_BODY: Final = TypeAdapter(dict[str, object])
|
|
|
|
|
|
def configure_executor() -> None:
|
|
asyncio.get_running_loop().set_default_executor(
|
|
ThreadPoolExecutor(max_workers=32, thread_name_prefix="integration-provider")
|
|
)
|
|
|
|
|
|
async def worker_readiness() -> JSONResponse:
|
|
from litellm.proxy.health_endpoints._health_endpoints import health_readiness
|
|
|
|
response: Final = Response()
|
|
body: Final = READINESS_BODY.validate_python(await health_readiness(response))
|
|
return JSONResponse(
|
|
content=body, status_code=response.status_code, headers={"x-integration-worker-pid": str(os.getpid())}
|
|
)
|
|
|
|
|
|
async def worker_database() -> JSONResponse:
|
|
"""Whether this worker's Prisma client answers a query right now, without the readiness cache."""
|
|
from litellm.proxy.proxy_server import prisma_client
|
|
|
|
connected = False
|
|
if prisma_client is not None:
|
|
try:
|
|
await prisma_client.health_check()
|
|
connected = True
|
|
except Exception:
|
|
connected = False
|
|
return JSONResponse(
|
|
content={"db": "connected" if connected else "disconnected"},
|
|
headers={"x-integration-worker-pid": str(os.getpid())},
|
|
)
|
|
|
|
|
|
async def worker_deployment_ids(model_name: str) -> JSONResponse:
|
|
from litellm.proxy.proxy_server import llm_router
|
|
|
|
model_ids: Final = [] if llm_router is None else llm_router.get_model_ids(model_name=model_name)
|
|
return JSONResponse(content={"model_ids": model_ids}, headers={"x-integration-worker-pid": str(os.getpid())})
|
|
|
|
|
|
async def worker_general_setting(name: str) -> JSONResponse:
|
|
from litellm.proxy.proxy_server import proxy_config
|
|
|
|
return JSONResponse(
|
|
content={"value": proxy_config.settings.get(name)}, headers={"x-integration-worker-pid": str(os.getpid())}
|
|
)
|
|
|
|
|
|
def configure_readiness() -> None:
|
|
from litellm.proxy.proxy_server import app
|
|
|
|
app.add_api_route("/health/integration-readiness", worker_readiness, include_in_schema=False)
|
|
app.add_api_route("/health/integration-database", worker_database, include_in_schema=False)
|
|
app.add_api_route("/health/integration-deployment-ids", worker_deployment_ids, include_in_schema=False)
|
|
app.add_api_route("/health/integration-general-setting", worker_general_setting, include_in_schema=False)
|