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 Defaults Blanked When Using Data Links Back to Same Dashboard #35471

Open
lux4rd0 opened this issue Jun 10, 2021 · 12 comments · Fixed by #36521 or #37776
Open

Template Variable Defaults Blanked When Using Data Links Back to Same Dashboard #35471

lux4rd0 opened this issue Jun 10, 2021 · 12 comments · Fixed by #36521 or #37776

Comments

@lux4rd0
Copy link

lux4rd0 commented Jun 10, 2021

What happened:

When creating a data link to essentially "reset" any change in drop-down variables back to the dashboard defaults (On Dashboard Load) - the dashboard loads correctly (with defaults) - and then immediately blanks out all variables defaults.

What you expected to happen:

Not sure why there's an additional refresh of the variables after load that blanks out any defaults. It should not blank out the defaults (on dashboard load).

How to reproduce it (as minimally and precisely as possible):

Dashboard with data link:

1

That pushes new variables back into the same dashboard:

/d/${__dashboard.uid}/?var-forecast_day_num=${__data.fields["day_num"]}&var-display_date=${__data.fields.day_start_local}&from=now%2B${__data.fields.day_relative}d%2Fd&to=now%2B${__data.fields.day_relative}d%2Fd&var-interval=1h&${station_name:queryparam}&${tz:queryparam}

2

Dashboard presented with new parameters correctly.

Click on the panel link to "reset" back to the dashboard URL without any pushed variables (top Left panel has a panel link):

URL: /d/${__dashboard.uid}

3

Takes me back to the same dashboard as expected and proper... And then a split second later, removes all "on dashboard load" variables to:

4

Them all being blank. (The variables are in the dropdowns - just the default selection has been wiped out...)

Anything else we need to know?:

Rolled back to testing on 7.5.7 and this works as expected.

Environment: Linux Docker x64

  • Grafana version: 8.0.0 Release - but also tested nightly Grafana v8.1.0-25681pre (f4e9dcd)
  • Data source type & version:
  • OS Grafana is installed on:
  • User OS & Browser: MacOS - Version 91.0.4472.77 (Official Build) (x86_64) and Safari Version 14.1.1 (16611.2.7.1.4)
  • Grafana plugins:
  • Others:
@lux4rd0 lux4rd0 changed the title Template Variables Blanked (Not Refreshing "On Dashboard Load") When Using Data Links Template Variable Defaults Blanked When Using Data Links Back to Same Dashboard Jun 10, 2021
@natellium natellium added this to Bugs (max. 35) in Frontend Platform Backlog Jun 10, 2021
@lux4rd0
Copy link
Author

lux4rd0 commented Jun 24, 2021

Thought I'd share a quick animated GIF showing this... Makes panel and datalinks unusable in this version if you're using variables.

blanking

@tskarhed tskarhed self-assigned this Jul 6, 2021
@tskarhed
Copy link
Contributor

tskarhed commented Jul 6, 2021

I have a feeling we have had this exact same issue before.

@tskarhed
Copy link
Contributor

tskarhed commented Jul 6, 2021

@lux4rd0 If you have the default values and then click the link, do the values disappear?

@lux4rd0
Copy link
Author

lux4rd0 commented Jul 6, 2021

If I launch the page - then click on the link, the values do not disappear. I tried a few other things as well.

Change the time frame and click the link - values do not disappear.

I think it just happens to do with when I change a variable. I did a few other tests where I changed the variable - then used the link - and it reset back as normal, and then quickly wiped all of the variables out to empty. (but still in the drop-downs - just not selected.)

@tskarhed tskarhed moved this from Bugs (max. 35) to In progress (max. internal 6) in Frontend Platform Backlog Jul 7, 2021
Frontend Platform Backlog automation moved this from In progress (max. internal 6) to Done Jul 9, 2021
@lux4rd0
Copy link
Author

lux4rd0 commented Jul 9, 2021

@tskarhed I just tested main and it's almost right. In my case - three of the four variables reset correctly - one that defaults to "All" still blanked out a second after hitting the anchor link.

missing_stations

Should be:

station_all

Variable definition:

station_variable

Trying to troubleshoot what's different in these variables...

"templating": {
   "list": [
     {
       "allValue": null,
       "current": {
         "selected": false,
         "text": "All",
         "value": "$__all"
       },
       "datasource": "InfluxDB - weatherflow",
       "definition": "SHOW TAG VALUES WITH KEY = \"station_name\"",
       "description": null,
       "error": null,
       "hide": 0,
       "includeAll": true,
       "label": "Station Name",
       "multi": true,
       "name": "station_name",
       "options": [],
       "query": "SHOW TAG VALUES WITH KEY = \"station_name\"",
       "refresh": 1,
       "regex": "",
       "skipUrlSync": false,
       "sort": 5,
       "tagValuesQuery": "",
       "tagsQuery": "",
       "type": "query",
       "useTags": false
     },

@tskarhed tskarhed reopened this Jul 9, 2021
@lux4rd0
Copy link
Author

lux4rd0 commented Jul 9, 2021

Actually - looking at this again - a few other variables aren't right either. It's resetting to first available in the variable - not what's defaulted in the "save variables". My "Interval" variable is set by default to 12h (saving) but gets reset to 1d, even though it was "pushed" to 1h by my link. So maybe the fix is ignoring the saved defaults?

@lux4rd0
Copy link
Author

lux4rd0 commented Jul 9, 2021

This is on first page load:

{
        "allValue": null,
        "current": {
          "selected": false,
          "text": "12h",
          "value": "12h"
        },
        "description": null,
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": "Interval",
        "multi": false,
        "name": "interval",
        "options": [
          {
            "selected": false,
            "text": "1d",
            "value": "1d"
          },
          {
            "selected": true,
            "text": "12h",
            "value": "12h"
          },
          {
            "selected": false,
            "text": "6h",
            "value": "6h"
          },
          {
            "selected": false,
            "text": "4h",
            "value": "4h"
          },
          {
            "selected": false,
            "text": "2h",
            "value": "2h"
          },
          {
            "selected": false,
            "text": "1h",
            "value": "1h"
          }
        ],
        "query": "1d,12h,6h,4h,2h,1h",
        "queryValue": "",
        "skipUrlSync": false,
        "type": "custom"
      },

Turns into this on clicking the link (which is not what's stored as my saved defaults):

{
        "allValue": null,
        "current": {
          "selected": true,
          "text": "1d",
          "value": "1d"
        },
        "description": null,
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": "Interval",
        "multi": false,
        "name": "interval",
        "options": [
          {
            "selected": true,
            "text": "1d",
            "value": "1d"
          },
          {
            "selected": false,
            "text": "12h",
            "value": "12h"
          },
          {
            "selected": false,
            "text": "6h",
            "value": "6h"
          },
          {
            "selected": false,
            "text": "4h",
            "value": "4h"
          },
          {
            "selected": false,
            "text": "2h",
            "value": "2h"
          },
          {
            "selected": false,
            "text": "1h",
            "value": "1h"
          }
        ],
        "query": "1d,12h,6h,4h,2h,1h",
        "queryValue": "",
        "skipUrlSync": false,
        "type": "custom"
      },

@tskarhed tskarhed moved this from Done to In progress (max. internal 6) in Frontend Platform Backlog Jul 12, 2021
@natellium natellium added this to In progress (max. 4) in User essentials squad (deprecated) Jul 12, 2021
@natellium natellium removed this from In progress (max. internal 6) in Frontend Platform Backlog Jul 14, 2021
@tskarhed tskarhed moved this from In progress (max. 4) to To be prioritised in User essentials squad (deprecated) Jul 19, 2021
@natellium natellium moved this from To be prioritised to Backlog (max bugs: TBD) in User essentials squad (deprecated) Jul 22, 2021
@lux4rd0
Copy link
Author

lux4rd0 commented Jul 25, 2021

I've also noticed that if I change a drop-down variable, move to something like the folder view (clicking on the top folder path next to the Dashboard name) then choose the same dashboard, it'll blank out the variables that were defined to be "save as default".

I can repeat this on the Play site:

https://play.grafana.org/d/000000137/influxdb-group-by-variable

The groupBy default is "datacenter".

datacenter

Change it to something else like "source"

source

Click back up on the folder view to take you back to "Influx DB"

Influx DB

Then choose the "InfluxDB Group By Variable" again, and the groupBy is blank.

empty

I've done it with all of the other examples in the InfluxDB example folder, and it obviously can get pretty drastic...

drastic

I see there's a PR for this - #36839 - but since it looks to be failing on something besides a datalink pushing a URL - not sure if that would fix things in this case either... Thanks for taking a look at this!

@hugohaggmark
Copy link
Contributor

Hi everyone, I've looked into this issue a bit and I think the root cause is that we've migrated to React Router. Previously we did a full page reload and so the variables would auto load the defaults. But now we're just changing the variable values when the user clicks a panel link. I'm looking into a solution for this.

@hugohaggmark hugohaggmark moved this from Backlog (max bugs: TBD) to In progress (max. 4) in User essentials squad (deprecated) Aug 10, 2021
@hugohaggmark hugohaggmark moved this from In progress (max. 4) to In Review (max internal 8, max external 3) in User essentials squad (deprecated) Aug 11, 2021
User essentials squad (deprecated) automation moved this from In Review (max internal 8, max external 3) to Done Aug 13, 2021
@lux4rd0
Copy link
Author

lux4rd0 commented Aug 19, 2021

@hugohaggmark I just pulled the 8.1.2 release today and I'm still having the issues with blanked variables.

blanked_still

Where Station Name and Forecast Day should have variables in them. (Station Name has an "All" and Forecast Day has an empty default).

Can we revisit this?

Thanks!

@lux4rd0 lux4rd0 reopened this Aug 19, 2021
@hugohaggmark
Copy link
Contributor

hugohaggmark commented Aug 20, 2021

@lux4rd0 what does your dashboard json look like for those variables? Try the following:

  1. Change Station Name and Forecast Day to the values that you want to have as defaults.
  2. Save dashboard and very important to check the Save current variable values as dashboard default
    image
  3. Remove any var-= from the url in the browser and hit ENTER for a clean variable system reload
  4. Make sure the default values you selected in step 1 appear as expected
  5. Now try the issue you were having

If you still have an issue ping me again. Thank you 🙏

@lux4rd0
Copy link
Author

lux4rd0 commented Aug 20, 2021

Thanks, @hugohaggmark - I still had one "default" that wasn't added to my JSON for Station Name:

Before:

	  "templating": {	
    "list": [	
      {	
        "allValue": null,	
        "current": {	
          "selected": false,	
          "text": "All",	
          "value": "$__all"	
        },

After:

	  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {
          "selected": false,
          "text": [
            "All"
          ],
          "value": [
            "$__all"
          ]
        },

The other variable for Forecast Day shouldn't have a saved default, however - since it's dynamically generated. I'll see how that gets impacted - but I don't see a change in the JSON for that variable. I Will review it tomorrow as the date progresses. I think this looks good though. :) Thanks!

@hugohaggmark hugohaggmark removed their assignment Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment