Skip to content

Commit 8c3a953

Browse files
rkuo-danswerRichard Kuo (Onyx)
and
Richard Kuo (Onyx)
authored
add prometheus metrics endpoints via helper package (#4436)
* add prometheus metrics endpoints via helper package * model server specific requirements * mark as public endpoint --------- Co-authored-by: Richard Kuo (Onyx) <[email protected]>
1 parent 54b883d commit 8c3a953

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

backend/model_server/main.py

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import torch
1010
import uvicorn
1111
from fastapi import FastAPI
12+
from prometheus_fastapi_instrumentator import Instrumentator
1213
from sentry_sdk.integrations.fastapi import FastApiIntegration
1314
from sentry_sdk.integrations.starlette import StarletteIntegration
1415
from transformers import logging as transformer_logging # type:ignore
@@ -127,6 +128,9 @@ def get_model_app() -> FastAPI:
127128

128129
add_onyx_request_id_middleware(application, request_id_prefix, logger)
129130

131+
# Initialize and instrument the app
132+
Instrumentator().instrument(application).expose(application)
133+
130134
return application
131135

132136

backend/onyx/main.py

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from fastapi.middleware.cors import CORSMiddleware
1818
from fastapi.responses import JSONResponse
1919
from httpx_oauth.clients.google import GoogleOAuth2
20+
from prometheus_fastapi_instrumentator import Instrumentator
2021
from sentry_sdk.integrations.fastapi import FastApiIntegration
2122
from sentry_sdk.integrations.starlette import StarletteIntegration
2223
from sqlalchemy.orm import Session
@@ -435,6 +436,9 @@ def get_application() -> FastAPI:
435436
# Ensure all routes have auth enabled or are explicitly marked as public
436437
check_router_auth(application)
437438

439+
# Initialize and instrument the app
440+
Instrumentator().instrument(application).expose(application)
441+
438442
return application
439443

440444

backend/onyx/server/auth_check.py

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
("/auth/oauth/callback", {"GET"}),
5050
# anonymous user on cloud
5151
("/tenants/anonymous-user", {"POST"}),
52+
("/metrics", {"GET"}), # added by prometheus_fastapi_instrumentator
5253
]
5354

5455

backend/requirements/default.txt

+1
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@ mistune==0.8.4
9696
sentry-sdk==2.14.0
9797
prometheus_client==0.21.0
9898
fastapi-limiter==0.1.6
99+
prometheus_fastapi_instrumentator==7.1.0

backend/requirements/model_server.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ uvicorn==0.21.1
1515
voyageai==0.2.3
1616
litellm==1.61.16
1717
sentry-sdk[fastapi,celery,starlette]==2.14.0
18-
aioboto3==13.4.0
18+
aioboto3==13.4.0
19+
prometheus_fastapi_instrumentator==7.1.0

0 commit comments

Comments
 (0)