Prometheus - 添加新标签以衡量导致“标签基数不一致”错误

Prometheus - Adding new labels to gauge results in an `inconsistent label cardinality` error

我有一个将数据发送到普罗米修斯仪表的 Go 应用程序

...
import (
    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/promauto"
)
...
var gauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
    Name: "some_name",
    Help: "some desc",
},
    []string{"labelA", "labelB"},
)
...
// sending data to gauge
gauge.With(prometheus.Labels{
  "labelA": "...",
  "labelB": "...",
})

然后我修改了应用以包含第三个标签 (labelC)

...
var gauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
    Name: "some_name",
    Help: "some desc",
},
    []string{"labelA", "labelB", "labelC"},
)
...
gauge.With(prometheus.Labels{
  "labelA": "...",
  "labelB": "...",
  "labelC": "...",
})

但现在当我 运行 包含新标签的应用程序时,我收到此错误

panic: inconsistent label cardinality: expected ... label values but got ... in prometheus.Labels{...}

调用gauge.With时发生错误

有人知道为什么吗?

如果 With 中的标签数量与 NewGaugeVec 中的标签数量不匹配,客户端库将抛出此错误。因此,您可能忘记在代码中的某处添加 labelC: "..." 。您应该能够在堆栈跟踪中找到该行。