Prometheus config doesn't work with Spring boot 2.3.0: ClassNotFoundException: io.micrometer.prometheus.HistogramFlavor
Asked Answered
P

4

17

Application was working correctly with version 2.2.6 but as the application is upgraded to latest version of spring boot 2.3.0 it stopped working and fails during startup.

2020-05-20T08:43:04.408+01:00 [APP/PROC/WEB/0] [OUT] 2020-05-20 07:43:04.407 ERROR 15 --- [ main] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. 
Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: 
    Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
    Error creating bean with name 'compositeMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryConfiguration.class]: 
    Unsatisfied dependency expressed through method 'compositeMeterRegistry' parameter 1; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
    Error creating bean with name 'prometheusMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.class]: 
    Unsatisfied dependency expressed through method 'prometheusMeterRegistry' parameter 0; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
    Error creating bean with name 'prometheusConfig' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.class]: 
    Unsatisfied dependency expressed through method 'prometheusConfig' parameter 0; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
    Error creating bean with name 'management.metrics.export.prometheus-org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusProperties': 
    Lookup method resolution failed; 
nested exception is java.lang.IllegalStateException: 
    Failed to introspect Class [org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusProperties] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@4f3f5b24]

Can see below class not found exception at the bottom of start trace. enter image description here

Pallua answered 20/5, 2020 at 8:24 Comment(0)
R
44

In your particular case the micrometer-registry-prometheus must be in-line with spring boot's micrometer-core's version. It is 1.5.1 because Spring Boot (Actuator) pulls that dependency in with version 2.3.0.

dependencies {
  implementation group: 'io.micrometer', name: 'micrometer-registry-prometheus', version: '1.5.1'
}
Recurrent answered 24/5, 2020 at 13:45 Comment(0)
G
12

Adding this answer as I initially didn't understand

must be in-line with spring boot's micrometer-core's version.

of lestar cdog answer

The micrometer-registry-prometheus package has to match the version of the io.micrometer:micrometer-core version. io.micrometer:micrometer-core is pulled by spring acutuator dependency.

You can check what version io.micrometer:micrometer-core in your IDE

IntelliJ: Project window(cmd + 1) -> External Librariesenter image description here

Gradation answered 10/8, 2020 at 9:6 Comment(1)
Yes indeed, even changing from Spring Boot 2.3.0 to 2.3.4 requires you to update micrometer-registry-prometheus from 1.5.1 to 1.5.5, otherwise you will get this error...Snarl
G
8

These two answers really helped me to sort out my issue. I'm posting this to show how to find the dependencies and version used by Spring Boot Starter Actuator ( inorder to find the io.micrometer:micrometer-core version used in your actuator dependency).

First go to the https://mvnrepository.com and search for the Spring Boot Starter Actuator and click on the "Spring Boot Starter Actuator" result. Then once you go inside, click on the version that your application use.

enter image description here

Then you will navigate to a page like below one

enter image description here

From this page, if you scroll little bit down, you'll be able to see all the other dependencies used by spring started actuator dependency (Screenshot attached below). In that table (compiled dependency), you'll be able to see the micrometer version that spring actuator uses.

enter image description here

Goodale answered 5/9, 2022 at 9:31 Comment(0)
O
1

When look at the partial logfile you included, it seems to me that multiple dependencies are not all there or working correctly. Please see the Spring Boot recommendations for using a dependency manager: https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-build-systems

When upgrading, it is always useful to check the releasenotes/changelog between versions.

If you require more help, please provide information about your configuration;

  1. your pom-file(s) (or other dependency management file)
  2. the 'prometheus configuration' that you think is causing the issues
Ornithopod answered 20/5, 2020 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.