Variable constants are unreliable

I’m finding the use of Grafana dashboard constants to be unreliable. I’m probably doing something wrong. Here’s the situation: I create a dashboard with hidden constants, e.g., instance, node, etc. I set the value of the constant. And then I use the dashboard. My intent was to share certain elements from dashboard to dashboard to make creating new ones easy.

But… when I access the dashboard I find that the constant variables are being overridden. There’s no ‘var-instance’ or ‘var-node’, etc. in the URL but the variables are still not the ones I set in the dashboard definition. When I use Chrome Dev Tools I see that the variables are being retrieved but that the ‘current’ value is the override value and the ‘options’ are the dashboard pre-set value.

What am I missing?

Make sure you check the checkbox “save current variables”

It only shows up if you changed the values of variables.

56

1 Like

I was wondering this like days… why my constant show in generated sql query different values. Please make that save current variables as default “ON”.

Is there any reason why you would not want to save current variables?

Exactly. the case for NOT saving the variables has to be much more rare then WANTING to save them.

I’d actually disagree with the case for NOT saving them being rare. I want to build a dashboard with variables so that I can easily and quickly dynamically change my dashboard to see the data I currently want (like specific host stats from an otherwise cluster view dashboard. I often will make minor tweaks to dashboards while viewing them and don’t want to save my variables changes each time, only the minor panel tweaks. I try to setup my dashboards initially as a good general/default view of information (i.e. variables are often set to “All” for the default view kind of thing)

Let’s think about how many people wonder this first time… you make a constant first time all good. Then you want to tweak it, save it → do not spot the slider: default “OFF”. Then you start to wonder weeks after… why the results are bit strange. Then you inspect the generated SQL… and there is the (old) value still. After this you go and check the variables, there is the new value :confused:. Start wondering what’s wrong.

You do not most likely start to edit the constant, due it’s correct. This will result, that you never see the additional “save current variables” proposed.

1 Like

I’ve hit on this problem now. I created a dashboard that uses one set of variables for one of our sites. I did ‘save as’ to create a copy of the dashboard and updated the variables for another site. I then clicked ‘Save’, didn’t notice the slider. On returning to the dashboard, it’s still using the variables for the old site.

After much head-scratching, I then came across this thread, so changed the variables and saved again with the ‘Save variables’ slider on. However, no matter if I refresh the page or not, the second dashboard still insists on using the initial variables from the first dashboard. So it seems that even the action expected of the ‘Save variables’ slider is not working as expected.

What I’ve found works is to switch back to using ‘Query’ variables, and change the ‘Refresh’ from ‘Never’ to ‘On Dashboard Load’. Then, switch back to using ‘Constant’ variables and put the data back in.

So, I suggest that when using ‘Constant’ variables, the ‘Refresh’ parameter should be forced to ‘On Dashboard Load’, otherwise it will not work as expected. Bug report?

Thanks for this! I’ve had this issue for days and did not know what was wrong.