diff --git a/.github/workflows/upload-dashboards.yaml b/.github/workflows/upload-dashboards.yaml new file mode 100644 index 000000000..c4e2f6784 --- /dev/null +++ b/.github/workflows/upload-dashboards.yaml @@ -0,0 +1,48 @@ +name: Upload Dashboards + +on: + push: + branches: + - main + paths: + - examples/dashboards/app_developer.json + - examples/dashboards/business_user.json + - examples/dashboards/platform_engineer.json + +jobs: + upload-dashboards: + name: Upload Dashboards + runs-on: ubuntu-latest + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v2 + - name: Set changed files variable + id: changes + run: | + echo "changed_files=$(git diff --name-only HEAD^ HEAD)" >> $GITHUB_ENV + - name: Upload Dashboard + run: | + # Push new dashboard changes + + # Init variable with base64 auth + auth=$(echo -n ${{ secrets.GRAFANA_USERNAME }}:${{ secrets.GRAFANA_PASSWORD }} | base64) + + # Check and upload each dashboard if it has changed + if [[ "$changed_files" == *"examples/dashboards/app_developer.json"* ]]; then + echo "Uploading App Developer Dashboard" + curl -X POST -F "json=@./examples/dashboards/app_developer.json" -H 'Content-Type: multipart/form-data' -H "Authorization: Basic $auth" "https://www.grafana.com/api/dashboards/20970/revisions" + fi + + if [[ "$changed_files" == *"examples/dashboards/business_user.json"* ]]; then + echo "Uploading Business User Dashboard" + curl -X POST -F "json=@./examples/dashboards/business_user.json" -H 'Content-Type: multipart/form-data' -H "Authorization: Basic $auth" "https://www.grafana.com/api/dashboards/20981/revisions" + fi + + if [[ "$changed_files" == *"examples/dashboards/platform_engineer.json"* ]]; then + echo "Uploading Platform Engineer Dashboard" + curl -X POST -F "json=@./examples/dashboards/platform_engineer.json" -H 'Content-Type: multipart/form-data' -H "Authorization: Basic $auth" "https://www.grafana.com/api/dashboards/20982/revisions" + fi + env: + changed_files: ${{ env.changed_files }} diff --git a/config/observability/README.md b/config/observability/README.md index bcb038f3b..7ee86e95b 100644 --- a/config/observability/README.md +++ b/config/observability/README.md @@ -46,3 +46,13 @@ In the modal popup click **Export** and then **Save to file**. Alerting rules can be defined in [PrometheusRules](https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/alerting.md#configuring-alertmanager-in-prometheus) resources. The can be viewed in the Prometheus UI Alerts tab. Some example alerting rules are available in the [/examples](/examples) folder. + +## Exporting a dashboard for use with Grafana Community Platform or other Grafana Instances + +Following the steps in [Editing dashboards](#editing-dashboards), we need to make one export where the toggle "Export for sharing manually" is toggled. Once this is saved, run the following from `config/observability` . + +```bash +universal-dashboard.sh <"Export for sharing manually" JSON file> /path/to/ +``` + +Now, you have a universal dashboard file you can use to import into your Grafana instance, but also use for uploading to the Grafana Community Platform. diff --git a/config/observability/universal-dashboard.sh b/config/observability/universal-dashboard.sh new file mode 100755 index 000000000..28f7d52e4 --- /dev/null +++ b/config/observability/universal-dashboard.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Check if an argument is provided +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Assign provided argument to a variable +public_file="$1" + +# Check if the provided file exists +if [ ! -f "$public_file" ]; then + echo "$public_file does not exist." + exit 1 +fi + +# Load data from the public file +public_data=$(<"$public_file") + +# Extract __inputs.name field and assign to name variable +name=$(echo "$public_data" | jq -r '.__inputs[0].name') +# Encase name variable with ${} so jq can match it. +name=$'${'$name'}' + +# Remove the __inputs and __elements fields using jq +updated_data=$(echo "$public_data" | jq 'del(.__inputs, .__elements)') + +# Update the uid attribute content to ${datasource} +updated_data=$(echo "$updated_data" | jq --arg old_value $name 'walk(if type == "string" and . == $old_value then "${datasource}" else . end)') + +# Write the updated data back to the public file +echo "$updated_data" > $public_file + +echo "File $public_file has been updated successfully." diff --git a/examples/dashboards/app_developer.json b/examples/dashboards/app_developer.json index d7780b0ba..b38189162 100644 --- a/examples/dashboards/app_developer.json +++ b/examples/dashboards/app_developer.json @@ -1,4 +1,49 @@ { + "__elements": [], + "__requires": [ + { + "type": "panel", + "id": "dashlist", + "name": "Dashboard list", + "version": "" + }, + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "8.5.5" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "table", + "name": "Table", + "version": "" + }, + { + "type": "panel", + "id": "text", + "name": "Text", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], "annotations": { "list": [ { @@ -26,8 +71,8 @@ "fiscalYearStartMonth": 0, "gnetId": 7630, "graphTooltip": 1, - "id": 2, - "iteration": 1713209903588, + "id": null, + "iteration": 1715589343999, "links": [], "liveNow": false, "panels": [ @@ -1229,8 +1274,8 @@ { "current": { "selected": false, - "text": "prometheus", - "value": "prometheus" + "text": "Kuadrant-Thanos-Hub", + "value": "Kuadrant-Thanos-Hub" }, "hide": 0, "includeAll": false, @@ -1246,15 +1291,7 @@ "type": "datasource" }, { - "current": { - "selected": true, - "text": [ - "All" - ], - "value": [ - "$__all" - ] - }, + "current": {}, "datasource": { "type": "prometheus", "uid": "${datasource}" diff --git a/examples/dashboards/business_user.json b/examples/dashboards/business_user.json index 02c5ff198..e7a9c170e 100644 --- a/examples/dashboards/business_user.json +++ b/examples/dashboards/business_user.json @@ -1,4 +1,49 @@ { + "__elements": [], + "__requires": [ + { + "type": "panel", + "id": "dashlist", + "name": "Dashboard list", + "version": "" + }, + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "8.5.5" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "state-timeline", + "name": "State timeline", + "version": "" + }, + { + "type": "panel", + "id": "table", + "name": "Table", + "version": "" + }, + { + "type": "panel", + "id": "text", + "name": "Text", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], "annotations": { "list": [ { @@ -24,8 +69,8 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 1, - "id": 3, - "iteration": 1713210122715, + "id": null, + "iteration": 1715594450345, "links": [], "liveNow": false, "panels": [ @@ -610,8 +655,8 @@ { "current": { "selected": false, - "text": "prometheus", - "value": "prometheus" + "text": "Kuadrant-Thanos-Hub", + "value": "Kuadrant-Thanos-Hub" }, "hide": 0, "includeAll": false, @@ -626,15 +671,7 @@ "type": "datasource" }, { - "current": { - "selected": true, - "text": [ - "All" - ], - "value": [ - "$__all" - ] - }, + "current": {}, "datasource": { "type": "prometheus", "uid": "${datasource}" @@ -658,15 +695,7 @@ "type": "query" }, { - "current": { - "selected": true, - "text": [ - "All" - ], - "value": [ - "$__all" - ] - }, + "current": {}, "datasource": { "type": "prometheus", "uid": "${datasource}" diff --git a/examples/dashboards/platform_engineer.json b/examples/dashboards/platform_engineer.json index bb3267ea6..5d2b95848 100644 --- a/examples/dashboards/platform_engineer.json +++ b/examples/dashboards/platform_engineer.json @@ -1,4 +1,49 @@ { + "__elements": [], + "__requires": [ + { + "type": "panel", + "id": "dashlist", + "name": "Dashboard list", + "version": "" + }, + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "8.5.5" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "table", + "name": "Table", + "version": "" + }, + { + "type": "panel", + "id": "text", + "name": "Text", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], "annotations": { "list": [ { @@ -26,8 +71,8 @@ "fiscalYearStartMonth": 0, "gnetId": 7630, "graphTooltip": 1, - "id": 7, - "iteration": 1713209154052, + "id": null, + "iteration": 1715594457566, "links": [], "liveNow": false, "panels": [ @@ -1474,7 +1519,8 @@ "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "red", @@ -1651,7 +1697,8 @@ "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "red", @@ -1794,8 +1841,8 @@ { "current": { "selected": false, - "text": "prometheus", - "value": "prometheus" + "text": "Kuadrant-Thanos-Hub", + "value": "Kuadrant-Thanos-Hub" }, "hide": 0, "includeAll": false, @@ -1810,15 +1857,7 @@ "type": "datasource" }, { - "current": { - "selected": true, - "text": [ - "All" - ], - "value": [ - "$__all" - ] - }, + "current": {}, "datasource": { "type": "prometheus", "uid": "${datasource}" @@ -1842,15 +1881,7 @@ "type": "query" }, { - "current": { - "selected": true, - "text": [ - "All" - ], - "value": [ - "$__all" - ] - }, + "current": {}, "datasource": { "type": "prometheus", "uid": "${datasource}" @@ -1874,15 +1905,7 @@ "type": "query" }, { - "current": { - "selected": true, - "text": [ - "All" - ], - "value": [ - "$__all" - ] - }, + "current": {}, "datasource": { "type": "prometheus", "uid": "${datasource}"