Skip to content

MeterRegistry not configured with Advisor bean that depends on it #19148

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

Closed
biergit opened this issue Nov 26, 2019 · 4 comments
Closed

MeterRegistry not configured with Advisor bean that depends on it #19148

biergit opened this issue Nov 26, 2019 · 4 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@biergit
Copy link
Contributor

biergit commented Nov 26, 2019

Spring Boot 2.2.1.RELEASE

We use a Spring AOP Advisor bean inside a library to publish execution times of certain methods. This used to work fine with Spring Boot 1.4.2. Debugging showed that the Advisor bean (and with it the MeterRegistry ) is created before the MeterRegistryPostProcessor so that the MeterRegistry is not configured.

Sample project: https://github.com/biergit/playground

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 26, 2019
@wilkinsona
Copy link
Member

Thanks for the sample. There are a number of info messages logged which show that there's a problem with the dependency relationships between the beans in your app:

2019-11-26 19:49:45.834  INFO 28828 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'playgroundApplication' of type [com.example.playground.PlaygroundApplication$$EnhancerBySpringCGLIB$$6f378901] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-26 19:49:45.837  INFO 28828 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-26 19:49:45.848  INFO 28828 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'management.metrics.export.simple-org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleProperties' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-26 19:49:45.851  INFO 28828 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'simpleConfig' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimplePropertiesConfigAdapter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-26 19:49:45.853  INFO 28828 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration' of type [org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-26 19:49:45.855  INFO 28828 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'micrometerClock' of type [io.micrometer.core.instrument.Clock$1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-26 19:49:45.865  INFO 28828 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'simpleMeterRegistry' of type [io.micrometer.core.instrument.simple.SimpleMeterRegistry] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-26 19:49:45.878  INFO 28828 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'someAdvisor' of type [org.springframework.aop.support.DefaultPointcutAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

This is happening because you have injected MeterRegistry into an Advisor. Spring Framework applies advice via a bean post-processor. This bean post-processor depends upon any Advisor beans. Your custom Advistor depends on the MeterRegistry which causes it to be instantiated when bean post-processor are being created. This is very early in the application context's lifecycle and prevents it from being post-processed.

You can avoid the problem by making the injected MeterRegistry lazy by annotating its injection point with @Lazy:

@Bean
public Advisor someAdvisor(@Lazy MeterRegistry meterRegistry) {
    //…
}

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 26, 2019
@biergit
Copy link
Contributor Author

biergit commented Nov 27, 2019

Thanks for looking into it. Should this be documented somewhere?
I was also surprised to see that jvm metrics were not configured in my case but e.g. tomcat metrics on the other hand were available since they are registered by other means than bean post processing.

@wilkinsona
Copy link
Member

The problem is broader than Spring Boot and its auto-configuration of MeterRegistry. It applies to dependency injection into anything that's a dependency of a bean post-processor. As such, if it's to be documented anywhere, I think it should be in Spring Framework's reference documentation. That would hopefully help to guide people who've noticed the info log messages about a bean not being eligible for bean post-processing.

There's a large section about AOP with a sub-section dedicated to understanding AOP's use of proxies. It's the use of proxies for AOP and a bean post-processor to create them that means that care must be taken when injecting dependencies into a bean that's an aspect or advisor. An update to this section of the documentation may make sense.

I've opened spring-projects/spring-framework#24092.

@biergit
Copy link
Contributor Author

biergit commented Nov 27, 2019

Awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants