Prometheus 查询和区分大小写

Prometheus query and case sensitivity

我有一个查询,我试图在一个标签上加入两个指标。 K_Status_Value == 5 和 ON(macAddr) state_details{live="True"}

标签 macAddr 出现在两个指标中。标签的值出现在 'K_Status_Value' 有时大写 (78:32:5A:29:2F:0D) 有时小写 (78:72:5d:39:2f:0a) 但总是出现'state_details' 的大写字母。有什么方法可以使查询中的标签 macAddr 值不区分大小写,这样我就不会错过大小写不匹配的情况吗?

我能想到两个方案

使用正则表达式“i”匹配修饰符:

引用 Ben Kochie 对 Prometheus 用户的评论 mailing list:

The regexp matching in Prometheus is based on RE2 I think you can set flags within a match by using (?i(matchstring))

它确实有效:这个指标 up{instance="localhost:9090",job="prometheus"} 与这个表达式相匹配:

up{job=~"(?i:(ProMeTHeUs))"}

此提示对上述情况没有帮助。加入 on (xx)group_left.

都无济于事

使用记录规则:

我最初希望使用 recording rule to lower case at ingestion time (in prometheus.yml). However this features is not implemented at this time (issue 1548)

看起来 Prometheus 没有在不同情况下匹配标签值的功能:(但这可以用 label_uppercase and/or label_lowercase functions from MetricsQL 解决。例如,以下查询应该正确匹配 macAddr 中的标签值不同情况:

(label_lowercase(K_Status_Value, "macAddr") == 5)
and ON(macAddr)
label_lowercase(state_details{live="True"}, "macAddr")