Skip to content

Dashboards API: Add v2alpha2 #108121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 16, 2025
Merged

Dashboards API: Add v2alpha2 #108121

merged 5 commits into from
Jul 16, 2025

Conversation

dprokop
Copy link
Collaborator

@dprokop dprokop commented Jul 15, 2025

Related reverts:

This PR bings v2alpha2 dashboards API to enable conversion of data source representation changed in the mentioned reverts.

@dprokop dprokop requested review from a team as code owners July 15, 2025 12:58
@dprokop dprokop requested review from radiohead, samsch, eledobleefe, hugohaggmark, bfmatei and kaydelaney and removed request for a team July 15, 2025 12:58
@github-actions github-actions bot added this to the 12.1.x milestone Jul 15, 2025
@dprokop dprokop added no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes labels Jul 15, 2025
@dprokop dprokop force-pushed the schemav2-api-v2alpha2 branch from 59fdc18 to 3d7cdbe Compare July 15, 2025 14:36
Copy link
Contributor

@ivanortegaalba ivanortegaalba left a comment

Choose a reason for hiding this comment

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

I tested the endpoint, and it works as expected.

I couldn't find a way to make it work, just returning whatever is stored, but I coudn't 😓

Ready to merge from my side!

func Convert_V2alpha1_to_V2alpha2(in *dashv2alpha1.Dashboard, out *dashv2alpha2.Dashboard, scope conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta

// TODO: implement V2alpha1 to V2alpha2 conversion
Copy link
Contributor

Choose a reason for hiding this comment

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

I tested locally using the client to access the new endpoint, and it redirects (making some UI changes) and works well.

I played around a bit here, and I couldn't find a way to assign in to out. I guess it doesn't make sense because they are two different types, but they are 100% equivalent.

I tried several things: marshalling/unmarshalling, scope.Convert() (I got something like converting (v2alpha1.DashboardSpec) to (v2alpha2.DashboardSpec): unknown conversion), etc. I couldn’t figure out how to do a proper conversion here.

We will probably need help to write a migration properly:

  1. I take the in
  2. I modify only the properties that have changed between versions
  3. I keep the rest unmodified and return everything as out.

Do we have any examples of this? Can you provide guidance?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

send help, @grafana/grafana-app-platform-squad :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@ivanortegaalba so, out is going to be empty here, you'll need to manually fill it in, based on the data that's contained in in.

Unfortunately it'll require a lot of manual code, that's just how Go types work. I've put a few minutes into it and got to this result:

func Convert_V2alpha1_to_V2alpha2(in *dashv2alpha1.Dashboard, out *dashv2alpha2.Dashboard, scope conversion.Scope) error {
	out.ObjectMeta = in.ObjectMeta

	// TODO: implement V2alpha1 to V2alpha2 conversion

	// Convert scalar values
	out.Spec = dashv2alpha2.DashboardSpec{
		CursorSync:  dashv2alpha2.DashboardDashboardCursorSync(in.Spec.CursorSync),
		Description: in.Spec.Description,
		Editable:    in.Spec.Editable,
		LiveNow:     in.Spec.LiveNow,
		Preload:     in.Spec.Preload,
		Revision:    in.Spec.Revision,
		Tags:        in.Spec.Tags,
		TimeSettings: dashv2alpha2.DashboardTimeSettingsSpec{
			Timezone:             in.Spec.TimeSettings.Timezone,
			From:                 in.Spec.TimeSettings.From,
			To:                   in.Spec.TimeSettings.To,
			AutoRefresh:          in.Spec.TimeSettings.AutoRefresh,
			AutoRefreshIntervals: in.Spec.TimeSettings.AutoRefreshIntervals,
			// TODO: convert quick ranges
			// QuickRanges:          in.Spec.TimeSettings.QuickRanges,
			HideTimepicker: in.Spec.TimeSettings.HideTimepicker,
			// TODO: convert week start
			// WeekStart:            in.Spec.TimeSettings.WeekStart,
			FiscalYearStartMonth: in.Spec.TimeSettings.FiscalYearStartMonth,
			NowDelay:             in.Spec.TimeSettings.NowDelay,
		},
		Title: in.Spec.Title,
	}

	// TODO: convert annotations

	// Convert elements
	out.Spec.Elements = make(map[string]dashv2alpha2.DashboardElement, len(in.Spec.Elements))
	for k, v := range in.Spec.Elements {
		el := dashv2alpha2.DashboardElement{}

		if v.PanelKind != nil {
			el.PanelKind = &dashv2alpha2.DashboardPanelKind{
				Kind: v.PanelKind.Kind,
				Spec: dashv2alpha2.DashboardPanelSpec{
					Id:          v.PanelKind.Spec.Id,
					Title:       v.PanelKind.Spec.Title,
					Description: v.PanelKind.Spec.Description,
					Transparent: v.PanelKind.Spec.Transparent,
					// TODO: make links, data, vizConfig, etc.
					// Links:       make([]dashv2alpha2.DashboardDataLink, len(v.PanelKind.Spec.Links)),
					// Data:        *v.PanelKind.Spec.Data,
					// VizConfig:   *v.PanelKind.Spec.VizConfig,
				},
			}
		}
		if v.LibraryPanelKind != nil {
			// TODO: implement library panel conversion
		}
		out.Spec.Elements[k] = el
	}

	// TODO: convert links
	// TODO: convert variables

	out.Status = dashv2alpha2.DashboardStatus{
		Conversion: &dashv2alpha2.DashboardConversionStatus{
			StoredVersion: dashv2alpha1.VERSION,
			Failed:        true,
			Error:         "backend conversion not yet implemented",
		},
	}

	return nil
}

Copy link
Contributor

@radiohead radiohead left a comment

Choose a reason for hiding this comment

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

Looks good, just wanted to check the API version preferences.

@ivanortegaalba
Copy link
Contributor

@dprokop @radiohead I applied the feedback. I moved to the bottom the v2alpha2 until is ready :)

@dprokop dprokop enabled auto-merge (squash) July 16, 2025 12:02
@dprokop dprokop merged commit b4738c5 into main Jul 16, 2025
113 checks passed
@dprokop dprokop deleted the schemav2-api-v2alpha2 branch July 16, 2025 12:22
harisrozajac pushed a commit that referenced this pull request Jul 16, 2025
* Dashboards API: Register v2alpha2 API

* Prepare conversion functions

* Fix test

* Move to the bottom the v2aplha2 until is ready

---------

Co-authored-by: Ivan Ortega <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend area/frontend no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants