Skip to content

observability-lib: pin Grafana panel IDs via PanelOptions.StableID#2241

Open
cawthorne wants to merge 9 commits into
mainfrom
feat/grafana-stable-panel-ids
Open

observability-lib: pin Grafana panel IDs via PanelOptions.StableID#2241
cawthorne wants to merge 9 commits into
mainfrom
feat/grafana-stable-panel-ids

Conversation

@cawthorne

@cawthorne cawthorne commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add StableID uint32 on PanelOptions; the builder assigns pinned IDs at build time.
  • Unpinned panels auto-increment from 1, skipping IDs already reserved by StableID panels in the same dashboard.
  • Remove title-based pinning (WithStablePanelIDs, ApplyStablePanelIDs); consumers set StableID at panel definition.
  • Add PanelIDByTitle for deploy-time alert annotation lookups (top-level panels and panels inside row containers).

Design notes

  • Use high ID blocks (e.g. 20100+) for pinned panels so they stay clear of auto-increment.
  • Build() rejects duplicate panel IDs (duplicate StableID values or collisions with auto-assigned IDs).
  • Auto-increment does not advance the counter for pinned panels, but skips reserved stable slots.

Consumer follow-up (after merge)

  • chainlink-data-feeds: set StableID on vm-alerts-linked panels, remove post-build title patching, bump observability-lib.

Test plan

  • go test ./observability-lib/grafana/...

Pin panel IDs by title after dashboard build so vm-alerts detail_panel_id and viewPanel deep links stay stable across regenerations.
@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

✅ API Diff Results - github.com/smartcontractkit/chainlink-common/observability-lib

✅ Compatible Changes (13)

grafana (1)
  • PanelIDByTitle — ➕ Added
grafana.BarGaugePanelOptions (1)
  • StableID — ➕ Added
grafana.BusinessVariablePanelOptions (1)
  • StableID — ➕ Added
grafana.GaugePanelOptions (1)
  • StableID — ➕ Added
grafana.HeatmapPanelOptions (1)
  • StableID — ➕ Added
grafana.HistogramPanelOptions (1)
  • StableID — ➕ Added
grafana.LogPanelOptions (1)
  • StableID — ➕ Added
grafana.PanelOptions (1)
  • StableID — ➕ Added
grafana.PolystatPanelOptions (1)
  • StableID — ➕ Added
grafana.StatPanelOptions (1)
  • StableID — ➕ Added
grafana.TablePanelOptions (1)
  • StableID — ➕ Added
grafana.TextPanelOptions (1)
  • StableID — ➕ Added
grafana.TimeSeriesPanelOptions (1)
  • StableID — ➕ Added

📄 View full apidiff report

@cawthorne cawthorne changed the title observability-lib: stable Grafana panel IDs by title observability-lib: stable Grafana panel IDs via PanelOptions.StableID Jul 13, 2026
Pin IDs at panel definition via StableID while keeping title-based
ApplyStablePanelIDs and WithStablePanelIDs as legacy fallbacks.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 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.
@cawthorne
cawthorne marked this pull request as ready for review July 13, 2026 11:28
@cawthorne
cawthorne requested a review from a team as a code owner July 13, 2026 11:28
Copilot AI review requested due to automatic review settings July 13, 2026 11:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.StableID and 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 StableID when 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.

Comment thread observability-lib/grafana/builder.go Outdated
Comment thread observability-lib/grafana/panel_ids.go Outdated
Comment on lines +7 to +8
// 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.
@cawthorne cawthorne changed the title observability-lib: stable Grafana panel IDs via PanelOptions.StableID observability-lib: pin Grafana panel IDs via PanelOptions.StableID Jul 13, 2026
@cawthorne
cawthorne force-pushed the feat/grafana-stable-panel-ids branch from 991734f to d485dbf Compare July 13, 2026 12:01
Track assigned StableID and auto-increment IDs and return an error when
two panels would share the same Grafana panel ID.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants