spring-boot
                                
                                 spring-boot copied to clipboard
                                
                                    spring-boot copied to clipboard
                            
                            
                            
                        Http server metrics counts twice for Jersey endpoints
After upgrading to Spring Boot 2.6 with Micrometer 1.8.1 metric "http_server_requests_seconds_count" counts twice every jersey call with different uri tag:
correct uri by org.springframework.boot.actuate.autoconfigure.metrics.jersey.JerseyServerMetricsAutoConfiguration
UNKNOWN by org.springframework.boot.actuate.autoconfigure.metrics.web.servlet.WebMvcMetricsAutoConfiguration
in that order (by filter priority)
Simple project for problem demonstration https://github.com/Declow0/jersey-metrics
Can WebMvcMetricsFilter ignore request for counting if Jersey implemetation was already counted?
Here's a Java version of the sample: https://github.com/philwebb/scratch-gh-29303
@Declow0 What version are you upgrading from? I tried 2.5 and I think I get the same result. Do you need to mix Spring MVC and Jersey in your application?
I upgraded from 2.3 to 2.6. Yes, I mix REST Controllers and Jersey endpoints (from Camunda project). At 2.3 I don't have Jersey metrics autoconfiguration and all Jersey call has uri tag = UNKNOWN
I'd like to discuss this one with the rest of the team to see if they have any ideas. I wonder if we might be able to tighten WebMvcMetricsFilter and only apply it if the request has been handled by a DispatcherServlet. Perhaps we can check for a DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE in the request.
See also #13064
We're going to look at adding a property that will allow WebMvcMetricsFilter to check if the request is from a DispatcherServlet. Since existing users might be relying on the existing behavior, we won't flip the default until Spring Boot 2.7.
We should also check what happens if Jersey's configured as a filter and with FILTER_FORWARD_ON_404. There's a chance that this will result in duplicate metrics as the request will have passed through Jersey and MVC's DispatcherServlet.
I upgraded from 2.3 to 2.6. Yes, I mix REST Controllers and Jersey endpoints (from Camunda project). At 2.3 I don't have Jersey metrics autoconfiguration and all Jersey call has uri tag =
UNKNOWN
Also facing same problem URI tag remain either UNKNOWN or /** instead actual endpoint urls? Any idea what might be wrong?
In the meantime, the observability support has been rewritten entirely and Jersey/MVC instrumentations are independent. Jersey apps should not depend on the web starter and as a result, the web layer will not be instrumented twice. Closing with https://github.com/spring-projects/spring-boot/issues/39294#issuecomment-1948529675
hi i have exactly same issue but for all count not only http, but database call, webclient calls etc all are counted twice
@cyril-telr in that case, it's not exactly the same issue. The problem that was tracked by this issue was specific to Jersey and how the web stack was instrumented. If you would like us to spend some time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can then share it with us by opening a new issue and pushing it to a separate repository on GitHub or by zipping it up and attaching it to the new issue.