Description
Including spring-boot-starter-data-jpa to the classpath results in a lot of missing metrics for the application.
Guess: Looks like part of my configuration isn't applied - see e.g. XActuatorTest::testDisabledMetricsShouldNotBePresent and the disabled property in my application.yml.
Example
- https://github.com/knoobie/spring-boot-25-prometheus
- run
XActuatorTest
The problem did not occur with Spring Boot 2.4.5 or without spring-boot-starter-data-jpa. Downgrading to 2.4.5 or removing spring-boot-starter-data-jpa changes all test from fail to success.
Edit: This problem does not only occur in test, running the application normally as well.
Comment From: little-pinecone
I'm also having this problem.
This seems to be a recurring issue, described here: https://stackoverflow.com/a/53119998/7995881
The solution below seems to fix it (from https://stackoverflow.com/a/57908577/7995881):
@Configuration
public class ActuatorMetricsConfig {
@Bean
InitializingBean forcePrometheusPostProcessor(BeanPostProcessor meterRegistryPostProcessor, PrometheusMeterRegistry registry) {
return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, "");
}
}
Comment From: wilkinsona
Thanks for the sample, @knoobie. The problem's due to some premature initialisation of the MeterRegistry. You can see this in the logs:
2021-05-21 12:08:12.599 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'management.metrics-org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties' of type [org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-21 12:08:14.029 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.actuate.autoconfigure.metrics.data.RepositoryMetricsAutoConfiguration' of type [org.springframework.boot.actuate.autoconfigure.metrics.data.RepositoryMetricsAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-21 12:08:14.647 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-21 12:08:15.191 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'management.metrics.export.prometheus-org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusProperties' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-21 12:08:15.721 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'prometheusConfig' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusPropertiesConfigAdapter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-21 12:08:16.205 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'collectorRegistry' of type [io.prometheus.client.CollectorRegistry] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-21 12:08:16.732 INFO 52357 --- [ 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)
2021-05-21 12:08:17.293 INFO 52357 --- [ 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)
2021-05-21 12:08:17.950 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'prometheusMeterRegistry' of type [io.micrometer.prometheus.PrometheusMeterRegistry] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-21 12:08:18.598 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'repositoryTagsProvider' of type [org.springframework.boot.actuate.metrics.data.DefaultRepositoryTagsProvider] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-21 12:08:19.198 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'metricsRepositoryMethodInvocationListener' of type [org.springframework.boot.actuate.metrics.data.MetricsRepositoryMethodInvocationListener] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
I'd like these warnings to be more prominent. In this case they're caused by a change in Boot 2.5 which we'll fix. In the meantime, you can add the following bean to improve the situation:
@Bean
public static MetricsRepositoryMethodInvocationListener metricsRepositoryMethodInvocationListener(MetricsProperties
metricsProperties, @Lazy MeterRegistry registry, RepositoryTagsProvider tagsProvider) {
Repository properties = metricsProperties.getData().getRepository();
return new MetricsRepositoryMethodInvocationListener(registry, tagsProvider, properties.getMetricName(),
properties.getAutotime());
}
The @Lazy on the MeterRegistry is sufficient to prevent most of the premature initialization so meters are still bound.
Comment From: knoobie
Another workaround I found while fixing our application. Excluding RepositoryMetricsAutoConfiguration.class works for us as well. We don't need the new metrics ASAP, so this a good workaround until the next boot release.
With the MetricsRepositoryMethodInvocationListener above, I had the problem that some of our tests fails, that don't have MetricsProperties - to reduce the migration effort (cleaning up) from 2.5.0 to 2.5.1 I decided to exclude the new feature for now, which is a nice one-liner.
Comment From: sanjayrawat1
@wilkinsona adding the bean suggested by you is failing the application to run. The repo beans are throwing NPE while building spring context.
Getting exception of BeanCreationException: Invocation of init method failed, nested exception is NPE: cannot read the array length because "
I am invoking the repo.findAll() method inside @PostConstruct method of a spring bean.
Comment From: snicoll
@sanjayrawat1 this issue is closed now and that NPE doesn't seem related to the task at hand. If you think you've found a bug in Spring Boot, please create a separate issue with a small sample we can run that reproduces the problem. You may also want to try 2.5.1-SNAPSHOT first.
Comment From: deanjo
Thanks for the sample, @knoobie. The problem's due to some premature initialisation of the
MeterRegistry. You can see this in the logs:
2021-05-21 12:08:12.599 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'management.metrics-org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties' of type [org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-05-21 12:08:14.029 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.actuate.autoconfigure.metrics.data.RepositoryMetricsAutoConfiguration' of type [org.springframework.boot.actuate.autoconfigure.metrics.data.RepositoryMetricsAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-05-21 12:08:14.647 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-05-21 12:08:15.191 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'management.metrics.export.prometheus-org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusProperties' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-05-21 12:08:15.721 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'prometheusConfig' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusPropertiesConfigAdapter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-05-21 12:08:16.205 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'collectorRegistry' of type [io.prometheus.client.CollectorRegistry] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-05-21 12:08:16.732 INFO 52357 --- [ 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) 2021-05-21 12:08:17.293 INFO 52357 --- [ 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) 2021-05-21 12:08:17.950 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'prometheusMeterRegistry' of type [io.micrometer.prometheus.PrometheusMeterRegistry] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-05-21 12:08:18.598 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'repositoryTagsProvider' of type [org.springframework.boot.actuate.metrics.data.DefaultRepositoryTagsProvider] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-05-21 12:08:19.198 INFO 52357 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'metricsRepositoryMethodInvocationListener' of type [org.springframework.boot.actuate.metrics.data.MetricsRepositoryMethodInvocationListener] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)I'd like these warnings to be more prominent. In this case they're caused by a change in Boot 2.5 which we'll fix. In the meantime, you can add the following bean to improve the situation:
@Bean public static MetricsRepositoryMethodInvocationListener metricsRepositoryMethodInvocationListener(MetricsProperties metricsProperties, @Lazy MeterRegistry registry, RepositoryTagsProvider tagsProvider) { Repository properties = metricsProperties.getData().getRepository(); return new MetricsRepositoryMethodInvocationListener(registry, tagsProvider, properties.getMetricName(), properties.getAutotime()); }The
@Lazyon theMeterRegistryis sufficient to prevent most of the premature initialization so meters are still bound.
Hello I solved the problem of missing JVM metrics using this way
@Configuration
public class ActuatorMetricsConfig {
@Bean
InitializingBean forcePrometheusPostProcessor(BeanPostProcessor meterRegistryPostProcessor, PrometheusMeterRegistry registry) {
return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, "");
}
}
The following method does not solve the problem, what is your reason?
@Bean
public static MetricsRepositoryMethodInvocationListener metricsRepositoryMethodInvocationListener(MetricsProperties
metricsProperties, @Lazy MeterRegistry registry, RepositoryTagsProvider tagsProvider) {
Repository properties = metricsProperties.getData().getRepository();
return new MetricsRepositoryMethodInvocationListener(registry, tagsProvider, properties.getMetricName(),
properties.getAutotime());
}