Creating repeatable panels based on a variable with annotations

Hello! One quick question because Google doesn’t help (probably due to my poor phrasing): I have a dashboard in Grafana with a repeatable panel that shows network traffic per switch based on a variable ($switch). This works fine but now I’m trying to add Loki logs as annotations on the same dashboard. For the love of whichever god, I cannot find the proper way to do this!

Now, if I hardcode a specific switch, this works fine. What I cannot make happen is somehow pass the Grafana variable in the LogQL query. Is there any way to do that?

I did it like this ; {filename="/var/log/telegraf/telegraf.log",job=~.*${telegraf}$}

Hmm, I don’t have telegraf in my stack but I have Loki as a direct data source instead. Unfortunately, if I’m not missing something, it seems that I cannot pass Grafana vars as ${variable}.

Whats the full query you use with hardcoded variable?

Aaah, just saw the backticks! What works (hardcoded) is this {host="10.25.251.1"}

And these IP addresses ‘live’ under dashboard variable switch

Host=~.*${switch}$
maybe this works then?

So, if I’m translating correct from what you suggested, it should become something like this, {host=${switch}$}, right? Trying right now…

https://stackoverflow.com/questions/64531912/grafana-loki-query-with-regex-interpolation-for-multiple-choice-variable

That’s what I used as a reference when i made mine

Yes, that’s exactly the case but I’m not quite there yet…

{host=${switch}} should work according to the article you linked but it doesn’t for whatever reason

This gives you nothing also? {host=~.*${switch}$}

Well, it should be an exact match so I’d guess it doesn’t need the tilde. Nevertheless, I tried it too and still nada.

What does the query inspector say?

When I save the dashboard after changing the annotation query, I get this

Same with or without tilde

Strange, i haven’t seen that error on mine before

Aaah, nevermind! I’ll pick it up again on Monday. A million thanks for your assistance though!!!

No problem :slightly_smiling_face: