Pin explicit UIDs on auto-provisioned Grafana datasources - #840
Pin explicit UIDs on auto-provisioned Grafana datasources#840youzer-name wants to merge 1 commit into
Conversation
Without an explicit uid, Grafana auto-assigns one at provisioning time, which can collide or drift across restarts/reprovisioning in ways that break dashboard datasource references. Pin stable uids (pwd-influxdb-auto, pwd-sunandmoon-auto) so they stay consistent. Note: on an existing install, this changes the datasource's uid at the next Grafana restart if it previously had a different (Grafana- generated) one. Dashboards imported before this change may show "datasource not found" until re-imported, or until the panel's datasource is manually re-linked to the same-named datasource. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
jasonacox-sam
left a comment
There was a problem hiding this comment.
Good proactive fix. Pinning explicit UIDs on auto-provisioned datasources prevents collisions and drift — especially relevant with #830 (TimescaleDB) adding a Postgres-family datasource to the stack.
Both datasource files are covered:
influxdb.yml→uid: pwd-influxdb-auto✓sunandmoon-template.yml→uid: pwd-sunandmoon-auto✓
One upgrade consideration for existing users: If someone has already provisioned Grafana with auto-assigned UIDs, adding explicit UIDs here will create new datasource entries on next restart rather than updating the existing ones. Existing dashboards that reference the old auto-assigned UID would need to be re-pointed. Worth calling out in the upgrade notes when this merges — but the fix itself is correct.
— Sam 🌊
There was a problem hiding this comment.
Pull request overview
Pins stable Grafana datasource UIDs for the auto-provisioned InfluxDB and Sun/Moon datasources so dashboard panels that reference datasources by UID don’t break due to Grafana-generated UID drift or collisions.
Changes:
- Add explicit
uid: pwd-influxdb-autoto the InfluxDB provisioned datasource. - Add explicit
uid: pwd-sunandmoon-autoto the Sun/Moon provisioned datasource. - Normalize minor YAML formatting in the Sun/Moon datasource definition (
jsonData:spacing).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| grafana/sunandmoon-template.yml | Pins a fixed UID for the Sun/Moon auto-provisioned datasource to prevent UID drift/collisions. |
| grafana/provisions/datasources/influxdb.yml | Pins a fixed UID for the InfluxDB auto-provisioned datasource to keep dashboards stable across reprovisioning. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - name: InfluxDB (auto provisioned) | ||
| type: influxdb | ||
| uid: pwd-influxdb-auto |
There was a problem hiding this comment.
Valid point — and @youzer-name already flagged this in the PR description under the upgrade note. When this lands we'll make sure the RELEASE.md callout covers the re-import/re-link remediation steps for upgrading users. No code change needed here.
|
@jasonacox-sam add to release notes (unreleased) |
Document the upcoming datasource UID change and upgrade remediation steps for existing installs.
|
Added to
Committed to — Sam 🌊 |
- PWD_USER now derives as SUDO_UID:SUDO_GID (invoking user's uid and primary gid) — the exact same uid:gid convention setup.sh writes — so a restore never silently changes how an install is owned. Drops the docker-GID pairing, which was self-consistent but diverged from the rest of the project. Root-shell (UID 0) guard retained. - CQ replay now detects failures: the influx 1.x CLI prints statement errors to stdout and exits 0 regardless, so the previous exit-code check reported success even if every CREATE failed. New replay_cqs helper captures output, filters harmless 'already exists' responses, greps for ERR, and surfaces the first errors to the user. - Staging disk-space checks: restore.sh warns (with sizes and a TMPDIR override hint) if the staging filesystem can't hold ~6x the compressed archive; backup.sh aborts before copying a snapshot that won't fit (protects RAM-backed /tmp from multi-GB datasets, cron-safe: no prompt). - Docs: README large-dataset/TMPDIR note, updated restore step list, RELEASE.md v5.3.0 entry updated to match final behavior (also folds in the previously-unreleased jasonacox#840 datasource UID note post-rebase).
|
Sorry, I've been terribly busy. I'm trying to close out some of these but I'm having heartburn over this one. The golden rule has been "no breaking changes" and we have gone out of our way to help with that. As @youzer-name mentions this woudl impact our entire install base, require them to re-import the dashboard, which is not a standard pattern most people follow (even if the upgrade script mentions it) since most people quickly customize their dashboard. I appreciate the PR and the point is valid, but we do not see this a prevalent issue or it would have surfaced in issues long before now. If there is a way to make this non-breaking, or as an opt-in change, then I would support it. Otherwise, I think we stick with the golden rule. |
|
@jasonacox — agreed, the breaking concern is real. I checked the dashboard JSONs and they contain hardcoded Grafana-generated UIDs ( Two paths forward:
I'd lean toward option 1 if @youzer-name is willing to take it on — it's a meaningful improvement that makes the dashboards more portable. But if the scope is too much for this PR, closing is the right call. Either way, I'll revert the |
|
@jasonacox-sam The issue is that most people don't replace (or re-install) their dashboard.json during an upgrade because they highly customize them but still want to upgrade the underlying code (pypowerwall proxy server version and any tweaks). Changing the dashboards may still be a good idea but won't help make this a non-breaking change unless I'm missing something. |
The datasource UID pinning change is a breaking change for existing installs. Removing the unreleased section until a non-breaking path is identified.
|
You're right — I was wrong about option 1. Updating the dashboard JSONs in the repo doesn't help if users don't re-import them, and most don't because they've customized their layouts. The fundamental problem: on an existing install, Grafana already created datasource entries with auto-generated UIDs. Users' dashboards (customized or not) reference those UIDs in every panel. If we pin new UIDs in the provisioning YAML, Grafana updates the datasource entries on next restart — and every panel referencing the old UID goes dark. There's no way to patch that from the repo side without touching each user's grafana.db directly. The only path to non-breaking I can think of would be a migration step in Given that this hasn't surfaced as a real problem in issues, I agree with sticking to the golden rule. Recommend closing #840. I've also reverted the unreleased RELEASE.md entry I added earlier. — Sam 🌊 |
- PWD_USER now derives as SUDO_UID:SUDO_GID (invoking user's uid and primary gid) — the exact same uid:gid convention setup.sh writes — so a restore never silently changes how an install is owned. Drops the docker-GID pairing, which was self-consistent but diverged from the rest of the project. Root-shell (UID 0) guard retained. - CQ replay now detects failures: the influx 1.x CLI prints statement errors to stdout and exits 0 regardless, so the previous exit-code check reported success even if every CREATE failed. New replay_cqs helper captures output, filters harmless 'already exists' responses, greps for ERR, and surfaces the first errors to the user. - Staging disk-space checks: restore.sh warns (with sizes and a TMPDIR override hint) if the staging filesystem can't hold ~6x the compressed archive; backup.sh aborts before copying a snapshot that won't fit (protects RAM-backed /tmp from multi-GB datasets, cron-safe: no prompt). - Docs: README large-dataset/TMPDIR note, updated restore step list, RELEASE.md v5.3.0 entry updated to match final behavior (also folds in the previously-unreleased jasonacox#840 datasource UID note post-rebase).
|
Holding this for now. |
Summary
uid: pwd-influxdb-autotografana/provisions/datasources/influxdb.ymlanduid: pwd-sunandmoon-autotografana/sunandmoon-template.yml.uid, Grafana auto-assigns one at provisioning time. That can collide (e.g. when a second auto-provisioned Postgres-family datasource is added elsewhere in the stack) or drift across restarts/reprovisioning, breaking dashboard panels that reference a datasource by UID.This is a breaking change for existing installs: on next Grafana restart after upgrading, these datasources will get the new pinned UID if they previously had a different Grafana-generated one. Dashboards imported before this change may show "datasource not found" on affected panels until either:
Worth a callout in the release notes for whatever version this lands in, so upgrading users aren't surprised. Happy to draft that note if useful — didn't want to presume the versioning/release process by editing
RELEASE.md/VERSIONmyself.Test plan
yaml.safe_load) on both changed filessetup.shrun, and that existing dashboards can be re-linked without issue