Implement filtering of async requests.#689
Implement filtering of async requests.#689lapo-luchini wants to merge 1 commit intoprometheus:mainfrom
Conversation
Signed-off-by: Lapo Luchini <lapo@lapo.it>
fstab
left a comment
There was a problem hiding this comment.
This is a nice one, thanks a lot!
Unfortunately, I have moved the Servlet filter implementation in the meantime, all common functionality is now in io.prometheus.client.servlet.common.filter.Filter, and there are two implementations using it: One for javax Servlets, and one for jakarta Servlets.
It will require a bit of boiler-plate code to port your solution to the current implementation, but I think it's worthwhile doing it. Basically you would need a common implementation of the AsyncListener in simpleclient_servlet_common, and an implementation of jakarta.servlet.AsyncListener and javax.servlet.AsyncListener in simpleclient_servlet and simpleclient_servlet_jakarta. This is similar to what I did with MetricsServlet and MetricsFilter.
Could you port your solution to the current master branch? I would really appreciate that.
| if (!done) { | ||
| done = true; |
There was a problem hiding this comment.
This isn't thread safe, because there's a check-then-act race condition. I don't think thread safety is needed here, because my understanding is that meter() will only be called once. If it's only called once, please remove done. If there are cases where it is called multiple times in different threads, fix the race condition.
There was a problem hiding this comment.
Makes sense… I can't find anything definitive on the 3.0 specs that only one of the three methods will ever be called, so I'll rather err on the safe side by fixing the race.
This fixes #676 for me… but there are no tests as I have no idea how to properly test an async servlet responses with Mockito.
Doesn't break any of the existing tests, though: