Grafana zero-downtime data source migration: file-based provisioning reload or HTTP API partial updates?
0 reputation · 05 Jan 2025, 18:15 UTC
0 reputation · 05 Jan 2025, 18:15 UTC
I'm planning a migration of a small Grafana instance (single node, Grafana 10.x assumed) to a new back-end data source endpoint, and the goal is to keep all dashboards queryable throughout the switch with no restart and no visible gap for viewers.
Two documented approaches seem viable, and I'm unsure which fits this constraint better. File-based provisioning supports hot-reloading of data source definitions, so updating the YAML files on disk would be picked up without restarting the server. Alternatively, the HTTP API (/api/datasources) supports partial updates, letting me swap the URL and credentials on the existing data source incrementally while keeping UIDs stable so panels don't need redeployment.
My main uncertainty is around atomicity: if credentials change at the same time as the URL, I want to avoid a window where queries hit the new endpoint with stale auth and fail transiently. I'm also unsure how the two methods interact if provisioning files and API changes both manage the same data source.
Which approach gives the cleaner cutover for a small instance — provisioned file reload or API-driven partial update? Can provisioning and API updates safely coexist on the same data source, or does one override the other? Is there a documented way to make the credential-plus-URL change atomic?
For a single‑node Grafana 10.x instance the cleanest, safest cutover is to use the /api/datasources/:id endpoint with a single PUT that replaces the entire datasource definition. The API performs the update in one transaction, so the URL and credentials change atomically and dashboards can keep querying the same UID without a visible gap.
curl -s -H "Authorization: Bearer $TOKEN" "http://grafana/api/datasources/:id" > ds.json
ds.json with the new URL and credentials.curl -s -X PUT \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $TOKEN" \ -d @ds.json \ http://grafana/api/datasources/:id
Partial field updates (e.g., only the URL) via the API are not atomic; they can leave the datasource in a half‑updated state if the request is interrupted. Always send the full JSON payload.
Do any dashboards reference the datasource via a UID that is shared with other instances (e.g., a shared datasource across multiple Grafana servers)? Knowing this will confirm whether a single‑UID update is sufficient or if a new UID path is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.