1

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

KidCrippler
  • 1,633
  • 2
  • 19
  • 34

1 Answers1

1

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

/^mvng\-(.+)$/
  • So you're actually saying that the value will be taken from the first capture group of the regex? In that case - can I make some kind of an "intermediate" variable that just takes another variable and extracts part of it using a regex? – KidCrippler Feb 24 '22 at 16:07
  • 1
    Exactly. Yes, you can. – Marcelo Ávila de Oliveira Feb 24 '22 at 16:51
  • care to elaborate how? – KidCrippler Feb 24 '22 at 21:22
  • 1
    Sorry, I didn't interpret your question right. You can't use the first variable (which has the "mvng-" prefix) to create the second one, but (if you need) you can define two variables, one with the "mvng-" prefix (like you have already done) and other without the "mvng-" prefix (the way I suggested in the answer). – Marcelo Ávila de Oliveira Feb 25 '22 at 13:22