grafana-json-datasource icon indicating copy to clipboard operation
grafana-json-datasource copied to clipboard

Template variable not updating

Open hafeja opened this issue 4 years ago • 14 comments

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. image

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?

hafeja avatar Apr 13 '21 14:04 hafeja

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?

marcusolsson avatar Apr 14 '21 09:04 marcusolsson

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:

hafeja avatar Apr 15 '21 09:04 hafeja

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?

marcusolsson avatar Apr 15 '21 11:04 marcusolsson

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.

hafeja avatar Apr 15 '21 12:04 hafeja

Thank you for confirming. I'll do some more digging!

marcusolsson avatar Apr 15 '21 13:04 marcusolsson

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?

marcusolsson avatar Apr 17 '21 16:04 marcusolsson

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?

marcusolsson avatar Apr 17 '21 16:04 marcusolsson

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.

hafeja avatar Apr 19 '21 09:04 hafeja

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 avatar Apr 20 '21 06:04 marcusolsson

@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 : image

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

If I refer $name variable in the Path tab : image

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

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

ugoleleux avatar Dec 13 '21 14:12 ugoleleux

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

bode689 avatar Feb 10 '22 15:02 bode689

@ugoleleux: not all heroes wear capes. Thank you for the workaround, it works great!

mlcdf avatar Apr 27 '22 07:04 mlcdf

@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. :)

ugoleleux avatar Apr 27 '22 07:04 ugoleleux

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.

tmbull avatar Mar 07 '24 19:03 tmbull