Warm tip: This article is reproduced from stackoverflow.com, please click
grafana prometheus

Prometheus query filter not working for OR filter

发布于 2020-04-18 10:17:43

Is there any issue with the below query?

kube_resourcequota{resource="count/deployments.apps",type="hard",namespace="test1|test2"}

It works if I pass just one namespace.

kube_resourcequota{resource="count/deployments.apps",type="hard",namespace="test1"}

Sum also works without passing anything.

sum(kube_resourcequota{resource="count/deployments.apps",type="hard"})
Questioner
user1578872
Viewed
49
Michael Doubez 2020-02-05 04:58

The instant vector selector can be expressed as

  • namespace="test1" to match label namespace exactly equal to "test1"
  • <no selector on namestapce> to match all values of namespace
  • namespace=~"test1|test2" to match label namespace with given regex

You made a mistake: you used a regex "test1[test2" with an exact match (=) instead of regex match (=~).

Correct expression would be:

kube_resourcequota{resource="count/deployments.apps",type="hard",namespace=~"test1|test2"}