Using grafana v7.5.15 (the docker image), I’m looking for a way to escape a $
so it doesn’t get interpreted as a template variable.
I’ve tried:
\$
← gets passed through as is
$$
← gets passed through as is
\\$
← gets passed through as is
but they don’t do what I want (pass through the string $1
but without grafana attempting to interpolate it).
Here’s an example prometheus query:
label_replace(
rate(container_cpu_usage_seconds_total{name=~"${cluster}"}[5m]),
"alloc",
"$1",
"name",
".*"
)
Right now grafana treats $1
as a variable replacement, but fortunately does nothing since the 1
variable doesn’t exist. But we have more complex use cases and I’d like to try and avoid this in the future.
2 Likes
do you think you could try and replicate this on our public sandbox, https://play.grafana.org ?
I might suggest upgrading to at least Grafana 8, as we aren’t really supporting v7 anymore
2 Likes
granted, the problem might still exist
1 Like
Can do; I tried on the template variable dashboard .
source:
## Escape a $?
```
${servers}
$${servers}
\${servers}
\\${servers}
```
rendered:
Escape a $?
test.1, test2
$test.1, test2
\test.1, test2
\\test.1, test2
(removing the {}
made no difference)
Desired output:
${servers}
xbglowx
September 23, 2022, 7:27pm
5
Running into the same problem with Grafana 8.3.6. Need to figure out how to escape the capture group reference.
1 Like
Run into the same problem, found a workaround: make a constant nothing
with empty value, and then $${nothing}variable
is rendered as $variable
1 Like
Ah! that’s a good workaround.
Or, possibly more clearly, add a constant variable dollar=$
, then
${dollar}1
becomes →
$1