prometheuspromql

why promql expression {__name__=~ ".*"} results in error message


prometheus promql expression {__name__ =~ ".*"} fails with error below where as {__name__ =~ ".+"} is valid query (regular expression .* vs .+)

Error executing query: invalid parameter "query": 1:1: parse error: vector selector must contain at least one non-empty matcher

Solution

  • In promql expression, it is mandatory to provide at least one non-empty label value as selector to match. The regular expression in the selector ".*' includes empty string which is the root cause of this error. However, ".+" doesn't include empty string and hence satisfies the condition at least one non-empty label value for selector.

    Why prometheus has to fail if the selector RE expansion includes an empty string, is something not very clear (why this restriction from prometheus)? (Vector selector __name__=".*" should not be considered as empty selector as it has many non-empty strings as well)

    One answer little bit convincing is prometheus doesn't store any empty label values. empty labels like name="" is same as label name not present at all in prometheus.

    PromQL regular expressions follow RE2 syntax where

    . means any character

    ".*" means zero or more occurrence of any character.

    ".+" means one or more occurrence of any character.

    More details in attachment. enter image description here