Search code examples
prometheusprometheus-alertmanagerpromql

Prometheus query and case sensitivity


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?


Solution

  • 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)