Skip to content
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

Http server metrics counts twice for Jersey endpoints #29303

Closed
Declow0 opened this issue Jan 10, 2022 · 11 comments
Closed

Http server metrics counts twice for Jersey endpoints #29303

Declow0 opened this issue Jan 10, 2022 · 11 comments
Labels
status: superseded An issue that has been superseded by another

Comments

@Declow0
Copy link

Declow0 commented Jan 10, 2022

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)

jersey-metrics

Simple project for problem demonstration https://github.com/Declow0/jersey-metrics

Can WebMvcMetricsFilter ignore request for counting if Jersey implemetation was already counted?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 10, 2022
@philwebb
Copy link
Member

Here's a Java version of the sample: https://github.com/philwebb/scratch-gh-29303

@philwebb
Copy link
Member

@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?

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label Jan 10, 2022
@Declow0
Copy link
Author

Declow0 commented Jan 10, 2022

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

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 10, 2022
@philwebb
Copy link
Member

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.

@philwebb philwebb added the for: team-meeting An issue we'd like to discuss as a team to make progress label Jan 10, 2022
@philwebb
Copy link
Member

See also #13064

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided for: team-meeting An issue we'd like to discuss as a team to make progress labels Jan 12, 2022
@philwebb philwebb added this to the 2.5.x milestone Jan 12, 2022
@philwebb
Copy link
Member

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.

@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona modified the milestones: 2.5.x, 2.6.x May 19, 2022
@wilkinsona wilkinsona modified the milestones: 2.6.x, 2.7.x Nov 24, 2022
@philwebb philwebb modified the milestones: 2.7.x, 3.1.x Nov 8, 2023
@anand188
Copy link

anand188 commented Apr 9, 2024

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?

@bclozel
Copy link
Member

bclozel commented Apr 15, 2024

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 #39294 (comment)

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
@bclozel bclozel added status: superseded An issue that has been superseded by another and removed type: bug A general bug labels Apr 15, 2024
@bclozel bclozel removed this from the 3.1.x milestone Apr 15, 2024
@cyril-telr
Copy link

hi i have exactly same issue but for all count not only http, but database call, webclient calls etc all are counted twice

@wilkinsona
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

7 participants