Skip to content

Commit

Permalink
fix: variable DS_PROMETHEUS should exist in dashboard
Browse files Browse the repository at this point in the history
test: add unit test to ensure variable exists
  • Loading branch information
cgrinds committed Feb 3, 2023
1 parent 6eaff34 commit ab3dc51
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
20 changes: 20 additions & 0 deletions cmd/tools/grafana/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions grafana/dashboards/storagegrid/overview.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down
20 changes: 20 additions & 0 deletions grafana/dashboards/storagegrid/tenant.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down
11 changes: 10 additions & 1 deletion harvest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@ Pollers:
# ssl_key: /path/to/key.key
# ca_cert: /path/to/server.crt
# exporters:
# - prometheus1
# - prometheus1

# StorageGRID example
# grid-01:
# datacenter: DC-01
# addr: 10.0.0.3
# username: myuser
# password: mypass
# collectors:
# - StorageGrid

0 comments on commit ab3dc51

Please sign in to comment.