Skip to content

Commit

Permalink
Fix /metrics 404 error
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkLight1337 committed Jul 16, 2024
1 parent 4defc08 commit fc19360
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 1 addition & 2 deletions tests/entrypoints/openai/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 9 additions & 5 deletions vllm/entrypoints/openai/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<path>.*)$')
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<path>.*)$')
app.routes.append(metrics_route)


@router.get("/health")
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fc19360

Please sign in to comment.