e463781077
- Implement full conversion pipeline from v1beta1 → v2beta1 - Ensure frontend–backend parity for all dashboard serialization paths - Add automatic data loss detection for conversions (panels, queries, annotations, links, variables) - Extract atomic conversion functions for v0 → v1beta1 → v2alpha1 → v2beta1 - Introduce conversion metrics and detailed logging for loss tracking - Normalize datasource resolution, defaults, and annotation processing - Improve panel layout serialization and y-coordinate normalization - Fix inconsistencies in nested panels and collapsed row behavior - Refine variable handling: - Filter refId from variable query specs - Default variable refresh to 'never' (matches frontend) - Fix constant and interval variable handling for missing queries - Unify schema defaults (enable, hide, iconColor, editable, liveNow) - Fix pluginId usage (UID vs type) and datasource references - Fix metrics.go bug swallowing errors (return nil → return err) - Add tests for version-specific conversion error handling - Add data loss detection tests using source/target version comparison - Clean up lint issues, legacy code, and redundant files - Update OpenAPI snapshots and migrated dashboards - Improve backend migrator to reuse datasource provider and match frontend logic Co-authored-by: Haris Rozajac <haris.rozajac12@gmail.com> Co-authored-by: Oscar Kilhed <oscar.kilhed@grafana.com> Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
125 lines
3.5 KiB
Go
125 lines
3.5 KiB
Go
package conversion
|
|
|
|
import (
|
|
"k8s.io/apimachinery/pkg/conversion"
|
|
"k8s.io/utils/ptr"
|
|
|
|
dashv0 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
|
|
dashv1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
|
|
dashv2alpha1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
|
|
dashv2beta1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2beta1"
|
|
)
|
|
|
|
func Convert_V2alpha1_to_V0(in *dashv2alpha1.Dashboard, out *dashv0.Dashboard, scope conversion.Scope) error {
|
|
out.ObjectMeta = in.ObjectMeta
|
|
|
|
// TODO: implement V2 to V0 conversion
|
|
|
|
out.Status = dashv0.DashboardStatus{
|
|
Conversion: &dashv0.DashboardConversionStatus{
|
|
StoredVersion: ptr.To(dashv2alpha1.VERSION),
|
|
Failed: true,
|
|
Error: ptr.To("backend conversion not yet implemented"),
|
|
Source: in,
|
|
},
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Convert_V2alpha1_to_V1beta1(in *dashv2alpha1.Dashboard, out *dashv1.Dashboard, scope conversion.Scope) error {
|
|
out.ObjectMeta = in.ObjectMeta
|
|
|
|
// TODO: implement V2 to V1 conversion
|
|
|
|
out.Status = dashv1.DashboardStatus{
|
|
Conversion: &dashv1.DashboardConversionStatus{
|
|
StoredVersion: ptr.To(dashv2alpha1.VERSION),
|
|
Failed: true,
|
|
Error: ptr.To("backend conversion not yet implemented"),
|
|
Source: in,
|
|
},
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Convert_V2alpha1_to_V2beta1(in *dashv2alpha1.Dashboard, out *dashv2beta1.Dashboard, scope conversion.Scope) error {
|
|
out.ObjectMeta = in.ObjectMeta
|
|
|
|
// Convert the spec
|
|
if err := ConvertDashboard_V2alpha1_to_V2beta1(in, out, scope); err != nil {
|
|
out.Status = dashv2beta1.DashboardStatus{
|
|
Conversion: &dashv2beta1.DashboardConversionStatus{
|
|
StoredVersion: ptr.To(dashv2alpha1.VERSION),
|
|
Failed: true,
|
|
Error: ptr.To(err.Error()),
|
|
Source: in,
|
|
},
|
|
}
|
|
|
|
return NewConversionError(err.Error(), "v2alpha1", "v2beta1", "ConvertDashboard_V2alpha1_to_V2beta1")
|
|
}
|
|
|
|
// Set successful conversion status
|
|
out.Status = dashv2beta1.DashboardStatus{
|
|
Conversion: &dashv2beta1.DashboardConversionStatus{
|
|
StoredVersion: ptr.To(dashv2alpha1.VERSION),
|
|
Failed: false,
|
|
},
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Convert_V2beta1_to_V0(in *dashv2beta1.Dashboard, out *dashv0.Dashboard, scope conversion.Scope) error {
|
|
out.ObjectMeta = in.ObjectMeta
|
|
|
|
// TODO: implement v2beta1 to V0 conversion
|
|
|
|
out.Status = dashv0.DashboardStatus{
|
|
Conversion: &dashv0.DashboardConversionStatus{
|
|
StoredVersion: ptr.To(dashv2beta1.VERSION),
|
|
Failed: true,
|
|
Error: ptr.To("backend conversion not yet implemented"),
|
|
Source: in,
|
|
},
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Convert_V2beta1_to_V1beta1(in *dashv2beta1.Dashboard, out *dashv1.Dashboard, scope conversion.Scope) error {
|
|
out.ObjectMeta = in.ObjectMeta
|
|
|
|
// TODO: implement v2beta1 to V1 conversion
|
|
|
|
out.Status = dashv1.DashboardStatus{
|
|
Conversion: &dashv1.DashboardConversionStatus{
|
|
StoredVersion: ptr.To(dashv2beta1.VERSION),
|
|
Failed: true,
|
|
Error: ptr.To("backend conversion not yet implemented"),
|
|
Source: in,
|
|
},
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Convert_V2beta1_to_V2alpha1(in *dashv2beta1.Dashboard, out *dashv2alpha1.Dashboard, scope conversion.Scope) error {
|
|
out.ObjectMeta = in.ObjectMeta
|
|
|
|
// TODO: implement v2beta1 to V2alpha1 conversion
|
|
|
|
out.Status = dashv2alpha1.DashboardStatus{
|
|
Conversion: &dashv2alpha1.DashboardConversionStatus{
|
|
StoredVersion: ptr.To(dashv2beta1.VERSION),
|
|
Failed: true,
|
|
Error: ptr.To("backend conversion not yet implemented"),
|
|
Source: in,
|
|
},
|
|
}
|
|
|
|
return nil
|
|
}
|