Skip to content

Commit

Permalink
fix: throughput should use sum aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Jul 16, 2024
1 parent ded2a1e commit 9c37e06
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
32 changes: 32 additions & 0 deletions cmd/tools/grafana/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,38 @@ var dashboards = []string{
"../../../grafana/dashboards/storagegrid",
}

var throughputPattern = regexp.MustCompile(`(throughput|read_data|write_data|total_data)`)
var aggregationThroughputPattern = regexp.MustCompile(`(?i)(\w+)\(`)

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

func checkThroughput(t *testing.T, path string, data []byte) {
path = ShortPath(path)
// visit all panels for datasource test
VisitAllPanels(data, func(_ string, _, value gjson.Result) {
panelTitle := value.Get("title").String()
kind := value.Get("type").String()
targetsSlice := value.Get("targets").Array()
for _, targetN := range targetsSlice {
expr := targetN.Get("expr").String()
if !throughputPattern.MatchString(expr) {
continue
}
matches := aggregationThroughputPattern.FindStringSubmatch(expr)
if len(matches) > 1 {
aggregation := matches[1]
if strings.EqualFold(aggregation, "avg") {
t.Errorf("dashboard=%s panel=%s kind=%s expr=%s should use sum for throughput", path, panelTitle, kind, expr)
}
}
}
})
}

func TestThreshold(t *testing.T) {
VisitDashboards(dashboards, func(path string, data []byte) {
checkThreshold(t, path, data)
Expand Down
10 changes: 5 additions & 5 deletions grafana/dashboards/cmode/node.json
Original file line number Diff line number Diff line change
Expand Up @@ -3112,7 +3112,7 @@
"targets": [
{
"exemplar": false,
"expr": "avg(node_nfs_throughput{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",node=~\"$Node\",nfsv=\"v3\"})",
"expr": "sum(node_nfs_throughput{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",node=~\"$Node\",nfsv=\"v3\"})",
"format": "table",
"instant": true,
"interval": "",
Expand All @@ -3121,7 +3121,7 @@
},
{
"exemplar": false,
"expr": "avg(node_nfs_write_throughput{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",node=~\"$Node\",nfsv=\"v3\"})",
"expr": "sum(node_nfs_write_throughput{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",node=~\"$Node\",nfsv=\"v3\"})",
"format": "table",
"hide": false,
"instant": true,
Expand All @@ -3131,7 +3131,7 @@
},
{
"exemplar": false,
"expr": "avg(node_nfs_read_throughput{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",node=~\"$Node\",nfsv=\"v3\"})",
"expr": "sum(node_nfs_read_throughput{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",node=~\"$Node\",nfsv=\"v3\"})",
"format": "table",
"hide": false,
"instant": true,
Expand Down Expand Up @@ -3467,15 +3467,15 @@
"targets": [
{
"exemplar": false,
"expr": "avg(node_nfs_read_throughput{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",node=~\"$Node\",nfsv=\"v3\"})",
"expr": "sum(node_nfs_read_throughput{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",node=~\"$Node\",nfsv=\"v3\"})",
"hide": false,
"interval": "",
"legendFormat": "Read",
"refId": "A"
},
{
"exemplar": false,
"expr": "avg(node_nfs_write_throughput{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",node=~\"$Node\",nfsv=\"v3\"})",
"expr": "sum(node_nfs_write_throughput{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",node=~\"$Node\",nfsv=\"v3\"})",
"hide": false,
"interval": "",
"legendFormat": "Write",
Expand Down

0 comments on commit 9c37e06

Please sign in to comment.