I’m working on Druid datasource engine, and leveraging grafana-druid-plugin as front-end. The plugin first replaces all template variables, the executes the queries just fine. However when I’m implementing TsdbQueryEndpoint and Query API, the query passed in is raw text, all variables are still represented by name, something like $variable, is there a way to get its actual value in backend? from context somehow?
Have you forked Grafana and started building backend support for Druid in Grafana?
The frontend code should do the template variable replacement before sending the query to the backend. Template variable queries are stored in the dashboard json and are not sent with the query to the backend.
Thanks @daniellee. Yes, I forked Grafana and working on my own copy.
I’m also curious about alerting function when template exists. From ‘datasource.ts’, I can see an error when templates are used in query, this is true for all the datasources. Does that mean if anyone who wants to use alert, s/he can’t use template at the same time?
Yes, exactly. See this very long issue:
and our reasoning on why we have not implemented it yet:
Thanks @daniellee for finding it out for me. I’ll look at it.
Basically, there is no support for template variables in alerting queries and we are probably never going to implement that fully. We do have some partial solutions that we will be working on after New Year.
Hello @daniellee, this is interesting for me, and unfortunately looks like a bad news, if i undestand it correctly. So i’m sorry for off-topic from main subject, but your insight is appreciated.
We are currently monitoring our ventilation units in Grafana with this lovely dashboard, which gives us quick look on status (more to be implemented, but so far even this is great help for us). But it requires some human-action to watch on page, and with lot of units it’s impossible at all to scroll down and back (some sort of filtering will be implemented when 5.0 will arrive with MySQL variables support). So I would like to implement some basic alerting with Grafana (cheaper/faster than other ways) at start (like that unit #47 is not sending data for longer than 1 hour, unit #52 have CO2 level higher than 1500pm and so on), send mail, send Telegram message when this alert appeaers and agregate this alerts on main dashboard. But if i understand it correctly, this level of alerting (based on template variables) is not possible to achieve?
Thank you very much for clarification
Martin
Hi Martin,
This is the problem we introduced by connecting alerts with the graph panel. Template variables are a display option and not the same thing as wanting to alert for multiple servers. Quoting from Torkel’s answer that I linked to above:
No good solution has yet been proposed and we are still pretty sure this is a bad idea as it’s mixing two features that serve different purposes. Templating variables are used for dynamic dashboards & exploration. Alert rules can already by made to be dynamic with regex / wildcard queries. Mixing these two seems like a terrible idea, at least in way that is understandable & predictable.
Basically, you can get what you want using wildcards but you can’t mix it with template variables. We will be working to make this better next year with some sort of partial support for template variables in alert queries but it does not make sense/is impossible to support them 100% (think 3 levels of chained variables - the combined number of paths is exponential).