grafana-json-datasource
grafana-json-datasource copied to clipboard
Template variable not updating
Hello @marcusolsson, first of all: Useful plugin, thanks!
I encountered an issue.
Scenario
The JSON plugin is used to define a template variable json-var. Inside the "Fields" tab, another template variable var (e.g. of type
"Custom") is used: $.mapping[?(@.attr == '$var')].something.

Expected behavior
json-var is always updated when var is updated.
Actual behavior
json-var isn't updated when var is updated.
Only once during creation of json-var it is initialized correctly according to var.
Environment Grafana 7.5 Neither changing "Refresh" option nor "Cache Time" solves the issue.
Basically, I would like to use a template variable inside the "Field" configuration of the "Fields" tab. How can I get it working?
Thank you for the excellent bug report. Much appreciated!
This seems to be a duplicate of https://github.com/marcusolsson/grafana-json-datasource/issues/93. Could you confirm?
From user perspective, this issue is related to usage of variables inside the "Field" configuration, not to the cache. But I don't know the internals of this plugin, maybe it's the same root cause.
If this issue disappears after #93 is fixed, then yes - it is a duplicate, otherwise not :smirk:
I've just published v1.1.0 to the marketplace. While I haven't worked on this specifically. I've fixed a couple of related issues. Would you mind letting me know if this issue is still there in 1.1.0?
Unfortunately, I can still reproduce the issue with v1.1.0 :worried:
One further thing which might help to find the root cause: Inside the Settings menu of the Template variable json-var (from my example above) , the variable var is replaced correctly by its actual value. That means the "Preview of values" section gets updated correctly. But as soon as I save the setting and go back to the dashboard, json-var is not updated anymore.
Thank you for confirming. I'll do some more digging!
I've been experimenting with this, and while I'm able to reproduce this, I'm not sure this is something I can control in the plugin. Grafana isn't calling the function (metricFindQuery) to update the values at all, which makes me wonder whether this is something Grafana supports.
Are you able to do this with any other data source?
So to clarify, if you've set json-var to refresh on Dashboard Load, it will indeed use the value set by var when the dashboard loads. So the question is whether Grafana lets you refresh when the variable it depends on change. I've tried to reproduce this with other data sources, but have been unable to do so.
Could you give me some hope that this is actually supported?
A rather common use case for me is to have a chain of depending dashboard variables like this:
var-a depends on var-b depends on var-c.
The variables are defined using MySQL as datasource. If var-c is updated, the depending variables var-b and var-a are updated properly. That's why I assume Grafana itself supports this use case.
Thanks for confirming. I've also received confirmation from the team that this should indeed work. I'll do some more troubleshooting to see why it's not triggering.
@marcusolsson https://github.com/marcusolsson/grafana-json-datasource/issues/216#issuecomment-992540623
I just updated the closed issue, but here is my entry again on this case :
I found a new behavior that will help you in your analysis.
I have a variable $name that contains a list of choices.
This variable is used inside a child variable on the Params tab :

When I look at the dependency tree, the $name var is not used by $child

If I refer $name variable in the Path tab :

This time, the dependency tree is well seeing the relation.

By doing this little change, my child var is now updated on the fly when I modify the $name.
I hope this will help you to correct this issue :)
Regards Ugo
Hi all, I just realized that parent-var does update correctly if it is referenced inside the body of child-var. Unfortunately, if the query of child-var is a GET request and we need to pass parent-var as a Param , it updates only after a manual refresh.
Hope it helps
@ugoleleux: not all heroes wear capes. Thank you for the workaround, it works great!
@mlcdf
@ugoleleux: not all heroes wear capes. Thank you for the workaround, it works great!
I'm glad it helped you, I spent so much time discovering this workaround. :)
I stumbled upon this issue with troubleshooting this same problem. In my case, it turned out the root cause was that my nginx server was configured to add the Cache-Control: max-age=3600 header on all responses.
I'm not sure if the plugin should obey or ignore the Cache-Control header or not, but I thought I would post this here in case it helps anyone else.