-
Notifications
You must be signed in to change notification settings - Fork 801
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
ASGI mounted to FastAPI mounts metrics to /metrics/
instead of /metrics
#1016
Comments
prometheus_client
mounts metrics to /metrics/
instead of /metrics
/metrics/
instead of /metrics
@kakkoyun this might be something to look at to learn more about the project as well. |
Thanks for pointing this out @hmellor. I was am doing something similar but got an "Method Not Allowed" when doing a GET request for http://localhost:8000/metrics. I am using hypercorn but I do not get the redirect.
|
I think I found the root cause.
And from FastApi and Starlette docs you can read that sub-applications are mounted under a prefix, in this case "/metrics". So when you want to actually access this sub-application I guess a new root endpoint is automatically added thus creating "/metrics/". Here you can find the docs: |
In from aioprometheus.asgi.starlette import metrics
app.add_route("/metrics", metrics) |
Yes, that is exactly the cause. In this client the make_asgi_app() creates a sub-application that is mounted with app.mount() thus creating a "/metrics" prefix vs an actual route. |
This workaround appears to work (changes import re
from starlette.routing import Mount
...
# Add prometheus asgi middleware to route /metrics requests
route = Mount("/metrics", make_asgi_app())
route.path_regex = re.compile('^/metrics(?P<path>.*)$')
app.routes.append(route) |
The documentation gives an example application which mounts the ASGI app to
/metrics
in a FastAPI appand says that you should be able to see the metrics at http://localhost:8000/metrics, however if you try to access this endpoint
you get redirected to
/metrics/
.It would be better if this redirect could be avoided.
The text was updated successfully, but these errors were encountered: