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

Weird response getting in Spring boot when using @Timed #2930

Closed
nithu1991 opened this issue Dec 22, 2021 · 7 comments
Closed

Weird response getting in Spring boot when using @Timed #2930

nithu1991 opened this issue Dec 22, 2021 · 7 comments
Labels
doc-update A documentation update module: micrometer-core An issue that is related to our core module

Comments

@nithu1991
Copy link

When using @timed annotation in the controller in the response gets some weird return. And this function will call external calls ( using resttemplate).

Response getting -
{ "message": "okay" }{ "timestamp": "2021-12-22T11:43:40.386+00:00", "status": 200, "error": "OK", "message": "", "path": "/api/v1/request" }

Removing value from @timed annotation will fix this issue or removing the below Beans also fix the issue.
@Bean public TimedAspect timedAspect(MeterRegistry registry) { return new TimedAspect(registry); }

The exception getting is --
java.lang.IllegalArgumentException: Collector already registered that provides name: requestInsurekaRepresentative_driskaa_seconds_count at io.prometheus.client.CollectorRegistry.register(CollectorRegistry.java:54) at io.prometheus.client.Collector.register(Collector.java:139) at io.micrometer.prometheus.PrometheusMeterRegistry.lambda$applyToCollector$16(PrometheusMeterRegistry.java:410) at java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1853) at io.micrometer.prometheus.PrometheusMeterRegistry.applyToCollector(PrometheusMeterRegistry.java:406) at io.micrometer.prometheus.PrometheusMeterRegistry.newTimer(PrometheusMeterRegistry.java:200) at io.micrometer.core.instrument.MeterRegistry.lambda$timer$2(MeterRegistry.java:310) at io.micrometer.core.instrument.MeterRegistry.getOrCreateMeter(MeterRegistry.java:614) at io.micrometer.core.instrument.MeterRegistry.registerMeterIfNecessary(MeterRegistry.java:568) at io.micrometer.core.instrument.MeterRegistry.timer(MeterRegistry.java:308) at io.micrometer.core.instrument.Timer$Builder.register(Timer.java:401) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.getTimer(WebMvcMetricsFilter.java:169) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.record(WebMvcMetricsFilter.java:135) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:109) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.keycloak.adapters.tomcat.AbstractAuthenticatedActionsValve.invoke(AbstractAuthenticatedActionsValve.java:67) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:181) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

@nithu1991 nithu1991 added the bug A general bug label Dec 22, 2021
@jonatan-ivanov
Copy link
Member

Could you please check this issue, it seems to be related: #2399?
Also, could you please try and update Spring Boot (and Micrometer)?

If updating them does not help, could you please provide a minimal sample project to reproduce this issue so we can more easily investigate and ensure any fix is working properly for your use case?

@jonatan-ivanov jonatan-ivanov added the waiting for feedback We need additional information before we can continue label Jan 5, 2022
@nithu1991
Copy link
Author

nithu1991 commented Jan 6, 2022 via email

@shakuzen
Copy link
Member

shakuzen commented Jan 6, 2022

Can you make and share a minimal sample project that reproduces the behavior? It will help us figure out what's happening.

@nithu1991
Copy link
Author

nithu1991 commented Jan 6, 2022 via email

@shakuzen
Copy link
Member

shakuzen commented Jan 6, 2022

Alright, well, I've now taken the time to create such a sample application at https://github.com/shakuzen/gh-2930 and I don't see the behavior you've described. I start the application, I make a request to /hello, and I make a request to /actuator/prometheus. No problems, no errors.

You shouldn't be making a TimedAspect bean to use @Timed on controller methods. Spring Boot supports that without the need for the aspect. See this Spring Boot documentation.

@shakuzen shakuzen closed this as completed Jan 6, 2022
@shakuzen shakuzen added doc-update A documentation update module: micrometer-core An issue that is related to our core module and removed bug A general bug waiting for feedback We need additional information before we can continue labels Jan 6, 2022
@shakuzen
Copy link
Member

shakuzen commented Jan 6, 2022

I've opened #4621 to improve our documentation around this issue as it has come up before.

@nithu1991
Copy link
Author

nithu1991 commented Jan 6, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-update A documentation update module: micrometer-core An issue that is related to our core module
Projects
None yet
Development

No branches or pull requests

3 participants