Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimal fastapi prom metrics #1426

Merged
merged 6 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from oasst_shared.exceptions import OasstError, OasstErrorCode
from oasst_shared.schemas import protocol as protocol_schema
from oasst_shared.utils import utcnow
from prometheus_fastapi_instrumentator import Instrumentator
from pydantic import BaseModel
from sqlmodel import Session, select
from starlette.middleware.cors import CORSMiddleware
Expand Down Expand Up @@ -100,6 +101,13 @@ def create_official_web_api_client():
)


if settings.ENABLE_PROM_METRICS:

@app.on_event("startup")
async def enable_prom_metrics():
Instrumentator().instrument(app).expose(app)


if settings.RATE_LIMIT:

@app.on_event("startup")
Expand Down
2 changes: 2 additions & 0 deletions backend/oasst_backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ class Settings(BaseSettings):

ROOT_TOKENS: List[str] = ["1234"] # supply a string that can be parsed to a json list

ENABLE_PROM_METRICS: bool = True # enable prometheus metrics at /metrics

@validator("DATABASE_URI", pre=True)
def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
if isinstance(v, str):
Expand Down
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ fastapi-limiter==0.1.5
fastapi-utils==0.2.1
loguru==0.6.0
numpy==1.22.4
prometheus-fastapi-instrumentator==5.9.1
psycopg2-binary==2.9.5
pydantic==1.9.1
pydantic[email]==1.9.1
Expand Down
8 changes: 8 additions & 0 deletions inference/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@
from fastapi.middleware.cors import CORSMiddleware
from loguru import logger
from oasst_shared.schemas import inference, protocol
from prometheus_fastapi_instrumentator import Instrumentator
from sse_starlette.sse import EventSourceResponse

app = fastapi.FastAPI()


# add prometheus metrics at /metrics
@app.on_event("startup")
async def enable_prom_metrics():
Instrumentator().instrument(app).expose(app)


# Allow CORS
app.add_middleware(
CORSMiddleware,
Expand Down
1 change: 1 addition & 0 deletions inference/server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fastapi[all]
loguru
prometheus-fastapi-instrumentator==5.9.1
pydantic
redis
sse-starlette
Expand Down