Repository: NetApp/harvest
Pull request #1688 (2023-02-03 18:38:10)

fix: variable DS_PROMETHEUS should exist in dashboard
test: add unit test to ensure variable exists


Patch:
diff --git a/grafana/dashboards/storagegrid/overview.json b/grafana/dashboards/storagegrid/overview.json
index 4268f7e0..cc0bdb0e 100644
--- a/grafana/dashboards/storagegrid/overview.json
+++ b/grafana/dashboards/storagegrid/overview.json
@@ -1600,6 +1600,26 @@
   ],
   "templating": {
     "list": [
+      {
+        "current": {
+          "selected": false,
+          "text": "Prometheus",
+          "value": "Prometheus"
+        },
+        "description": null,
+        "error": null,
+        "hide": 2,
+        "includeAll": false,
+        "label": "Data Source",
+        "multi": false,
+        "name": "DS_PROMETHEUS",
+        "options": [],
+        "query": "prometheus",
+        "refresh": 1,
+        "regex": "",
+        "skipUrlSync": false,
+        "type": "datasource"
+      },
       {
         "allValue": null,
         "current": {},
diff --git a/grafana/dashboards/storagegrid/tenant.json b/grafana/dashboards/storagegrid/tenant.json
index 5b2ee261..f48b48cc 100644
--- a/grafana/dashboards/storagegrid/tenant.json
+++ b/grafana/dashboards/storagegrid/tenant.json
@@ -454,6 +454,26 @@
   ],
   "templating": {
     "list": [
+      {
+        "current": {
+          "selected": false,
+          "text": "Prometheus",
+          "value": "Prometheus"
+        },
+        "description": null,
+        "error": null,
+        "hide": 2,
+        "includeAll": false,
+        "label": "Data Source",
+        "multi": false,
+        "name": "DS_PROMETHEUS",
+        "options": [],
+        "query": "prometheus",
+        "refresh": 1,
+        "regex": "",
+        "skipUrlSync": false,
+        "type": "datasource"
+      },
       {
         "allValue": null,
         "current": {},
diff --git a/harvest.yml b/harvest.yml
index 0c451bc1..bfc22e06 100644
--- a/harvest.yml
+++ b/harvest.yml
@@ -61,7 +61,7 @@ Pollers:
   # no need to add collectors, since they're already defined in Defaults
 
   # example with certificate authentication
-  # See https://github.com/NetApp/harvest/blob/main/docs/AuthAndPermissions.md#using-certificate-authentication
+  # See https://netapp.github.io/harvest/latest/prepare-cdot-clusters/#using-certificate-authentication
   # cluster-01:
   #   datacenter: DC-01
   #   addr: 10.0.0.2
@@ -70,4 +70,15 @@ Pollers:
   #   ssl_key: /path/to/key.key
   #   ca_cert: /path/to/server.crt
   #   exporters:
-  #     - prometheus1
\ No newline at end of file
+  #     - prometheus1
+
+  # StorageGRID example
+  #  grid-01:
+  #    datacenter: DC-01
+  #    addr: 10.0.0.3
+  #    username: myuser
+  #    password: mypass
+  #    exporters:
+  #      - prometheus1
+  #    collectors:
+  #      - StorageGrid


Test patch:
diff --git a/cmd/tools/grafana/dashboard_test.go b/cmd/tools/grafana/dashboard_test.go
index 31427079..a0d56ecf 100644
--- a/cmd/tools/grafana/dashboard_test.go
+++ b/cmd/tools/grafana/dashboard_test.go
@@ -28,6 +28,26 @@ func checkDashboardForDatasource(t *testing.T, path string, data []byte) {
 		}
 		return true
 	})
+
+	// Check that the variable DS_PROMETHEUS exist
+	doesDsPromExist := false
+	gjson.GetBytes(data, "templating.list").ForEach(func(key, value gjson.Result) bool {
+		if value.Get("name").String() == "DS_PROMETHEUS" {
+			doesDsPromExist = true
+			query := value.Get("query").String()
+			if query != "prometheus" {
+				t.Errorf("dashboard=%s var=DS_PROMETHEUS query want=prometheus got=%s", path, query)
+			}
+			theType := value.Get("type").String()
+			if theType != "datasource" {
+				t.Errorf("dashboard=%s var=DS_PROMETHEUS type want=datasource got=%s", path, theType)
+			}
+		}
+		return true
+	})
+	if !doesDsPromExist {
+		t.Errorf("dashboard=%s should define variable has DS_PROMETHEUS", path)
+	}
 }
 
 func TestUnitsAndExprMatch(t *testing.T) {