当在PrometheusOperator的ServiceMonitor中进行relabeling时,会出现“relabel配置替换操作需要‘target_label’值”的错误提示

这篇文章是关于什么的?

就如标题所示。
我们在编写Prometheus Operator的ServiceMonitor时遇到了一个问题:“替换操作的重标签配置需要’目标标签’值”的错误提示。

症状的解释。

当更改ServiceMonitor的重标签设置并重新启动Prometheus Pod时,如果无法启动,则查看日志会发现以下内容。

level=info ts=2019-06-07T05:27:07.605342963Z caller=notifier.go:521 component=notifier msg="Stopping notification manager..."
level=info ts=2019-06-07T05:27:07.605372036Z caller=main.go:679 msg="Notifier manager stopped"
level=error ts=2019-06-07T05:27:07.605757827Z caller=main.go:688 err="error loading config from \"/etc/prometheus/config_out/prometheus.env.yaml\": couldn't load configuration (--config.file=\"/etc/prometheus/config_out/prometheus.env.yaml\"): parsing YAML file /etc/prometheus/config_out/prometheus.env.yaml: relabel configuration for replace action requires 'target_label' value"

这个 (zhè ge)

relabel configuration for replace action requires 'target_label' value"

一旦见到,没有使用”は”,为什么会变成”???”呢?

引发的因素

定义为目标标签或源标签。

PrometheusPrometheusOperatortarget_labeltargetLabelsource_labelsourceLabel

大多数情况下,这种情况发生是因为直接复制了prometheus.yml的内容。PrometheusOperator使用的是驼峰命名法,即将单词的首字母大写,而不是使用下划线加蛇形命名法(snake_case),这是为了符合Kubernetes的最佳实践规范而设计的。相关的问题也在这里有提及:https://github.com/coreos/prometheus-operator/issues/2503

结束

因为花了将近一个小时来处理这个问题,所以我写下了这句话,为了不再有下一个受害者。
我希望这个问题能够得到统一解决…。

bannerAds