在 Spring Boot 3.2 中禁用示例支持以避免 Prometheus 报废指标问题

Pio*_*ski 5 spring spring-boot prometheus micrometer micrometer-tracing

新的 Spring Boot 添加了范例支持: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#broader-exemplar-support-in-micrometer-112

升级到 Spring Boot 3.2.0 后,Prometheus 停止从我们的应用程序中废弃指标,因为它需要 Prometheus 版本 2.43.0 或更高版本:

metric name web_client_requests_seconds_count does not support exemplars

我认为应该有一种方法可以禁用此功能,直到我们不再升级 Prometheus。

Jon*_*oni 6

我认为这是因为您使用的是不受支持的 Prometheus 服务器版本。您将需要 Prometheus: Exemplars 对所有时间序列的支持进行此更改 #11982。它是在Prometheus 2.43.0中引入的。另请参阅对此的讨论:Add exemplar support to _count #3996

根据 Prometheus 支持条款,您应该至少使用 2.45

如果你真的想破解这个(请不要这样做,而是使用受支持的 Prometheus 版本),我认为如果你创建一个总是说并且它可以为 spanId 和 traceId 返回 null 的值,你将看不到这些示例。SpanContextSupplier @BeanisSampled false

还可以修改Accept标头的值并text/plain代替application/openmetrics-text在自定义控制器或网关或反向代理中使用。这应该可行,因为 OpenMetrics 格式支持范例,而 Prometheus 格式不支持(Prometheus 默认要求 OpenMetrics 格式)。

  • @JonatanIvanov Metrics 是一种企业功能。2023 年 3 月 21 日 2.43 刚刚发布时,甚至不尝试向后兼容,这都是荒谬的。大公司使用 Spring Boot,有时基础设施的移动速度比单个服务慢得多。这一切都是可笑的。 (2认同)