claws / aioprometheus

A Prometheus Python client library for asyncio-based applications
176 stars 21 forks source link

Metrics exposure is blocking #98

Open stephanecollot opened 9 months ago

stephanecollot commented 9 months ago

Hello,

I'm using aioprometheus in my FastAPI like this:

@app.get("/metrics")
async def handle_metrics(
    accept: List[str] = Header(None),
) -> Response:
    content, http_headers = render(REGISTRY, accept)
    return Response(content=content, media_type=http_headers["Content-Type"])

And I notice that when querying /metrics my application freeze for few seconds. Is this normal? I'm looking at the code of render() and it seems not async.

Do you plan to make it async? If not what solution do you suggest?

Thank you in advance

stephanecollot commented 9 months ago

Looking at the official client, it seems that they added async ASGI metric exposure. But I don't know if their metrics update will then be blocking. https://github.com/prometheus/client_python/pull/512