Skip to content

Commit 3859da1

Browse files
committed
updates
1 parent 42a6722 commit 3859da1

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

backend/health_check_api.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import logging
77
import asyncio
8+
import os
89
from datetime import datetime
910
from typing import Dict, Any, List
1011
from fastapi import APIRouter, HTTPException, status
@@ -382,12 +383,12 @@ async def services_health():
382383

383384
services_status = []
384385

385-
async def check_service_endpoint(name: str, url: str, timeout: float = 5.0) -> Dict[str, Any]:
386+
async def check_service_endpoint(name: str, url: str, timeout: float = 5.0, headers: Dict[str, str] = None) -> Dict[str, Any]:
386387
"""Helper to check a service health endpoint"""
387388
try:
388389
start = datetime.utcnow()
389390
async with httpx.AsyncClient(timeout=timeout) as client:
390-
response = await client.get(url)
391+
response = await client.get(url, headers=headers)
391392
latency_ms = (datetime.utcnow() - start).total_seconds() * 1000
392393

393394
is_healthy = response.status_code in [200, 201]
@@ -417,9 +418,29 @@ async def check_service_endpoint(name: str, url: str, timeout: float = 5.0) -> D
417418
"http://uchub-keycloak:8080/health/ready"
418419
)
419420

421+
# LiteLLM: try multiple hostnames since env var may have non-resolving hostname
422+
litellm_urls = [
423+
os.getenv("LITELLM_PROXY_URL", "").rstrip("/"),
424+
"http://unicorn-litellm-wilmer:4000",
425+
"http://litellm:4000",
426+
]
427+
# Pick first URL that has a resolvable host
428+
litellm_url = "http://unicorn-litellm-wilmer:4000"
429+
for url in litellm_urls:
430+
if url:
431+
try:
432+
import urllib.parse
433+
host = urllib.parse.urlparse(url).hostname
434+
if host:
435+
import socket
436+
socket.gethostbyname(host)
437+
litellm_url = url
438+
break
439+
except (socket.gaierror, Exception):
440+
continue
420441
litellm_check = check_service_endpoint(
421442
"LiteLLM",
422-
"http://localhost:4000/health"
443+
f"{litellm_url}/"
423444
)
424445

425446
claude_agents_check = check_service_endpoint(

0 commit comments

Comments
 (0)