observability-lib: pin Grafana panel IDs via PanelOptions.StableID#2241
observability-lib: pin Grafana panel IDs via PanelOptions.StableID#2241cawthorne wants to merge 9 commits into
Conversation
Pin panel IDs by title after dashboard build so vm-alerts detail_panel_id and viewPanel deep links stay stable across regenerations.
✅ API Diff Results -
|
Pin IDs at panel definition via StableID while keeping title-based ApplyStablePanelIDs and WithStablePanelIDs as legacy fallbacks.
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.
| Benchmark suite | Current: 612fa8c | Previous: 65ffba5 | Ratio |
|---|---|---|---|
BenchmarkKeystore_Sign/nop/out-of-process |
70492 ns/op |
27935 ns/op |
2.52 |
BenchmarkKeystore_Sign/hex/out-of-process |
71228 ns/op |
27604 ns/op |
2.58 |
BenchmarkKeystore_Sign/ed25519/out-of-process |
114594 ns/op |
52469 ns/op |
2.18 |
This comment was automatically generated by workflow using github-action-benchmark.
Stable panel IDs are assigned only via PanelOptions.StableID at build time. Remove WithStablePanelIDs, ApplyStablePanelIDs, and related title-map helpers; keep PanelIDByTitle for deploy-time lookups.
Each Builder is single-use per dashboard, and panel IDs need only be unique within that dashboard. Use StableID when set, otherwise increment.
There was a problem hiding this comment.
Pull request overview
This PR updates the Grafana dashboard builder in observability-lib to support explicitly pinned panel IDs via a new PanelOptions.StableID field, and replaces the previous title-based stable-ID mechanism with a build-time assignment approach. It also adds a helper to look up panel IDs by title (including panels nested inside rows) and wires that helper into deploy-time alert annotations.
Changes:
- Add
PanelOptions.StableIDand propagate it into built panel metadata so the builder can assign pinned IDs. - Introduce
PanelIDByTitle(and tests) to locate panel IDs by title across top-level panels and row-contained panels. - Update the builder to use
StableIDwhen present; otherwise fall back to the existing auto-incrementing ID counter.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| observability-lib/grafana/panels.go | Adds StableID to PanelOptions and attaches it to Panel instances for build-time ID selection. |
| observability-lib/grafana/panel_ids.go | Adds PanelIDByTitle helper to find panel IDs by title, traversing dashboard panels and panels inside rows. |
| observability-lib/grafana/panel_ids_test.go | Adds coverage validating stable IDs are preserved and discoverable by title. |
| observability-lib/grafana/dashboard.go | Switches deploy-time title→ID lookup to use the new PanelIDByTitle helper. |
| observability-lib/grafana/builder.go | Uses StableID when set, otherwise uses the existing auto-increment counter for panel IDs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // PanelIDByTitle returns the panel ID for a dashboard panel title, including row panels. | ||
| func PanelIDByTitle(db *dashboard.Dashboard, title string) (uint32, bool) { |
Track assigned panel IDs during build so unpinned panels advance past stable ID slots instead of colliding with them.
Use strconv.FormatUint in deploy lookup, fix test variable shadowing, and document that auto-increment skips StableID reservations.
991734f to
d485dbf
Compare
Track assigned StableID and auto-increment IDs and return an error when two panels would share the same Grafana panel ID.
Summary
StableID uint32onPanelOptions; the builder assigns pinned IDs at build time.StableIDpanels in the same dashboard.WithStablePanelIDs,ApplyStablePanelIDs); consumers setStableIDat panel definition.PanelIDByTitlefor deploy-time alert annotation lookups (top-level panels and panels inside row containers).Design notes
20100+) for pinned panels so they stay clear of auto-increment.Build()rejects duplicate panel IDs (duplicateStableIDvalues or collisions with auto-assigned IDs).Consumer follow-up (after merge)
StableIDon vm-alerts-linked panels, remove post-build title patching, bump observability-lib.Test plan
go test ./observability-lib/grafana/...