Repository navigation
feat: add a reusable workflow to sync Grafana dashboards - #94
Merged
Merged
Conversation
WHY: A repository can keep Grafana dashboard JSON files, but no workflow sends them to Grafana. Each dashboard change needs a manual step in the Grafana UI or a manual Terraform apply. If a person forgets that step, the dashboard in Grafana and the file in git do not agree. HOW: - Add `sync-grafana-dashboards.yaml`. The caller gives the directory of the dashboard files (`dashboards_path`), the Grafana folder (`folder_uid`) and a service account token. - On a push, find the JSON files under `dashboards_path` that the push added or changed. If there are no such files, skip the push step. Thus a caller can add the job to a main workflow that runs on each push. - On a manual run, or on a push that has no previous commit, send all the dashboards under the path. - Send each file to `POST /api/dashboards/db` with `overwrite: true`. Each dashboard must have a fixed `uid`. The workflow then updates the dashboard and does not make a copy. A file without a `uid` causes the job to fail. - Check out with `fetch-depth: 0` and `filter: blob:none`. The diff against the previous push commit needs the history, but not the file contents. - To sync dashboards from more than one directory, call the workflow one time for each directory. ADDITIONAL NOTES: A deleted file does not delete the dashboard in Grafana. The workflow does not keep edits from the Grafana UI. The next push of the file replaces them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
sync-grafana-dashboards.yaml, a reusable workflow that pushes Grafana dashboard JSON files from the calling repository to Grafana through the dashboards API..jsonfiles underdashboards_paththat the push added or changed. If nothing under the path changed, the push step is skipped, so the job can sit in an existing main workflow without apaths:filter.workflow_dispatch, or on a push with no previous commit, it sends every dashboard under the path.uid. A file without one fails the job, because Grafana would otherwise create a new copy on each push.Usage
Call it once per dashboard directory. Each call can target its own Grafana folder.
The token is a Grafana service account token with
dashboards:writeon the target folder.grafana_urldefaults tohttps://grafana.propellerheads.xyz.Testing
actionlint,zizmorandshellcheckreport nothing. I ran both steps locally against a scratch repository and againstgrafana.propellerheads.xyz, using a separate test dashboard (tycho-router-trades-ci-testin thetmpfolder):count=0, push step skippedbeforeSHA, orworkflow_dispatchdashboards_pathdoes not existuid🤖 Generated with Claude Code