Skip to content

Commit

Permalink
fix: Set dashboard variable to refresh to time range change.
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Nov 7, 2024
1 parent f645947 commit 03ae234
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
31 changes: 31 additions & 0 deletions cmd/tools/grafana/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,37 @@ func unitForExpr(e expression, overrides []override, defaultUnit string,
return defaultUnit
}

func TestVariablesRefresh(t *testing.T) {
VisitDashboards(dashboards,
func(path string, data []byte) {
checkVariablesRefresh(t, path, data)
})
}

func checkVariablesRefresh(t *testing.T, path string, data []byte) {
gjson.GetBytes(data, "templating.list").ForEach(func(key, value gjson.Result) bool {
if value.Get("type").String() == "datasource" {
return true
}
// If the variable is not visible, ignore
if value.Get("hide").Int() != 0 {
return true
}
// If the variable is custom, ignore
if value.Get("type").String() == "custom" {
return true
}

refreshVal := value.Get("refresh").Int()
if refreshVal != 2 {
varName := value.Get("name").String()
t.Errorf("dashboard=%s path=templating.list[%s].refresh variable=%s is not 2. Should be \"refresh\": 2,",
ShortPath(path), key.String(), varName)
}
return true
})
}

func TestVariablesAreSorted(t *testing.T) {
VisitDashboards(dashboards,
func(path string, data []byte) {
Expand Down
2 changes: 1 addition & 1 deletion grafana/dashboards/cmode-details/volumeDeepDive.json
Original file line number Diff line number Diff line change
Expand Up @@ -3804,7 +3804,7 @@
"query": "label_values(qtree_total_ops{datacenter=~\"$Datacenter\", cluster=~\"$Cluster\", svm=~\"$SVM\", volume=~\"$Volume\"} ,qtree)",
"refId": "PrometheusVariableQueryEditor-VariableQuery"
},
"refresh": 1,
"refresh": 2,
"regex": "",
"skipUrlSync": false,
"sort": 1,
Expand Down
4 changes: 2 additions & 2 deletions grafana/dashboards/cmode/vscan.json
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@
"query": "label_values(svm_vscan_scan_latency{system_type!=\"7mode\",datacenter=~\"$Datacenter\", cluster=~\"$Cluster\"}, svm)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"refresh": 2,
"regex": "",
"skipUrlSync": false,
"sort": 1,
Expand All @@ -1212,7 +1212,7 @@
"query": "label_values(vscan_scanner_stats_pct_cpu_used{system_type!=\"7mode\",datacenter=~\"$Datacenter\", cluster=~\"$Cluster\"}, scanner)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"refresh": 2,
"regex": "",
"skipUrlSync": false,
"sort": 1,
Expand Down

0 comments on commit 03ae234

Please sign in to comment.