Grafana Version:
grafana v10.3.1 on docker container using grafana/grafana base image
I’m trying to filter a chained variable. The filter works and the chaining works as expected, but the psql query can’t handle the ‘All’ option and the UI leaves me no ability to correct this.
Trying to make this clear:
Var1=container_type
var_type=Custom
values: type_1, type_2, type_3
Var2=container_id
var_type=PSQL_Query
Query:
SELECT grafana_label AS "__text", container_id AS "__value" FROM containers WHERE container_type = ($container_type)
Possible values (these DO appear and this WORKS):
container_type=type_1
Result: id-446, id-578, etc (id’s that match on container type)
When container_type=All
I get nothing for id’s…
DB structure:
I have a table of containers with all the information I need on them to display specific metrics. We run metrics and I get those easily off of Prometheus, but the PSQL tables are mostly for historical references and my display.
NDA’s prevent me from taking photos, but hopefully I’m clear.
No errors showed up. I can set the All parameter to a default custom value… but I can’t seem to get it to work with the query?
Suggestion: Allow the custom All section to be a separate query to get exactly what I want with ease. For now, I need a workaround.
That’s not bug. You just don’t see how you can use all options, which Grafana has.
Var1=container_type
BUT: Custom all value: %
Var2=container_id
Query:
SELECT grafana_label AS “__text”, container_id AS “__value” FROM containers WHERE container_type LIKE ‘%${container_type:raw}%’
So what kind of SQL will be generated when Var1=All?
SELECT grafana_label AS “__text”, container_id AS “__value” FROM containers WHERE container_type LIKE ‘%%%’
So what kind of SQL will be generated when Var1=type_1?
SELECT grafana_label AS “__text”, container_id AS “__value” FROM containers WHERE container_type LIKE ‘%type_1%’
Both are valid SQLs. Of course there can be many other variations how to achieve desired result and this is just one example.
1 Like
Correct, the query is still valid. However, that isn’t what I want. I apologize because I didn’t clarify that.
I would like to run this when container_type=‘All’
SELECT grafana_label AS "__text", container_id AS "__value" FROM containers
This would return all the ids in my db. I did try setting my default value for container_type=%
That didn’t seem to work.
Correction: it seems to work in the actual psql CLI. I’m going to try recreating my dashboard container.
IT WORKS! Thank you!
Here’s my query:
SELECT grafana_label AS "__text", container_id AS "__value" FROM containers WHERE container_type LIKE '${container_type_l:raw}'
Here’s the default val for container type:
%
(see image above)