What is the sequence order of queries sent by grafana to datasource server?

What is the sequence order of queries sent by grafana to datasource server?
And which grafana component defines it?

In my grafana 4.6.2 dashboard with graph panel and clickhouse datasource I’m using ~5 linked (hierarchical) template variables (ex., A,B,C,D,E,F) with “Query” type, refresh “On Time Range Change” and their values filled from clickhouse queries like:

select A from ...
select B from ... where a=$A ...
select C from ... where a=$A and b=$B ...
...

and metrics query in graph panel uses these template variables:

SELECT ... FROM DB.TABLE WHERE $timeFilter AND field_a=$a AND field_b=$B ...

I noticed that when value for template variable $A is selected(changed) from dropdown too fast metrics query after template vars substitution gets malformed with some (typically last) variable expanded as empty string.
Naturally, this causes syntax error responce from DB and failure to draw graph. Simple click on dashboard refresh icon makes it work fine again.

Chrome devtools and apache log show that in case of problem some queries for template variables are sent after the main metrics query.

The sequence should be sequential I suppose. Would suggest you to create a bug report over at Grafana github repository if you think this is a bug.

Marcus

I’m facing the same problem with grafana-enterprise/stable,now 7.1.1 amd64 uner Ubuntu

Query sequence and timing are correctly executed, but variable are not updated. In the image you can see a wrong query based on variable value that is get correctly time before (is the second query executed 20ms before and that return the correct value. Seems the error is inside grafana template variable engine :confused:

opened issue https://github.com/grafana/grafana/issues/26647