Queries with parentheses in label values are failing to generate results - Grafana or Prometheus issue?

On our grafana dashboards we have queries run using template variables, such as:

We noticed that the query is not returning any results when there are parentheses in label values. For example, when programName is FXHD(Pacific), the query does not return any results. The following is the URL used by grafana, as reported by the Query Inspector. So grafana is attempting to escape the parenthesis using %5C%5C :

When there are no parenthesis in the label value, query successfully returns results.

I also noticed that the same query with the same label value works fine when using the prometheus expression browser. And the expression browser is NOT using %5C%5C to escape the parenthesis.

For further testing, I also tried using curl & HTTP API of Prometheus to perform the queries directly (outside grafana) and reproduced the problem. When using %5C%5C before the parenthesis in label value, queried fail. When they are not used, queries are successful.

Could this be an issue in Grafana or a Prometheus issue? Grafana is using %5C%5C before each parentheses in label value in its queries, but Prometheus does not like them (and works fine when %5C%5C is not used before parentheses in label value).

I know this is a really old post, but I just ran into this issue as well but found a solution by using the advanced variable format options. You can fix your issue by changing $programName to ${programName:raw} to not escape the parenthesis.

1 Like