You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: The view function did not return a valid response. The `return` type must be a string, dict, list, tuple with headers or status, Response instance, or WSGI callable, but it was a coroutine.
Internally decoration logic is implemented in _track, and the following simple patching resolves the error with coroutine handling,
def_track(self, metric_type, metric_call, metric_kwargs, name, description, labels,
initial_value_when_only_static_labels, registry, before=None, revert_when_not_tracked=None):
...
defdecorator(f):
@wraps(f)asyncdeffunc(*args, **kwargs):
...
try:
# execute the handler functionresponse=awaitf(*args, **kwargs)
exceptExceptionasex:
# let Flask decide to wrap or reraise the Exceptionresponse=current_app.handle_user_exception(ex)
....
after patching for the above example app both /health and /metrics respond correctly, metrics aggregated
So Its working, but I wonder if this can lead to unexpected increase of latency or any other drawbacks? Maybe there is another way to connect prometheus_flask_exporter to ASGI server? Any other advices are also appreciated!
Thanks!
The text was updated successfully, but these errors were encountered:
I'm not too familiar with ASGI and Uvicorn, I wonder if we're just missing support for the coroutine responses that we could add?
Is that what you patch does basically?
I wonder if we're just missing support for the coroutine responses that we could add? ... Is that what you patch does basically?
Yes, patching the code this way makes the coroutine response handling correct, though it seems like a surprisingly simple patch, so I'm not fully confident it addresses all edge cases.
I'm thinking perhaps we should subclass GunicornInternalPrometheusMetrics (or another appropriate class) that adds Uvicorn support, and then that can have this complication. What do you think?
Hello @rycus86 !
I'm trying to connect
prometheus_flask_exporter
to the following ASGI Flask app,it started normally with,
mkdir -p prometheus PROMETHEUS_MULTIPROC_DIR=prometheus gunicorn app:asgi_app -b 0.0.0.0:8000 --workers 2 -k 'uvicorn.workers.UvicornWorker'
but when requested with,
it gives the error,
Internally decoration logic is implemented in _track, and the following simple patching resolves the error with coroutine handling,
after patching for the above example app both
/health
and/metrics
respond correctly, metrics aggregatedSo Its working, but I wonder if this can lead to unexpected increase of latency or any other drawbacks? Maybe there is another way to connect
prometheus_flask_exporter
to ASGI server? Any other advices are also appreciated!Thanks!
The text was updated successfully, but these errors were encountered: