Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template variable not updating #95

Open
hafeja opened this issue Apr 13, 2021 · 14 comments
Open

Template variable not updating #95

hafeja opened this issue Apr 13, 2021 · 14 comments
Labels
type/bug Unexpected behavior or a feature is broken

Comments

@hafeja
Copy link

hafeja commented Apr 13, 2021

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?

@marcusolsson
Copy link
Contributor

Thank you for the excellent bug report. Much appreciated!

This seems to be a duplicate of #93. Could you confirm?

@hafeja
Copy link
Author

hafeja commented Apr 15, 2021

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 😏

@marcusolsson
Copy link
Contributor

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?

@hafeja
Copy link
Author

hafeja commented Apr 15, 2021

Unfortunately, I can still reproduce the issue with v1.1.0 😟

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.

@marcusolsson
Copy link
Contributor

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

@marcusolsson marcusolsson added triage/needs-investigation type/bug Unexpected behavior or a feature is broken labels Apr 15, 2021
@marcusolsson
Copy link
Contributor

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
Copy link
Contributor

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?

@hafeja
Copy link
Author

hafeja commented Apr 19, 2021

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.

@marcusolsson
Copy link
Contributor

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.

@ugoleleux
Copy link

ugoleleux commented Dec 13, 2021

@marcusolsson #216 (comment)
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

@bode689
Copy link

bode689 commented Feb 10, 2022

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

@marcusolsson marcusolsson moved this from Todo to 📅 Planned in Grafana plugins Mar 9, 2022
@mlcdf
Copy link

mlcdf commented Apr 27, 2022

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

@ugoleleux
Copy link

ugoleleux commented Apr 27, 2022

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

@tmbull
Copy link

tmbull commented Mar 7, 2024

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.

@gabor gabor moved this to Backlog in OSS Big Tent May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Unexpected behavior or a feature is broken
Projects
Status: Backlog
Development

No branches or pull requests

7 participants