本文介绍了Spring Boot 2.0 Prometheus向后兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迁移到Spring Boot 2.0,但是我的Prometheus指标存在问题.

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

我知道MicroMeter是一种新的做事方式,它不像Prometheus库那么清晰,但是还可以.

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

我的问题是,如果现在不想更改指标,则无法升级到Spring Boot 2.0.我说的对吗?

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?

我尝试了以下操作:

第1次审判

  • 保持实施不变"
  • 将新的依赖项io.micrometer:micrometer-registry-prometheus:1.0.2添加到我的应用中(执行器已经在其中)
  • 更改application.properties中的内容以访问端点actuator/prometheus
  • 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

=>我过去的CountersGauges被忽略了.好的,我从技术角度理解这一点.

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

第2次审判

  • 保持实施不变"
  • 添加旧的" io.prometheus"依赖性,并删除千分尺依赖性
  • 更改application.properties中的内容以访问端点actuator/prometheus
  • 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?

推荐答案

要使第1次试验有效,只需将Prometheus默认注册表添加为Micrometer可以利用的bean./p>

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默认情况下不使用默认注册表,因为它不允许注销仪表,并且可能使单元测试相当困难.

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.

要进行 2号试验工作,需要重新实现Prometheus执行器端点,因为该类在SpringBoot 2中发生了巨大变化.我不推荐这种方法.

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.

这篇关于Spring Boot 2.0 Prometheus向后兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-10 04:33