-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Timed annotation not working properly for reactive methods / futures #15601
Comments
Can you confirm which version of Quarkus you're using, and which extensions you have enabled? |
@ebullient I'm using 1.10.5.FINAL and I tried it in 1.11.2.FINAL if I remember correctly. I was using fault-tolerance extension along with Kafka, postgres-reactive and flyway. |
And which metrics extension? A reproducer would also help a lot, if that isn't asking too much |
Is this still an issue? |
Yes. |
I can confirm this is still an issue with 2.6, I have a reproducer if that helps, what's the best way to send it to you? Just zip and upload here? |
Sure, that works. |
Here it goes: It is a reactive kafka consumer that forces a random timeout, however, the metrics look wrong to me:
Let me know if that helps or you need anything, I'll try to be faster this time 🤦 |
Thanks for this info. |
I'm not sure of the right answer here, @geoand .. this is pretty standard fare for reactive methods: a @timed annotation can't really work there (as it can't follow the reactive chain properly.. there are too many variants). The @timed annotation can hitch itself to a completable future, but the last time @cescoffier and I talked about this, the more it seemed like metrics would need to be added explicitly, e.g. using logging: https://smallrye.io/smallrye-mutiny/guides/logging or by observing events: https://smallrye.io/smallrye-mutiny/getting-started/observing-events |
Although I am the original issue opener, I admit one could argue that the Timed annotation behaves as intended with its current behavior (after all it is measuring what the method takes to execute). So, an option could be just closing this issue, or adding a note in the documentation indicating this behavior and an example, as it can come a bit surprising. That being said, I had a look at the code and it seems the magic happens at io.quarkus.micrometer.runtime.binder.mpmetrics.TimedInterceptor which knows nothing about distinct return types (not only reactive code bug also futures). One option could be make it smart about it and use https://smallrye.io/smallrye-mutiny/getting-started/observing-events#the-invoke-method as suggested for reactive and equivalent code for futures, but that would require inspecting the class of the result, which is "clean" for futures but given quarkus' metrics module knows nothing about mutiny it would some ugly class existence checks or entangling dependencies. So TL;DR, it might be enough with enhancing the docs and closing the issue. |
So yeah, annotations like |
right. doable with a uni perhaps... |
Hay, last week we shifted one of our production services from spring webflux to quarkus and we encountered this exact issue which took us by surprise since the FaultTolerance annotations do handle reactive operations nicely. We assumed the Metrics annotation will behave the same. |
Yup, just like If I have time, I'll check it out. |
#22639 should take care of it |
Introduce support for Uni return types in Micrometer annotations
/cc @ebullient, @jmartisk |
Thanks a bunch! |
You are very welcome! |
Describe the bug
If you use the Timed annotation on a reactive method, it measures literally the time spent on the method, not the actual execution of the reactive action returned. Same happens with futures.
Expected behavior
Either it works or it should be validated so people doesn't get confusing results.
Actual behavior
It calculates the time creating the Uni/Multi/Future, but not the actual execution of the task itself.
To Reproduce
Create a method returning a Uni and annotate it with Timed, when you check the metrics, it does not match the reality.
Configuration
N/A
Screenshots
N/A
Environment (please complete the following information):
uname -a
orver
:java -version
:mvnw --version
orgradlew --version
): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)Additional context
N/A
The text was updated successfully, but these errors were encountered: