Bug description
I'm upgrading a fairly old application running on Spring Boot 2.7 to 3.4.2 and I'm running into an issue where rest controllers with multiple @Timed
annotations on the class are not being processed properly and metrics are missing. My application have controllers like this :
@Timed("test.two.timed.first")
@Timed("test.two.timed.second", histogram = true)
@RestController
public class TwoTimedController {
@RequestMapping("/two")
public String getTwo() {
return "Two";
}
}
where 2 @Timed
annotations are present to gather 2 different metrics. Since the update to Spring Boot 3.x, the metrics are not being reported anymore. If the controller have only 1 @Timed
annotation it works properly. I'm basing this observation on the /actuator/metrics
showing the metric being reported or not.
Reproduction repo
You'll find a reproduction example here : https://github.com/jebeaudet/spring-aop-issue
You only have to run the test in com.jebeaudet.demo.DemoApplicationTests
to see the results. Modify the pom.xml
spring-boot-starter-parent
version to see it working on 2.7.15
and not on 3.4.2
or 3.0.13
.
In my debugging attempts, I initially thought that a change in micrometer was responsible for it so I tried downgrading the dependency to 1.9.15
(managed version from Spring Boot 2.7.15
) but ran into some class not found exceptions so I copied the TimedAspect
implementation in the project and instantiated it myself. Given that the error is still there with the old TimedAspect
and the new Spring Boot version made me log an issue here. To test without this, simply set the micrometer.observations.annotations.enabled
to true in the application.properties
and the custom bean will back off.
Happy to provide any kind of missing information or precision.
Thanks!
Comment From: wilkinsona
Thanks for the sample. The reason for the difference in behavior is that the aspect isn't used in Spring Boot 2.7. Instead, it's WebMvcMetricsFilter
that finds the @Timed
annotations and generates metrics from them.
As far as I can tell, the problem in Spring Boot 3.x is a limitation of TimedAspect
. It doesn't have a pointcut that handles @TimedSet
. This means that it misses methods or classes annotated with multiple @Timed
annotations. This has been raised previously in https://github.com/micrometer-metrics/micrometer/issues/1032.
Comment From: jebeaudet
I completely missed that very important detail in 2.7 implementation and wrongly assumed TimedAspect
was used and that it was an issue within spring-aop.
Thanks a lot for providing the additional details, I really appreciate you taking the time to do so, sorry for the back and forth between spring-framework and spring boot. I'll reach out to the micrometer team for the rest.