prometheusgrafanagrafana-variablegrafana-templating

Creating a Grafana query variable based on a manipulated version of another one


I have a grafana dashboard that I want to filter by 2 variables:

  1. Kubernetes namespace (which I can easily get from Prometheus)
  2. AWS SQS Queue - get only the queues whose names are contained in the namespace from #1

This is relatively easy - I filter via a regex based on ${namespace} and everything works: Queue name variable

The problem arises when I want to perform a string manipulation on the namespace variable before using it to filter out values, e.g. my namespace is called mvng-test-pipeline, but I only want to see queues whose names contain "test-pipeline" (disregard the "mvng-" prefix). I didn't find a way to do it via regex. I also tried to create an intermediate variable, but surprisingly, I couldn't find a way to manipulate the variables using even the simplest string manipulations such as replace() or substring().

Would appreciate any help, 10x


Solution

  • When you get the "namespace" variable from Prometheus, remove the "mvng-" prefix with a Regex like the following:

    /^mvng\-(.+)$/