-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Dashboards API: Add v2alpha2 #108121
Conversation
59fdc18
to
3d7cdbe
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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:
- I take the
in
- I modify only the properties that have changed between versions
- I keep the rest unmodified and return everything as
out
.
Do we have any examples of this? Can you provide guidance?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
}
There was a problem hiding this 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.
@dprokop @radiohead I applied the feedback. I moved to the bottom the v2alpha2 until is ready :) |
* 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]>
Related reverts:
This PR bings
v2alpha2
dashboards API to enable conversion of data source representation changed in the mentioned reverts.