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

feat: add prometheus metrics to /metrics #466

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointing out that /metrics calls are not being logged already:

# Filter out /metrics noise
class MetricsCheckFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
return record.getMessage().find("/metrics") == -1


# 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