Closed treebee closed 7 years ago
Maybe @MathMagique has a clever idea how to test this w/o the exception? Therefore I added him to the reviewers
As an idea: If we hold a reference to the collector, we could modify the instance at runtime on each call of /metrics
and set the timeout. This way the collector doesn't need to interfere with flask at all.
I also thought about that. This solution would require to provide a custom /metrics
endpoint plus I have no idea what would happen should concurrent requests ever come in. Probably not much due to the global interpreter lock and how Python handles parallelism, but still it feels awkward. The real solution would be to get this is a first-class feature into Prometheus Python client.
metrics
is custom already. We would just shift the header parsing code there. The concurrency is indeed not trivial, because it might depend on the wsgi http server which concurrency model is used.
Ahh, good old days when I constructed the metrics output manually.
Looks good to me as well. I like the local registry approach you have taken that basically solves any concurrency problems that may have appeared with the global registry. Also, I like that the collector does not know it is supposed to run in a request context. Good job!
This implements #7
Not really happy with the test and that we have to catch this
RuntimeError
only for the unit test case, but I don't see a way to pull the value of the request header into the collector besides using flask's request object.