Skip to content

[FEATURE] Add panel-level annotations to the data model - #61

Draft
nicolastakashi wants to merge 1 commit into
perses:mainfrom
nicolastakashi:draft/panel-level-annotations-model
Draft

[FEATURE] Add panel-level annotations to the data model#61
nicolastakashi wants to merge 1 commit into
perses:mainfrom
nicolastakashi:draft/panel-level-annotations-model

Conversation

@nicolastakashi

Copy link
Copy Markdown

What this does

This adds an optional annotations block to PanelSpec so annotations can be set per panel. It follows the two-level annotation design being discussed in perses/perses#3001. The dashboard-level half of that design already shipped, and this PR is the data model for the panel-level half.

type PanelAnnotations struct {
    // Enabled toggles the display of dashboard-level annotations on this panel.
    // nil is treated as enabled (default on).
    Enabled     *bool
    // Definitions holds annotations defined locally on this panel, reusing AnnotationSpec.
    Definitions []AnnotationSpec
}

Enabled is a pointer so an omitted value means "on", which is the default-on behavior from the design. Definitions reuses the existing AnnotationSpec type instead of a new parallel shape.

Scope

This is the data model only. It does not touch backend validation, the frontend consumer hook, the panel editor, or Grafana migration, which I will send as separate follow-ups to keep this one small. I opened it as a draft because the shape is still under discussion on #3001, and I would rather agree on that before building the layers on top of it.

Mirrors

The Go types are the source of truth. I regenerated the CUE mirror with make cue-gen (not hand-edited) and updated the TypeScript (ts/src/dashboard/panel.ts) and Java (.../dashboard/panel/PanelSpec.java plus a new PanelAnnotations.java) mirrors by hand.

Validation

Panel-local definitions get validated without any extra code. AnnotationSpec.UnmarshalJSON already calls validate(), which requires a non-empty name, and that runs when a definition is unmarshaled inside a PanelSpec. So I did not add validation to PanelSpec itself.

Testing

go/dashboard/panel_test.go covers JSON and YAML round-trips, the default-on case when the block is omitted, and rejection of a definition with an empty name.

  • make cue-gen cue-eval: clean
  • go test ./go/...: all pass
  • gofmt -l go/: clean

One side note

Running make cue-gen on macOS hit a portability issue. The target uses GNU-style sed -i, which fails on BSD/macOS sed, so the import-path rewrite step silently does not run. I worked around it locally. I can send a small separate PR to make that sed call portable if that is useful.

Open questions

Same points I raised on #3001, repeated here for context:

  1. Is a single per-panel boolean enough for the toggle, or would you want per-annotation opt-out by name?
  2. Should panel-local Definitions be in this first iteration, or a follow-up after the toggle?
  3. Nested annotations object as done here, or two flat fields on PanelSpec?

Add an optional annotations block to PanelSpec so annotations can be configured
per panel, following the two-level annotation design discussed in
perses/perses#3001. PanelAnnotations carries an Enabled toggle for dashboard-level
annotations (nil is treated as on) and a list of panel-local Definitions that
reuse the existing AnnotationSpec type.

Regenerate the CUE mirror and update the TypeScript and Java mirrors to match.

Signed-off-by: Nicolas Takashi <nicolas.takashi@dash0.com>
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.

1 participant