12

I have one query where I am trying to join two metrics on a label. K_Status_Value == 5 and ON(macAddr) state_details{live="True"}

The label macAddr is present in both the metrics. The value of the label appears in 'K_Status_Value' sometimes in upper case (78:32:5A:29:2F:0D) and sometimes in lower case (78:72:5d:39:2f:0a) but always appears in upper case for 'state_details'. Is there any way I can make the label macAddr value case-insensitive in the query so that I don't miss out on the occurrences where the cases don't match?

Arnav Bose
  • 791
  • 4
  • 13
  • 27

2 Answers2

26

I can think of two options

Using regex "i" match modifier:

To quote Ben Kochie on Prometheus user mailing list:

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

It works indeed: this metric up{instance="localhost:9090",job="prometheus"} is matched by this expression :

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

This hint won't help in the case described above. It won't help either to join on (xx) or group_left.

Using a recording rule:

I was initialy hoping to use a recording rule to lower case at ingestion time (in prometheus.yml). However this features is not implemented at this time (issue 1548)

Community
  • 1
  • 1
Franklin Piat
  • 3,952
  • 3
  • 32
  • 45
-2

It looks like Prometheus has no functionality for matching label values in different cases :( But this can be solved with label_uppercase and/or label_lowercase functions from MetricsQL. For example, the following query should properly match macAddr label values in different cases:

(label_lowercase(K_Status_Value, "macAddr") == 5)
and ON(macAddr)
label_lowercase(state_details{live="True"}, "macAddr")
valyala
  • 11,669
  • 1
  • 59
  • 62