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

Some metrics are lost when Spring Data is on the classpath #26630

Closed
knoobie opened this issue May 21, 2021 · 6 comments
Closed

Some metrics are lost when Spring Data is on the classpath #26630

knoobie opened this issue May 21, 2021 · 6 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@knoobie
Copy link

knoobie commented May 21, 2021

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

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 21, 2021
@knoobie knoobie changed the title 2.5.0 - spring-boot-starter-data-jpa breaks metrics in tests 2.5.0 - spring-boot-starter-data-jpa breaks metrics May 21, 2021
@little-pinecone
Copy link

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, "");
    }

}

@wilkinsona
Copy link
Member

wilkinsona commented May 21, 2021

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.

@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels May 21, 2021
@wilkinsona wilkinsona modified the milestones: 2.5.x, 2.5.1 May 21, 2021
@wilkinsona wilkinsona self-assigned this May 21, 2021
@knoobie
Copy link
Author

knoobie commented May 21, 2021

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.

@wilkinsona wilkinsona changed the title 2.5.0 - spring-boot-starter-data-jpa breaks metrics spring-boot-starter-data-jpa breaks metrics May 21, 2021
@wilkinsona wilkinsona changed the title spring-boot-starter-data-jpa breaks metrics Some metrics are lost when Spring Data is on the classpath May 21, 2021
izeye added a commit to izeye/sample-micrometer-spring-boot that referenced this issue May 26, 2021
izeye added a commit to izeye/samples-spring-boot-kotlin-branches that referenced this issue May 26, 2021
@sanjayrawat1
Copy link

@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 "" is null.

I am invoking the repo.findAll() method inside @PostConstruct method of a spring bean.

@snicoll
Copy link
Member

snicoll commented Jun 1, 2021

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

@deanjo
Copy link

deanjo commented Apr 25, 2023

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.

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());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

7 participants