-
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
Added ASGI application #512
Conversation
59bfb87
to
331199e
Compare
Signed-off-by: Emil Madsen <sovende@gmail.com>
I'd prefer not to have to maintain yet another copy of the exposition http handling for a subtly difference interface. Is there not some interface all of these can share? |
I understand your hesitance to adapt yet another interface. The README file is already quite crowded. As for whether there is a common interface all of these can share, I wanna say yes, there is the PEP-3333 standard WSGI and it's spiritual successor ASGI.
My last though is that WSGI and ASGI should not be considered equal to the frameworks. As they are gateway interfaces and thus more general than specific frameworks. |
Note: I have closed the PR for the Quart extension of the README file, I included it solely for completeness to have a flask-equivalent ASGI framework example. |
It doesn't matter to me why this exists, it matters that we're already duplicating this code 3 times for various things that were popular at various times. |
How would you feel about cleaning up, by deprecating the twisted code, removing the flask and python http documentation and going solely with the code+examples for the gateway interfaces? The gateway interfaces produces production quality endpoints in standard defined ways, and the integrations are simple in most languages, either via routers, middleware or adapters. For Flask/Django it's common practice to utilize WSGI middlewares, for Quart/Django it's common practice to utliize ASGI middleware. Twisted has a WSGIResource which can call any WSGI app, thus I don't see the need for the MetricsResource for twisted. |
Signed-off-by: Emil Madsen <sovende@gmail.com>
Is it possible to get twisted to use one of the *sgi apis? That way it could be replaced by docs. |
Yea, that is very much possible. To use the The example in the README becomes:
Using WSGI, and:
Using ASGI and Either way all the framework specific code for twisted can be deprecated/removed. Potentially an alias can be setup, such as:
To maintain backwards compatability. |
If we can do that then and avoid duplicating the parameter handing code, that sounds good. |
I will do it when I can get around to it. How do you feel about the MetricsHandler, and start_http_server + _ThreadingSimpleServer? We could eliminate |
MetricsHandler is used by users, so it should continue to work. I'm okay with switching around how start_http_server works as long as it can still handle concurrent scrapes. |
Signed-off-by: Emil Madsen <sovende@gmail.com>
3f4851f
to
4aa2cf7
Compare
Signed-off-by: Emil Madsen <sovende@gmail.com>
Signed-off-by: Emil Madsen <sovende@gmail.com>
Signed-off-by: Emil Madsen <sovende@gmail.com>
What do you think about this? |
Signed-off-by: Emil Madsen <sovende@gmail.com>
Signed-off-by: Emil Madsen <sovende@gmail.com>
Signed-off-by: Emil Madsen <sovende@gmail.com>
Signed-off-by: Emil Madsen <sovende@gmail.com>
Thanks! |
@Skeen Thanks for this! It works really well, and I was able to add it to a FastAPI app like this:
@brian-brazil Can you please consider releasing a new version to PyPI? Thanks! |
Hi! ASGI is really cool feature. Especially for fastapi app (see comment above). When are you going to release asgi version to PyPI? |
I can't wait to use Prometheus in fastapi. But I noticed that prometheus_client has not released a new version. So I chose to starlette_exporter. At least for now, there are no functional issues. You can try it, too. |
@brian-brazil Thank you for the release! 🎉 |
could you please remain me that, how can i add a count metrics in the asgi mode? Thanks alot |
The same way you'd do it for non-asgi:
|
Thanks a lot! |
Hi @aLowMagic I don't think this PR is the right place to ask for help like this, or to have these discussions, as it's unrelated to ASGI itself. I would suggest you have a look at: https://prometheus.io/community/ - And seek help there :) |
Thanks a lot~ |
This PR introduces an ASGI counterpart to the current WSGI app.
The ASGI code itself is moved into a seperate module
asgi.py
, which is conditionally included as it is only valid in Python 3 (due to async/await calls).