Skip to content

Commit

Permalink
fix: Test grafana dashboards in hubble deploy (#650)
Browse files Browse the repository at this point in the history
# Description

Closes #501 

## Related Issue

The refactored hubble deployment included in grafana dashboard testing.
Also renamed the dashboards folder to match the `grafana` application
and the Makefile setup. This make phony is not run in CI and tests are
run via `make test` so this folder issue does not show up.

## Checklist

- [x] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [x] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [x] I have correctly attributed the author(s) of the code.
- [x] I have tested the changes locally.
- [x] I have followed the project's style guidelines.
- [x] I have updated the documentation, if necessary.
- [x] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

```bash
go test ./... -tags=dashboard -v
=== RUN   TestDashboardsAreSimplified
    simplify-grafana_test.go:21: verifying that dashboard is simplified: ../../../hubble/grafana/dashboards/clusters.json
    simplify-grafana_test.go:21: verifying that dashboard is simplified: ../../../hubble/grafana/dashboards/dns.json
    simplify-grafana_test.go:21: verifying that dashboard is simplified: ../../../hubble/grafana/dashboards/pod-flows-namespace.json
    simplify-grafana_test.go:21: verifying that dashboard is simplified: ../../../hubble/grafana/dashboards/pod-flows-workload.json
    simplify-grafana_test.go:21: verifying that dashboard is simplified: ../../../legacy/grafana/dashboards/clusters.json
    simplify-grafana_test.go:21: verifying that dashboard is simplified: ../../../legacy/grafana/dashboards/dns.json
    simplify-grafana_test.go:21: verifying that dashboard is simplified: ../../../legacy/grafana/dashboards/pod-level.json
--- PASS: TestDashboardsAreSimplified (0.01s)
PASS
ok      github.com/microsoft/retina/deploy/testutils/grafana/dashboards (cached)
```
```bash
make simplify-dashboards
cd deploy/testutils && go test ./... -tags=dashboard,simplifydashboard -v && cd /home/tisham/dev/retina
=== RUN   TestOverwriteDashboards
    simplify-grafana-overwrite_test.go:20: simplifying/overwriting dashboard: ../../../hubble/grafana/dashboards/clusters.json
    simplify-grafana-overwrite_test.go:20: simplifying/overwriting dashboard: ../../../hubble/grafana/dashboards/dns.json
    simplify-grafana-overwrite_test.go:20: simplifying/overwriting dashboard: ../../../hubble/grafana/dashboards/pod-flows-namespace.json
    simplify-grafana-overwrite_test.go:20: simplifying/overwriting dashboard: ../../../hubble/grafana/dashboards/pod-flows-workload.json
    simplify-grafana-overwrite_test.go:20: simplifying/overwriting dashboard: ../../../legacy/grafana/dashboards/clusters.json
    simplify-grafana-overwrite_test.go:20: simplifying/overwriting dashboard: ../../../legacy/grafana/dashboards/dns.json
    simplify-grafana-overwrite_test.go:20: simplifying/overwriting dashboard: ../../../legacy/grafana/dashboards/pod-level.json
--- PASS: TestOverwriteDashboards (0.01s)
PASS
ok      github.com/microsoft/retina/deploy/testutils/grafana/dashboards 0.013s
```

## Additional Notes

This PR duplicates code if more dashboard folders are added it would
perhaps be useful to improve the go test code to receive a list of
folders instead.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.
  • Loading branch information
whatnick authored Aug 30, 2024
1 parent 78f4b94 commit 3abb947
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,4 @@ quick-deploy-hubble:

.PHONY: simplify-dashboards
simplify-dashboards:
cd deploy/legacy/grafana/dashboards && go test . -tags=dashboard,simplifydashboard -v && cd $(REPO_ROOT)
cd deploy/testutils && go test ./... -tags=dashboard,simplifydashboard -v && cd $(REPO_ROOT)
14 changes: 7 additions & 7 deletions deploy/hubble/grafana/dashboards/clusters.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"__inputs": [],
"__elements": {},
"__inputs": [],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"type": "grafana",
"version": "9.5.15"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"type": "datasource",
"version": "1.0.0"
},
{
"type": "panel",
"id": "stat",
"name": "Stat",
"type": "panel",
"version": ""
},
{
"type": "panel",
"id": "table",
"name": "Table",
"type": "panel",
"version": ""
},
{
"type": "panel",
"id": "text",
"name": "Text",
"type": "panel",
"version": ""
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"type": "panel",
"version": ""
}
],
Expand Down
10 changes: 5 additions & 5 deletions deploy/hubble/grafana/dashboards/dns.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
{
"__inputs": [],
"__elements": {},
"__inputs": [],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"type": "grafana",
"version": "9.5.15"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"type": "datasource",
"version": "1.0.0"
},
{
"type": "panel",
"id": "table",
"name": "Table",
"type": "panel",
"version": ""
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"type": "panel",
"version": ""
}
],
Expand Down
14 changes: 7 additions & 7 deletions deploy/hubble/grafana/dashboards/pod-flows-namespace.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"__inputs": [],
"__elements": {},
"__inputs": [],
"__requires": [
{
"type": "panel",
"id": "bargauge",
"name": "Bar gauge",
"type": "panel",
"version": ""
},
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"type": "grafana",
"version": "9.5.15"
},
{
"type": "panel",
"id": "heatmap",
"name": "Heatmap",
"type": "panel",
"version": ""
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"type": "datasource",
"version": "1.0.0"
},
{
"type": "panel",
"id": "stat",
"name": "Stat",
"type": "panel",
"version": ""
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"type": "panel",
"version": ""
}
],
Expand Down
12 changes: 6 additions & 6 deletions deploy/hubble/grafana/dashboards/pod-flows-workload.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{
"__inputs": [],
"__elements": {},
"__inputs": [],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"type": "grafana",
"version": "9.5.15"
},
{
"type": "panel",
"id": "heatmap",
"name": "Heatmap",
"type": "panel",
"version": ""
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"type": "datasource",
"version": "1.0.0"
},
{
"type": "panel",
"id": "stat",
"name": "Stat",
"type": "panel",
"version": ""
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"type": "panel",
"version": ""
}
],
Expand Down
File renamed without changes.
33 changes: 0 additions & 33 deletions deploy/legacy/graphana/dashboards/simplify-grafana_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@
package dashboard

import (
"os"
"path/filepath"
"testing"
)

// TestOverwriteDashboards simplifies and overwrites Grafana dashboards in this folder.
// TestOverwriteDashboards simplifies and overwrites Grafana dashboards in deploy folder variants
func TestOverwriteDashboards(t *testing.T) {
// get all json's in this folder
files, err := os.ReadDir("./")
// get all json's in various generation deploly folders
files, err := filepath.Glob("../../../*/grafana/dashboards/*.json")

if err != nil {
t.Fatal(err)
}

for _, file := range files {
if filepath.Ext(file.Name()) == ".json" {
t.Logf("simplifying/overwriting dashboard: %s", file.Name())
t.Logf("simplifying/overwriting dashboard: %s", file)

sourcePath := file.Name()
_ = SimplifyGrafana(sourcePath, true)
}
sourcePath := file
_ = SimplifyGrafana(sourcePath, true)
}
}
31 changes: 31 additions & 0 deletions deploy/testutils/grafana/dashboards/simplify-grafana_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build dashboard && !simplifydashboard

package dashboard

import (
"path/filepath"
"reflect"
"testing"
)

// TestDashboardsAreSimplified ensures that all dashboards are simplified
func TestDashboardsAreSimplified(t *testing.T) {
// get all json's in this folder
files, err := filepath.Glob("../../../*/grafana/dashboards/*.json")

if err != nil {
t.Fatal(err)
}

for _, file := range files {
t.Logf("verifying that dashboard is simplified: %s", file)

sourcePath := file
simplified := SimplifyGrafana(sourcePath, false)
original := ParseDashboard(sourcePath)

if !reflect.DeepEqual(simplified, original) {
t.Errorf("ERROR: dashboard has not been simplified. Please run: make simplify-dashboards")
}
}
}

0 comments on commit 3abb947

Please sign in to comment.