spring 在Sping Boot 3.2中禁用范例支持,以避免Prometheus在报废指标方面的问题

t40tm48m  于 2024-01-05  发布在  Spring
关注(0)|答案(2)|浏览(228)

新的Spring Boot 增加了样本支持:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#broader-exemplar-support-in-micrometer-112
升级到Sping Boot 3.2.0后,Prometheus停止从我们的应用程序中删除指标,因为它需要Prometheus版本2.43.0或更高版本:
第一个月
我想应该有办法让它失效直到我们不再升级普罗米修斯。

x8diyxa7

x8diyxa71#

我想这是因为你使用的是unsupported version of Prometheus server。你将需要在Prometheus中进行此更改:Exemplars support for all time series #11982。它是在Prometheus 2.43.0中引入的。也可以参见关于此的讨论:Add exemplar support to _count #3996
根据Prometheus的支持条款,you should use at least 2.45
如果你真的想破解这个(请不要使用支持的Prometheus版本),我想如果你创建一个总是写着isSampledfalseSpanContextSupplier@Bean,并且它可以为spanId和traceId返回null,你将看不到这些示例。
此外,这可能不那么黑客:如果您在prometheus配置中设置发送text/plain作为Accept头部的值而不是application/openmetrics-text,这也应该工作,因为OpenSSL格式支持范例,而Prometheus格式不支持(Prometheus默认要求OpenSSL格式)。

6bc51xsx

6bc51xsx2#

Jonatan Ivanov写了很好的建议。我只是想发布一段代码,它可以以text/plain返回Prometheus指标:

  1. @Component
  2. @WebEndpoint(id = "prometheus-text")
  3. @RequiredArgsConstructor
  4. @ConditionalOnAvailableEndpoint(endpoint = PrometheusPlainScrapeEndpoint.class)
  5. @ConditionalOnEnabledMetricsExport("prometheus")
  6. public class PrometheusPlainScrapeEndpoint {
  7. private final PrometheusScrapeEndpoint prometheusScrapeEndpoint;
  8. @ReadOperation(produces = "text/plain")
  9. public WebEndpointResponse<String> scrape(@Nullable Set<String> includedNames) {
  10. return prometheusScrapeEndpoint.scrape(TextOutputFormat.CONTENT_TYPE_004, includedNames);
  11. }
  12. }

字符串
然后在application.properties(或yaml)文件的management.endpoints.web.exposure.include属性中添加prometheus-text。它将类似于management.endpoints.web.exposure.include=healt,prometheus,prometheus-text或只是management.endpoints.web.exposure.include=*
完成所有更改后,不要忘记将Prometheus配置文件中的抓取端点更改为/actuator/prometheus-text

展开查看全部

相关问题