I have written a script that imports pre-built templated Grafana dashboards into my Grafana installation for different orgs. These dashboards make use of template variables, some of which are of type Constant, and others are populated from the Prometheus datasource. As part of the import, the constant template variables are given a pre-set value (specific to the org for which the import job is running). The constant template variables are then used in the dashboard queries to limit scope of the query based on Prometheus labels.
One of the constant variables (stack) used in the above scenario, has a valid “EMPTY” state. Since the template variables cannot be empty, I use ‘.+’ instead and the queries use regex match. This works correctly when the dashboard is manually created. However, when the dashboard is imported, while the template variable value shows up correctly (.+) in the template editor, the query sent to Prometheus replaces the ‘+" with an escaped Space (’%20"). This effectively fails the query and returns no data for the dashboard.
see http capture:
Strangely, this issue gets temporarily suppressed, if I put the dashboard in edit mode and just randomly tab/click around. Opening the template editor, or the panel editor itself does not make a difference, however seemingly random clicking/tabbing through both the template variable value and anyone of the panel’s query textbox seems to trigger an understanding of the ‘.+’ and prevents the escape. This trigger then applies to all the queries on that dashboard, but only persists until moving out of that dashboard.
see http capture:
One moving out of the dashboard without saving any changes, the situation reverts and opening the dashboard takes it back to the original state.
Obviously I do not want to save the dashboard at this point, as that defeats the purpose of the dashboard import script.
I am using Grafana 4.2.0.
Any ideas on why this is happening?