Hello,
I need some help getting some variables to link properly in Grafana
here is a list of all my vars:
variable details: container_id
can select one, multiple, or all
hash
: can select 1 (hidden variable)
My table looks something like this:
grafana_label | config_hash | container_id | compression_type
L1 | hash1 | ID1 | c1
L2 | hash2 | ID2 | c1
L3 | hash3 | ID3 | c2
The page I’m creating is a big overview page in which users can view the status of a bunch of services. The issue I’m having is I need my container_id variable to provide the hash, container_id, and display the Grafana label. My setup above only works when a user selects one container_id. When you try to display all, hash query gets ‘None’ no matter what I seem to do.
All the panels use prometheus queries, so I can’t slice up the variables in any way.
Thanks for help in advance! Let me know if you need more info!
Use text instead of images + code formatting, pls.
Use browser console and check which query is executed for
when you select multivalue
container_id
- apparently
WHERE condition X = VAR
is very simple, so develop better one.
hmm, yeah, I think I know what you’re saying. I need to compensate for the fact the query looks like this:
SELECT config_hash AS "__text",
container_id AS "__value"
FROM containers WHERE container_id = 'hash1 + hash2'
I can return a vector of values? but this still doesn’t work? It calculates that query long before it gets to the panels. Like it’s running that query upon load, not at the panel level where I’d like it to caculate. Hence, running a psql query per panel to get the hash and then feed that variable into the prometheus query.
SELECT config_hash AS "__text",
container_id AS "__value"
FROM containers
WHERE container_id in ('hash1', 'hash2')
I just opened up developer mode to view the query and that’s what it looks like:
SELECT config_hash AS "__text",
container_id AS "__value"
FROM containers
WHERE grafana_label = ('L1', 'L2')
but that is not at all what I want. I want this:
SELECT config_hash AS "__text",
container_id AS "__value"
hash AS "__value2"
FROM containers
WHERE grafana_label LIKE ($container_id)
hmm, I’m thinking of yosiasz’s answer too…
No, first you need to know how variable is extrapolated in your case, because you selected terrible key/value option, where you can’t use advanced formatting:
Dashboard variables don’t support query inspector, so only browser console helps.
So when you know HOW it is extrapolated, then you need to be creative with SQL WHERE condition (yours “compensate”), e.g. IN, LIKE, SIMILAR, …
1 Like
This is exactly a case for IN:
WHERE grafana_label IN ($container_id)
1 Like
hmmm, yeah, I’ve done that. I’m thinking now… I feel like I’m so close…
Ok, so now all the values appear… how do I get them out based on the grafana labels?
Still at square one. This query let’s users see all the values. Which I don’t even want them to see, but nothing is linked…
I would copy/paste into code blocks but my buffers are unhappy right now. I’m working on multiple VMs.
Like the user selects “All” under labels and gets this? Can I regex filter in prometheus? Make an if/else? I would really prefer to have a Query A (PSQL gets hash) and Query B(calculates sum based on hash) in which query A gets the data, Query B completes the task as this would greatly simplify and speed up the problem I’m trying to solve.
Again, input is wrong and incomplete . It looks like we are not solving dashboard variable and PostgreSQL, but problem is now panel query and Prometheus (that can be new topic with full context). Why you are not precise, switching context without providing a new context, …
1 Like
you are a slippery one, hard to help you when you are just hacking away by trial and error and popping back in with a new issue
might be best to maybe walk away from it for a bit
haha yeah, I want to take a break. I’m leaving this job soon and I don’t want my team to assume too much work. I will come back to it tomorrow! I’ve been trying to solve this for 2 days! I feel bad because I can visualize the problem but words are hard!
1 Like
Also, I really appreciate the help/patience!
1 Like