Skip to content

Commit

Permalink
fix: timeseries panels with bytes should set decimals=2 (#1934)
Browse files Browse the repository at this point in the history
Thanks to Mamoep for raising on Discord
  • Loading branch information
cgrinds committed Apr 14, 2023
1 parent 3a9ebdd commit 83dba01
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 41 deletions.
44 changes: 44 additions & 0 deletions cmd/tools/grafana/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,3 +920,47 @@ func checkHeatmapSettings(t *testing.T, path string, data []byte) {
}
})
}

func TestBytePanelsHave2Decimals(t *testing.T) {
visitDashboards(
[]string{"../../../grafana/dashboards/cmode", "../../../grafana/dashboards/storagegrid"},
func(path string, data []byte) {
checkBytePanelsHave2Decimals(t, path, data)
})
}

func checkBytePanelsHave2Decimals(t *testing.T, path string, data []byte) {
dashPath := shortPath(path)
byteTypes := map[string]bool{
"bytes": true,
"decbytes": true,
"bits": true,
"decbits": true,
"kbytes": true,
"deckbytes": true,
"mbytes": true,
"decmbytes": true,
"gbytes": true,
"decgbytes": true,
"tbytes": true,
"dectbytes": true,
"pbytes": true,
"decpbytes": true,
}

visitAllPanels(data, func(path string, key, value gjson.Result) {
panelType := value.Get("type").String()
if panelType != "timeseries" {
return
}
defaultUnit := value.Get("fieldConfig.defaults.unit").String()
if !byteTypes[defaultUnit] {
return
}
decimals := value.Get("fieldConfig.defaults.decimals").String()
if decimals != "2" {
t.Errorf(`dashboard=%s path=%s panel="%s" got decimals=%s, want decimals=2`,
dashPath, path, value.Get("title").String(), decimals)
}
})
}
46 changes: 30 additions & 16 deletions grafana/dashboards/cmode/aggregate.json
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -1115,7 +1116,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -1206,7 +1208,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -1296,7 +1299,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -1386,7 +1390,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -1857,7 +1862,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -2599,7 +2605,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -2682,7 +2689,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -2765,7 +2773,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -2848,7 +2857,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -2932,7 +2942,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -3015,7 +3026,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -3581,7 +3593,6 @@
"mode": "off"
}
},
"decimals": 0,
"mappings": [],
"min": 0,
"thresholds": {
Expand All @@ -3593,7 +3604,8 @@
}
]
},
"unit": "kbytes"
"unit": "kbytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -3936,7 +3948,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -4124,7 +4137,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down
18 changes: 12 additions & 6 deletions grafana/dashboards/cmode/cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -3112,7 +3112,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -3194,7 +3195,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -3276,7 +3278,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -3358,7 +3361,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -3441,7 +3445,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -3523,7 +3528,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down
6 changes: 4 additions & 2 deletions grafana/dashboards/cmode/disk.json
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,8 @@
}
]
},
"unit": "kbytes"
"unit": "kbytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -1284,7 +1285,8 @@
}
]
},
"unit": "kbytes"
"unit": "kbytes",
"decimals": 2
},
"overrides": []
},
Expand Down
3 changes: 2 additions & 1 deletion grafana/dashboards/cmode/fsa.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down
3 changes: 2 additions & 1 deletion grafana/dashboards/cmode/lun.json
Original file line number Diff line number Diff line change
Expand Up @@ -4423,7 +4423,8 @@
}
]
},
"unit": "deckbytes"
"unit": "deckbytes",
"decimals": 2
},
"overrides": []
},
Expand Down
9 changes: 6 additions & 3 deletions grafana/dashboards/cmode/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2367,7 +2367,8 @@
}
]
},
"unit": "deckbytes"
"unit": "deckbytes",
"decimals": 2
},
"overrides": [
{
Expand Down Expand Up @@ -2493,7 +2494,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down Expand Up @@ -2815,7 +2817,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down
3 changes: 2 additions & 1 deletion grafana/dashboards/cmode/qtree.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@
}
]
},
"unit": "kbytes"
"unit": "kbytes",
"decimals": 2
},
"overrides": []
},
Expand Down
3 changes: 2 additions & 1 deletion grafana/dashboards/cmode/s3ObjectStorage.json
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down
4 changes: 2 additions & 2 deletions grafana/dashboards/cmode/snapmirror.json
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,6 @@
"mode": "off"
}
},
"decimals": 0,
"links": [],
"mappings": [],
"thresholds": {
Expand All @@ -1059,7 +1058,8 @@
}
]
},
"unit": "bytes"
"unit": "bytes",
"decimals": 2
},
"overrides": []
},
Expand Down
Loading

0 comments on commit 83dba01

Please sign in to comment.