IDKHowToCodeFr commited on
Commit
9ef7f14
·
1 Parent(s): 84b8635

fix(health): allow projects without warmup to report healthy status

Browse files
Files changed (2) hide show
  1. main.py +6 -8
  2. tests/test_host.py +1 -1
main.py CHANGED
@@ -5,11 +5,9 @@ import os
5
  import time
6
  from contextlib import asynccontextmanager
7
  from typing import Callable
8
-
9
  from fastapi import FastAPI, HTTPException, Request, Response
10
  from fastapi.middleware.cors import CORSMiddleware
11
  from starlette.middleware.base import BaseHTTPMiddleware
12
-
13
  from registry import PROJECT_REGISTRY
14
 
15
  logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
@@ -153,15 +151,15 @@ load_routers()
153
 
154
  @app.get("/health")
155
  def health():
156
- all_mounted = bool(loaded_projects) and len(failed_projects) == 0
157
- all_warmed = bool(loaded_projects) and all(warm_status.get(p) == "warmed" for p in loaded_projects)
158
 
159
- if all_mounted and all_warmed:
160
- overall_status = "healthy"
161
- elif loaded_projects:
162
  overall_status = "degraded"
163
  else:
164
- overall_status = "unhealthy"
165
 
166
  return {
167
  "status": overall_status,
 
5
  import time
6
  from contextlib import asynccontextmanager
7
  from typing import Callable
 
8
  from fastapi import FastAPI, HTTPException, Request, Response
9
  from fastapi.middleware.cors import CORSMiddleware
10
  from starlette.middleware.base import BaseHTTPMiddleware
 
11
  from registry import PROJECT_REGISTRY
12
 
13
  logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
 
151
 
152
  @app.get("/health")
153
  def health():
154
+ any_warmup_failed = any(status.startswith("failed:") for status in warm_status.values())
155
+ has_mount_failures = len(failed_projects) > 0
156
 
157
+ if not loaded_projects:
158
+ overall_status = "unhealthy"
159
+ elif has_mount_failures or any_warmup_failed:
160
  overall_status = "degraded"
161
  else:
162
+ overall_status = "healthy"
163
 
164
  return {
165
  "status": overall_status,
tests/test_host.py CHANGED
@@ -275,7 +275,7 @@ def test_project_without_warmup(monkeypatch):
275
  res = client.get("/health")
276
  assert res.status_code == 200
277
  data = res.json()
278
- assert data["status"] == "degraded"
279
  assert data["warm_status"]["/nowarm"] == "no warmup"
280
  assert client.get("/nowarm/ping").status_code == 200
281
 
 
275
  res = client.get("/health")
276
  assert res.status_code == 200
277
  data = res.json()
278
+ assert data["status"] == "healthy"
279
  assert data["warm_status"]["/nowarm"] == "no warmup"
280
  assert client.get("/nowarm/ping").status_code == 200
281