How can I filter variables into another?

Hi ! I’m rather new to templating.
I’m creating a “unified” dashboard that will gather a bunch of metrics for an application. Those metrics come from Prometheus using node and mysql exporters.

I have created two variables that I use to select my customer, and the metrics for one or multiple node/mysql servers for this customer in particular :

tenant=label_values(tenant) gives me the customers
vm=label_values({tenant=~"$tenant"}, instance) gives me one or more instances for this tenant

the instances are named like this : tenantName_kind
kind can either be a web or a mysql_master|mysql_slave
I want to create a third variable that will filter out the vm variable and give me a list of, say, the mysql_slave instances.
Let’s say I have these values coming from the $vm variable

test_web | test_mysql_master | test_mysql_slave_1 |. test_mysql_slave_2

How can i get only the two last values (test_mysql_slave_1 |. test_mysql_slave_2) ?

I want to get them from the $vm variable because if there are instances selected manually, I want my new variable to also show these instances only .
Thanks for your kind help :slight_smile:

I look for help too fast. I think I’ve managed to get what I need :

label_values({instance=~"$vm", instance=~".*slave.*"}, instance)