From 03ae2348028d272901e04c09ed2a859119b2d815 Mon Sep 17 00:00:00 2001 From: rahulguptajss Date: Thu, 7 Nov 2024 15:36:26 +0530 Subject: [PATCH] fix: Set dashboard variable to refresh to time range change. --- cmd/tools/grafana/dashboard_test.go | 31 +++++++++++++++++++ .../cmode-details/volumeDeepDive.json | 2 +- grafana/dashboards/cmode/vscan.json | 4 +-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/cmd/tools/grafana/dashboard_test.go b/cmd/tools/grafana/dashboard_test.go index 2e730c4f3..11ce088b8 100644 --- a/cmd/tools/grafana/dashboard_test.go +++ b/cmd/tools/grafana/dashboard_test.go @@ -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) { diff --git a/grafana/dashboards/cmode-details/volumeDeepDive.json b/grafana/dashboards/cmode-details/volumeDeepDive.json index 36d4fa128..7833f31fa 100644 --- a/grafana/dashboards/cmode-details/volumeDeepDive.json +++ b/grafana/dashboards/cmode-details/volumeDeepDive.json @@ -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, diff --git a/grafana/dashboards/cmode/vscan.json b/grafana/dashboards/cmode/vscan.json index 3041c75da..d3f454ca3 100644 --- a/grafana/dashboards/cmode/vscan.json +++ b/grafana/dashboards/cmode/vscan.json @@ -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, @@ -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,