Skip to content

Commit a479041

Browse files
[ONPREM-2094] Add custom dashboard linting and validation (#41)
* Enable strict dashboard linting with some exclusions * Add script to validate and update dashboards * Helm ignore .lint
1 parent 35c5615 commit a479041

File tree

7 files changed

+101
-24
lines changed

7 files changed

+101
-24
lines changed

.circleci/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ jobs:
6868
steps:
6969
- checkout
7070
- run: ./do lint-dashboards
71+
- run: ./do validate-dashboards
72+
- run:
73+
name: Dashboards failed linting or validation
74+
command: |
75+
echo "Please refer to the documentation here:"
76+
echo "https://github.com/circleci-public/circleci-server-monitoring-reference?tab=readme-ov-file#8-modifying-or-adding-grafana-dashboards"
77+
exit 1
78+
when: on_fail
7179
- notify_failing_main
7280

7381
unit-tests:

.helmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
.circleci/
2727
bin/
2828
do
29+
dashboards/.lint
2930
docs/
3031
renovate.json5
3132
tests/

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,24 @@ The default dashboards are located in the `dashboards` directory of the referenc
128128

129129
Dashboards are provisioned directly from CRDs, which means any manual edits will be lost upon a refresh. As such, the workflow outlined below is recommended for making changes:
130130

131-
1. Create a copy of the dashboard by selecting **Edit** in the upper right corner, then **Save dashboard** -> **Save as copy**. After saving, navigate to the copy.
132-
2. Make your edits to the copy and exit edit mode.
133-
3. Select **Export** in the upper right corner and then **Export as JSON**. **Ensure that `Export the dashboard to use in another instance` is toggled on.**
134-
4. Download the file and replace the `./dashboards/server-slis.json` file with the updated copy. Ensure to update the title and UID of the updated dashboard to match the original:
135-
```json
136-
{
137-
"title": "Server SLIs",
138-
"uid": "beg3u6ond4ydcb"
139-
}
140-
```
141-
5. Commit the result and open a PR for the On-Prem team to review.
131+
1. **Create a Copy**:
132+
- Select **Edit** in the upper right corner.
133+
- Choose **Save dashboard** -> **Save as copy**.
134+
- After saving, navigate to the copy.
135+
2. **Make Edits**:
136+
- Modify the copy as needed and exit edit mode.
137+
3. **Export as JSON**:
138+
- Select **Export** in the upper right corner and then **Export as JSON**.
139+
- **Ensure that `Export the dashboard to use in another instance` is toggled on.**
140+
4. **Run Validation Command**:
141+
- Download the file and replace the `./dashboards/server-slis.json` file with the updated copy.
142+
- Run the following command to automatically validate the JSON and apply necessary updates:
143+
```bash
144+
./do validate-dashboards
145+
```
146+
5. **Commit and Open a PR**:
147+
- Review and commit the changes.
148+
- Open a pull request for the On-Prem team to review.
142149

143150
## Values
144151

README.md.gotmpl

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,24 @@ The default dashboards are located in the `dashboards` directory of the referenc
122122

123123
Dashboards are provisioned directly from CRDs, which means any manual edits will be lost upon a refresh. As such, the workflow outlined below is recommended for making changes:
124124

125-
1. Create a copy of the dashboard by selecting **Edit** in the upper right corner, then **Save dashboard** -> **Save as copy**. After saving, navigate to the copy.
126-
2. Make your edits to the copy and exit edit mode.
127-
3. Select **Export** in the upper right corner and then **Export as JSON**. **Ensure that `Export the dashboard to use in another instance` is toggled on.**
128-
4. Download the file and replace the `./dashboards/server-slis.json` file with the updated copy. Ensure to update the title and UID of the updated dashboard to match the original:
129-
```json
130-
{
131-
"title": "Server SLIs",
132-
"uid": "beg3u6ond4ydcb"
133-
}
134-
```
135-
5. Commit the result and open a PR for the On-Prem team to review.
125+
1. **Create a Copy**:
126+
- Select **Edit** in the upper right corner.
127+
- Choose **Save dashboard** -> **Save as copy**.
128+
- After saving, navigate to the copy.
129+
2. **Make Edits**:
130+
- Modify the copy as needed and exit edit mode.
131+
3. **Export as JSON**:
132+
- Select **Export** in the upper right corner and then **Export as JSON**.
133+
- **Ensure that `Export the dashboard to use in another instance` is toggled on.**
134+
4. **Run Validation Command**:
135+
- Download the file and replace the `./dashboards/server-slis.json` file with the updated copy.
136+
- Run the following command to automatically validate the JSON and apply necessary updates:
137+
```bash
138+
./do validate-dashboards
139+
```
140+
5. **Commit and Open a PR**:
141+
- Review and commit the changes.
142+
- Open a pull request for the On-Prem team to review.
136143

137144
{{ template "chart.valuesSection" . }}
138145

dashboards/.lint

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
exclusions:
2+
template-datasource-rule:
3+
reason: "The individual panels have a datasource."
4+
entries:
5+
- dashboard: Server SLIs
6+
panel-datasource-rule:
7+
reason: "'${DS_PROMETHEUS}' is a valid datasource."
8+
entries:
9+
- dashboard: Server SLIs
10+
panel-title-description-rule:
11+
reason: "Ideally each panel should have a description, but right now that's not the case."
12+
uneditable-dashboard:
13+
reason: "The dashboard needs to be editable in order to make copies of it."
14+
entries:
15+
- dashboard: Server SLIs

do

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@ kubeconform() {
2626

2727
# This variable is used, but shellcheck can't tell.
2828
# shellcheck disable=SC2034
29-
help_lint_dashboards="Lint the Grafana dashboards"
29+
help_lint_dashboards="Lint the Grafana dashboards using dashboard-linter."
3030
lint-dashboards() {
3131
install-go-bin "github.com/grafana/dashboard-linter@latest"
3232

33-
./bin/dashboard-linter lint dashboards/*
33+
./bin/dashboard-linter lint --strict --verbose dashboards/*
34+
}
35+
36+
# This variable is used, but shellcheck can't tell.
37+
# shellcheck disable=SC2034
38+
help_validate_dashboards="Validate the configurations of default Grafana dashboards."
39+
validate-dashboards() {
40+
bash scripts/validate_dashboards.sh
3441
}
3542

3643
# This variable is used, but shellcheck can't tell.

scripts/validate_dashboards.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
file_path="./dashboards/server-slis.json"
5+
6+
check_exported_for_external_instance() {
7+
if jq '.__inputs[] | select(.name == "DS_PROMETHEUS")' "$file_path" > /dev/null; then
8+
echo "__input 'DS_PROMETHEUS' is configured correctly."
9+
else
10+
echo "Error: '__input DS_PROMETHEUS' is missing. Ensure the dashboard is exported for an external instance."
11+
exit 1
12+
fi
13+
}
14+
15+
check_title_and_uid() {
16+
jq --arg title "Server SLIs" --arg uid "beg3u6ond4ydcb" '
17+
.title = $title |
18+
.uid = $uid
19+
' "$file_path" > "${file_path}.tmp"
20+
21+
if ! diff -q "$file_path" "${file_path}.tmp" > /dev/null; then
22+
mv "${file_path}.tmp" "$file_path"
23+
echo "Dashboard updated: title or UID was incorrect. Please commit the changes."
24+
exit 1
25+
else
26+
rm "${file_path}.tmp"
27+
echo "Dashboard title and UID are correctly set."
28+
fi
29+
}
30+
31+
check_exported_for_external_instance
32+
check_title_and_uid

0 commit comments

Comments
 (0)