Skip to content

Commit

Permalink
exported dashboards for sharing, created dashboard export script, upl…
Browse files Browse the repository at this point in the history
…oad dashboard github action and updated documentation (#641)

* exported dashboards for sharing

* Here, linty, you can have your newline and eat it too! :0

* removed abstract data source from export dashboards

* Added documentation for creating a universal dashboard via export

* ☜(`o´) <-- linty

* created universal dashboard script

* something really nice for you, linty... A NEW LINE!!!

* amended readme with new dashboard script

* modified script to edit just the "export for sharing manually" json

* updated readme to reflect changes to script.

* created dashboard github action

* added checks via git diff to ensure only changed files exec POST req
  • Loading branch information
ehearneRedHat authored May 16, 2024
1 parent b76633c commit 7efd1c3
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 68 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/upload-dashboards.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
10 changes: 10 additions & 0 deletions config/observability/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<JSON file>
```

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.
35 changes: 35 additions & 0 deletions config/observability/universal-dashboard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Check if an argument is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <public_file.json>"
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."
63 changes: 50 additions & 13 deletions examples/dashboards/app_developer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down Expand Up @@ -26,8 +71,8 @@
"fiscalYearStartMonth": 0,
"gnetId": 7630,
"graphTooltip": 1,
"id": 2,
"iteration": 1713209903588,
"id": null,
"iteration": 1715589343999,
"links": [],
"liveNow": false,
"panels": [
Expand Down Expand Up @@ -1229,8 +1274,8 @@
{
"current": {
"selected": false,
"text": "prometheus",
"value": "prometheus"
"text": "Kuadrant-Thanos-Hub",
"value": "Kuadrant-Thanos-Hub"
},
"hide": 0,
"includeAll": false,
Expand All @@ -1246,15 +1291,7 @@
"type": "datasource"
},
{
"current": {
"selected": true,
"text": [
"All"
],
"value": [
"$__all"
]
},
"current": {},
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
Expand Down
73 changes: 51 additions & 22 deletions examples/dashboards/business_user.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand All @@ -24,8 +69,8 @@
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 1,
"id": 3,
"iteration": 1713210122715,
"id": null,
"iteration": 1715594450345,
"links": [],
"liveNow": false,
"panels": [
Expand Down Expand Up @@ -610,8 +655,8 @@
{
"current": {
"selected": false,
"text": "prometheus",
"value": "prometheus"
"text": "Kuadrant-Thanos-Hub",
"value": "Kuadrant-Thanos-Hub"
},
"hide": 0,
"includeAll": false,
Expand All @@ -626,15 +671,7 @@
"type": "datasource"
},
{
"current": {
"selected": true,
"text": [
"All"
],
"value": [
"$__all"
]
},
"current": {},
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
Expand All @@ -658,15 +695,7 @@
"type": "query"
},
{
"current": {
"selected": true,
"text": [
"All"
],
"value": [
"$__all"
]
},
"current": {},
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
Expand Down
Loading

0 comments on commit 7efd1c3

Please sign in to comment.