Skip to content

Commit b7962ea

Browse files
DarkLight1337jimpang
authored andcommitted
[Bugfix][Frontend] Fix missing /metrics endpoint (vllm-project#6463)
1 parent 368ef77 commit b7962ea

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from http import HTTPStatus
2+
3+
import openai
4+
import pytest
5+
import requests
6+
7+
from vllm.version import __version__ as VLLM_VERSION
8+
9+
from ...utils import RemoteOpenAIServer
10+
11+
MODEL_NAME = "HuggingFaceH4/zephyr-7b-beta"
12+
13+
14+
@pytest.fixture(scope="module")
15+
def server():
16+
args = [
17+
# use half precision for speed and memory savings in CI environment
18+
"--dtype",
19+
"bfloat16",
20+
"--max-model-len",
21+
"8192",
22+
"--enforce-eager",
23+
"--max-num-seqs",
24+
"128",
25+
]
26+
27+
with RemoteOpenAIServer(MODEL_NAME, args) as remote_server:
28+
yield remote_server
29+
30+
31+
@pytest.fixture(scope="module")
32+
def client(server):
33+
return server.get_async_client()
34+
35+
36+
@pytest.mark.asyncio
37+
async def test_show_version(client: openai.AsyncOpenAI):
38+
base_url = str(client.base_url)[:-3].strip("/")
39+
40+
response = requests.get(base_url + "/version")
41+
response.raise_for_status()
42+
43+
assert response.json() == {"version": VLLM_VERSION}
44+
45+
46+
@pytest.mark.asyncio
47+
async def test_check_health(client: openai.AsyncOpenAI):
48+
base_url = str(client.base_url)[:-3].strip("/")
49+
50+
response = requests.get(base_url + "/health")
51+
52+
assert response.status_code == HTTPStatus.OK
53+
54+
55+
@pytest.mark.asyncio
56+
async def test_log_metrics(client: openai.AsyncOpenAI):
57+
base_url = str(client.base_url)[:-3].strip("/")
58+
59+
response = requests.get(base_url + "/metrics")
60+
61+
assert response.status_code == HTTPStatus.OK

vllm/entrypoints/openai/api_server.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ async def _force_log():
7373

7474
router = APIRouter()
7575

76-
# Add prometheus asgi middleware to route /metrics requests
77-
route = Mount("/metrics", make_asgi_app())
78-
# Workaround for 307 Redirect for /metrics
79-
route.path_regex = re.compile('^/metrics(?P<path>.*)$')
80-
router.routes.append(route)
76+
77+
def mount_metrics(app: fastapi.FastAPI):
78+
# Add prometheus asgi middleware to route /metrics requests
79+
metrics_route = Mount("/metrics", make_asgi_app())
80+
# Workaround for 307 Redirect for /metrics
81+
metrics_route.path_regex = re.compile('^/metrics(?P<path>.*)$')
82+
app.routes.append(metrics_route)
8183

8284

8385
@router.get("/health")
@@ -167,6 +169,8 @@ def build_app(args):
167169
app.include_router(router)
168170
app.root_path = args.root_path
169171

172+
mount_metrics(app)
173+
170174
app.add_middleware(
171175
CORSMiddleware,
172176
allow_origins=args.allowed_origins,

0 commit comments

Comments
 (0)