Dashboards: how to have a (preferably, hidden) variable that is calculated (transformed) based on user-chosen value of other variable

Hi, nice people!

I have a predicament where we have a bit of discrepancy in the naming of some values, that really should be named the same. for example, application logs are filtered by “dummy-service” but corresponding service Kafka consumer group would be named “dummy-service-consumer”, “dummy-service-kafka”, or something else. So, there’s basically one-to-one correspondence, but no linear one, it has to be hard-coded somewhere as a Map or a dict.

I already have a variable for $service, and I would love to have a hidden field $consumerGroup, based on that $service value, where if a $service value is blank (= All), then $consumerGroup would also be blank; and if $service is a (list of) hand-picked values, then a $consumerGroup would be a (list of) values based on those that $service includes. Ideally without even showing the value to user, but if it has to be, then it’s also good.

For now I was not able to come up with anything but two completely indepent variables, which is far from perfect.

Can I have a variable based on some other variable + transformation, without user input? And is there such a transformation based on dictionary lookup?

Many thanks in advance!

Yes, you can hide variable - use Show on dashboard (I highly recommend to have visible variable during dashboard development, just hide it at the end when you are sure that it works fine):

Yes, generally one dashboard variable can have dependency on another variable. But it depends on used datasource, how it can be implemeted.
E.g. you have variable tag_name and you will use it in instance_id variable, which will be query type and you will write query SELECT instance_id FROM table where name="$tag_name" (this not real example for your case, just meta example - check how to query your datasource and based on that write own query which will match your need).

Thanks Jan!

The issue is, there’s no data source I could have used for this transformation. It’s basically a simple mapping “if var1 == A then var2 = 1” etc.

Or should I create one? Can i create a “pseudo” data source somehow?

actually, I kinda achieved what I wanted with PostgreSQL datasource (Postgre allows to not use FROM in the query, so I could use that). Now I am almost done; just need to figure out what to do with multi-select and how to emulate “All” …

I got it sorted!

Was a bit tricky to figure but with some assistance from the docs and Inspector… this works, both for single-value, multi-value and All! Thanks!

   when 'first-service' = service then 'first-service-consumer'
   when 'other-service' = service then 'other-service-pg'
  else service
  end as consumer_group
  from unnest(string_to_array('${service:csv}',',')) service;