Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tool(grafana): test/tooling to ensure dashboards are simplified/importable #264

Merged
merged 2 commits into from
Apr 24, 2024

Conversation

huntergregory
Copy link
Contributor

@huntergregory huntergregory commented Apr 15, 2024

Description

When it comes to JSON for Grafana dashboards, it seems best practice to remove a bunch of unnecessary pieces like the name of your personal datasource, current variable selection, etc. This PR:

  1. Introduces make simplify-dashboards to automate this tedious process.
  2. Adds a unit test to ensure authors run this command.

Related Issue

Checklist

  • I have read the contributing documentation.
  • I signed and signed-off the commits (git commit -S -s ...). See this documentation on signing commits.
  • I have correctly attributed the author(s) of the code.
  • I have tested the changes locally.
  • I have followed the project's style guidelines.
  • I have updated the documentation, if necessary.
  • I have added tests, if applicable.

Screenshots (if applicable) or Testing Completed

make simplify-dashboards

$ make simplify-dashboards 
cd deploy/grafana/dashboards/ && go test . -tags=dashboard,simplifydashboard -v
=== RUN   TestOverwriteDashboards
    simplify-grafana-overwrite_test.go:22: simplifying/overwriting dashboard: clusters.json
    simplify-grafana-overwrite_test.go:22: simplifying/overwriting dashboard: dns.json
    simplify-grafana-overwrite_test.go:22: simplifying/overwriting dashboard: pod-level.json
--- PASS: TestOverwriteDashboards (0.02s)
PASS
ok      github.com/microsoft/retina/deploy/grafana/dashboards   0.019s

Unit Test to Ensure Simplification

go test . -tags=dashboard -v
=== RUN   TestDashboardsAreSimplified
    simplify-grafana_test.go:24: verifying that dashboard is simplified: clusters.json
    simplify-grafana_test.go:31: ERROR: dashboard has not been simplified. Please run: make simplify-dashboards
    simplify-grafana_test.go:24: verifying that dashboard is simplified: dns.json
    simplify-grafana_test.go:24: verifying that dashboard is simplified: pod-level.json
--- FAIL: TestDashboardsAreSimplified (0.01s)
FAIL
FAIL    github.com/microsoft/retina/deploy/grafana/dashboards   0.018s
FAIL

Additional Notes

Code added in this PR is put behind the go build tag dashboard, so these files are not compiled in Retina binaries.

@huntergregory huntergregory requested a review from a team as a code owner April 15, 2024 07:01
@huntergregory huntergregory changed the title feat(grafana): test/tooling to ensure dashboards are simplified/importable tool(grafana): test/tooling to ensure dashboards are simplified/importable Apr 15, 2024
Copy link
Contributor

@snguyen64 snguyen64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this change, could you rebase and resolve conflicts first?

@huntergregory huntergregory force-pushed the huntergregory/simplify-grafana-tooling branch from e73ef47 to 1173df1 Compare April 24, 2024 20:09
@huntergregory huntergregory added this pull request to the merge queue Apr 24, 2024
Merged via the queue into main with commit f1fb3c0 Apr 24, 2024
21 checks passed
@huntergregory huntergregory deleted the huntergregory/simplify-grafana-tooling branch April 24, 2024 23:00
nddq pushed a commit that referenced this pull request May 6, 2024
…table (#264)

# Description

When it comes to JSON for Grafana dashboards, it seems best practice to
remove a bunch of unnecessary pieces like the name of your personal
datasource, current variable selection, etc. This PR:
1. Introduces `make simplify-dashboards` to automate this tedious
process.
2. Adds a unit test to ensure authors run this command.

## Related Issue

## 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

### `make simplify-dashboards`
```bash
$ make simplify-dashboards 
cd deploy/grafana/dashboards/ && go test . -tags=dashboard,simplifydashboard -v
=== RUN   TestOverwriteDashboards
    simplify-grafana-overwrite_test.go:22: simplifying/overwriting dashboard: clusters.json
    simplify-grafana-overwrite_test.go:22: simplifying/overwriting dashboard: dns.json
    simplify-grafana-overwrite_test.go:22: simplifying/overwriting dashboard: pod-level.json
--- PASS: TestOverwriteDashboards (0.02s)
PASS
ok      github.com/microsoft/retina/deploy/grafana/dashboards   0.019s
```

### Unit Test to Ensure Simplification
```bash
go test . -tags=dashboard -v
=== RUN   TestDashboardsAreSimplified
    simplify-grafana_test.go:24: verifying that dashboard is simplified: clusters.json
    simplify-grafana_test.go:31: ERROR: dashboard has not been simplified. Please run: make simplify-dashboards
    simplify-grafana_test.go:24: verifying that dashboard is simplified: dns.json
    simplify-grafana_test.go:24: verifying that dashboard is simplified: pod-level.json
--- FAIL: TestDashboardsAreSimplified (0.01s)
FAIL
FAIL    github.com/microsoft/retina/deploy/grafana/dashboards   0.018s
FAIL
```

## Additional Notes
Code added in this PR is put behind the go build tag `dashboard`, so
these files are not compiled in Retina binaries.

---------

Signed-off-by: Hunter Gregory <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/data-ingestion-and-visualization area/infra Test, Release, or CI Infrastructure
Projects
Status: Done
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants