Skip to content

Commit

Permalink
feat: add prometheus metrics to /metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
tgalske committed Oct 14, 2024
1 parent d42a6cf commit b43fef0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.82

* Expose Prometheus metrics at /metrics

## 0.0.81

* Update `strategy` parameter to allow `'` and `"` as input surrounding the value.
Expand Down
6 changes: 5 additions & 1 deletion prepline_general/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from fastapi.datastructures import FormData
from fastapi.responses import JSONResponse
from fastapi.security import APIKeyHeader
from prometheus_client import make_asgi_app
import logging
import os

Expand All @@ -13,7 +14,7 @@
app = FastAPI(
title="Unstructured Pipeline API",
summary="Partition documents with the Unstructured library",
version="0.0.81",
version="0.0.82",
docs_url="/general/docs",
openapi_url="/general/openapi.json",
servers=[
Expand All @@ -31,6 +32,9 @@
openapi_tags=[{"name": "general"}],
)

metrics_app = make_asgi_app()
app.mount("/metrics", metrics_app)

# Note(austin) - This logger just dumps exceptions
# We'd rather handle those below, so disable this in deployments
uvicorn_logger = logging.getLogger("uvicorn.error")
Expand Down
4 changes: 2 additions & 2 deletions prepline_general/api/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def return_content_type(filename: str):


@router.get("/general/v0/general", include_in_schema=False)
@router.get("/general/v0.0.81/general", include_in_schema=False)
@router.get("/general/v0.0.82/general", include_in_schema=False)
async def handle_invalid_get_request():
raise HTTPException(
status_code=status.HTTP_405_METHOD_NOT_ALLOWED, detail="Only POST requests are supported."
Expand All @@ -668,7 +668,7 @@ async def handle_invalid_get_request():
description="Description",
operation_id="partition_parameters",
)
@router.post("/general/v0.0.81/general", include_in_schema=False)
@router.post("/general/v0.0.82/general", include_in_schema=False)
def general_partition(
request: Request,
# cannot use annotated type here because of a bug described here:
Expand Down
2 changes: 1 addition & 1 deletion preprocessing-pipeline-family.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name: general
version: 0.0.81
version: 0.0.82
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ backoff
pypdf
pycryptodome
psutil
prometheus_client
2 changes: 2 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ pillow==10.4.0
# unstructured-pytesseract
portalocker==2.10.1
# via iopath
prometheus-client==0.21.0
# via -r requirements/base.in
proto-plus==1.24.0
# via
# google-api-core
Expand Down

0 comments on commit b43fef0

Please sign in to comment.