Using a variable to build up a query throws error

Hi,

I have the following metric:

kube_system_upstream_public_cra7ccfa2b62624_alb1_responseMsec

The substring “public_cra7ccfa…_alb1” is an ID for an Application Load Balancer (ALB). I don’t want to create variables or queries using the given metric name as it is, because if I want to export my dashboard and use it in another environment where the ALB ID is different, then I would have to change that part of the metric name everywhere where its used. So I managed to isolate the ALB ID with a regex expression and assign it to a variable called “alb”. I’ m trying to use that variable as part as the metric name in a query as follows:

kube_system_upstream_$alb_responseMsec

But that gives me the following error:

Template variables could not be initialized: parse error at char 22: could not parse remaining input “$alb_responseMs”…

I also tried:

kube_system_upstream_"$alb"_responseMsec

Which gives me the following error:

Template variables could not be initialized: parse error at char 22: could not parse remaining input "“public_cra7ccf”…

Is it possible to do what I’m trying? If so, what would be the correct syntax in order for the query to be successful?

Thanks in advance!

Regards

There is an alternative syntax for template variables that might work better:

kube_system_upstream_[[alb]]_responseMsec

Hi daniellee,

Thanks for your quick response. I forgot to mention that I tried that as well, but it also fails… Any other suggestion?

Is this with Prometheus?

Hi daniellee,

Yes, it is Prometheus, but I found what was wrong, I was using [[$alb]] instead of just [[alb]] :sweat_smile:. Now it’s working, thank you!

1 Like