Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2.0 Prometheus Backward Compatibility

I am migrating to Spring Boot 2.0 and I am having issues with my Prometheus Metrics.

I know that MicroMeter is the new way of doing stuff, which is not as crisp as the Prometheus libs but OK.

My issue is that If I do not want to change my metrics now I cannot upgrade to Spring Boot 2.0. Am I right?

I tried the following:

Trial no 1

  • Keep my implementations "as is"
  • add the new dependency io.micrometer:micrometer-registry-prometheus:1.0.2 to my app (actuator is already in there)
  • change stuff in application.properties to get access to the endpoint actuator/prometheus

=> My Counters and Gauges from the past got ignored. OK I understand that from a technical point of view.

Trial no 2

  • Keep my implementations "as is"
  • add the "old" 'io.prometheus' dependencies and remove the micrometer dependency
  • change stuff in application.properties to get access to the endpoint actuator/prometheus

=> Now I get the following excpetion

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.actuate.endpoint.AbstractEndpoint
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_161]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_161]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_161]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_161]
... 37 common frames omitted

So my question is: Is there a "soft migration" way which works?

like image 511
Hubert Ströbitzer Avatar asked Mar 30 '18 08:03

Hubert Ströbitzer


1 Answers

To make Trial no 1 work, just add in the Prometheus default registry as a bean that Micrometer will be able to leverage.

@Bean
public CollectorRegistry collectorRegistry() {
    return CollectorRegistry.defaultRegistry;
}

Micrometer doesn't use the default registry by default since it doesn't allow un-registering of meters and can make unit testing quite difficult.

To make Trial no 2 work will require re-implementing the prometheus actuator endpoint, since that class changed drastically with SpringBoot 2. I wouldn't recommend that approach.

like image 176
checketts Avatar answered Nov 02 '22 23:11

checketts