diff --git a/tests/entrypoints/openai/test_basic.py b/tests/entrypoints/openai/test_basic.py index 2c370b01db6f2..de329d8cc6659 100644 --- a/tests/entrypoints/openai/test_basic.py +++ b/tests/entrypoints/openai/test_basic.py @@ -59,6 +59,5 @@ async def test_log_metrics(client: openai.AsyncOpenAI): base_url = str(client.base_url)[:-3].strip("/") response = requests.get(base_url + "/metrics") - response.raise_for_status() - assert response.json() is not None + assert response.status_code == HTTPStatus.OK diff --git a/vllm/entrypoints/openai/api_server.py b/vllm/entrypoints/openai/api_server.py index 45c634b4a2991..a86a5099d8b8f 100644 --- a/vllm/entrypoints/openai/api_server.py +++ b/vllm/entrypoints/openai/api_server.py @@ -70,11 +70,13 @@ async def _force_log(): router = APIRouter() -# Add prometheus asgi middleware to route /metrics requests -route = Mount("/metrics", make_asgi_app()) -# Workaround for 307 Redirect for /metrics -route.path_regex = re.compile('^/metrics(?P.*)$') -router.routes.append(route) + +def mount_metrics(app: fastapi.FastAPI): + # Add prometheus asgi middleware to route /metrics requests + metrics_route = Mount("/metrics", make_asgi_app()) + # Workaround for 307 Redirect for /metrics + metrics_route.path_regex = re.compile('^/metrics(?P.*)$') + app.routes.append(metrics_route) @router.get("/health") @@ -164,6 +166,8 @@ def build_app(args): app.include_router(router) app.root_path = args.root_path + mount_metrics(app) + app.add_middleware( CORSMiddleware, allow_origins=args.allowed_origins,