Skip to content

Commit

Permalink
fix dashboards, add script to aid in validating them (project-koku#2461)
Browse files Browse the repository at this point in the history
* fix dashboards, add script to aid in validating them
* add pre-commit check
  • Loading branch information
blentz authored Oct 20, 2020
1 parent df4f391 commit 1042272
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ repos:
rev: v0.0.3
hooks:
- id: check-pipfile-lock
- repo: local
hooks:
- id: validate-dashboards
name: Validate Grafana Dashboards
description: Ensures dashboard files are valid JSON
entry: scripts/validate_dashboards.sh
language: script
pass_filenames: false
files: dashboards\/.*\.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ data:
"current": {
"selected": true,
"text": "hccm-stage",
"value": "hccm-stage",
"value": "hccm-stage"
},
"datasource": "$Datasource",
"definition": "label_values(kubernetes_namespace)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ data:
"current": {
"selected": true,
"text": "hccm-stage",
"value": "hccm-stage",
"value": "hccm-stage"
},
"datasource": "$Datasource",
"definition": "label_values(kubernetes_namespace)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ data:
"current": {
"selected": true,
"text": "hccm-stage",
"value": "hccm-stage",
"value": "hccm-stage"
},
"datasource": "$Datasource",
"definition": "label_values(redis_up, instance)",
Expand Down
2 changes: 1 addition & 1 deletion dashboards/grafana-dashboard-insights-hccm.configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3234,7 +3234,7 @@ data:
"query": "cost-management-stage, cost-management-prod",
"skipUrlSync": false,
"type": "custom"
}
},
{
"current": {
"selected": true,
Expand Down
36 changes: 36 additions & 0 deletions scripts/validate_dashboards.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
#
# Copyright 2020 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
trap handle_errors ERR

function handle_errors() {
echo "Validation failed."
exit 1
}

SCRIPT_DIR="$( pushd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
DASHBOARD_DIR="$SCRIPT_DIR/../dashboards"

OC=$(which oc)
JQ=$(which jq)

for dashboard in $(ls -1 $DASHBOARD_DIR/*.yaml); do
echo "Checking $dashboard"
$OC extract -f $dashboard --to=- | $JQ '.' > /dev/null
done

echo "Success. All files valid."

0 comments on commit 1042272

Please sign in to comment.