Fix dashboard migration discrepancies between backend and frontend implementations (use toEqual) (#110268)
**Highlights**
* **Single-version migrations**: add `targetVersion` to migrator & model, separate outputs, enforce exact version.
* **Datasource fixes**: include `apiVersion` in tests, empty-string → `{}`, preserve `{}` refs, drop unwanted defaults.
* **Panel defaults & nesting**: only top-level panels get defaults; preserve empty `transformations` context-aware; filter repeated panels.
* **Migration parity**
* V16: collapsed rows, grid height parsing (`px`).
* V17: omit `maxPerRow` when `minSpan=1`.
* V19–V20: cleanup defaults (`targetBlank`, style).
* V23–V24: template vars + table panel consistency.
* V28: full singlestat/stat parity, mappings & color.
* V30–V36: threshold logic, empty refs, nested targets.
* **Save-model cleanup**: replicate frontend defaults/filtering, drop null IDs, metadata, unused props.
* **Testing**: unified suites, dev dashboards (v42), full unit coverage for major migrations.
Co-authored-by: Ivan Ortega [ivanortegaalba@gmail.com](mailto:ivanortegaalba@gmail.com)
Co-authored-by: Dominik Prokop [dominik.prokop@grafana.com](mailto:dominik.prokop@grafana.com)
This commit is contained in:
co-authored by
Ivan Ortega [ivanortegaalba@gmail.com](mailto:ivanortegaalba@gmail.com)
Dominik Prokop [dominik.prokop@grafana.com](mailto:dominik.prokop@grafana.com)
parent
98fd3e8fe9
commit
a72e02f88a
@@ -47,10 +47,10 @@ import "context"
|
||||
func V18(_ context.Context, dashboard map[string]interface{}) error {
|
||||
dashboard["schemaVersion"] = 18
|
||||
|
||||
panels, ok := dashboard["panels"].([]interface{})
|
||||
if !ok {
|
||||
if !IsArray(dashboard["panels"]) {
|
||||
return nil
|
||||
}
|
||||
panels := dashboard["panels"].([]interface{})
|
||||
|
||||
for _, p := range panels {
|
||||
panel, ok := p.(map[string]interface{})
|
||||
@@ -91,12 +91,15 @@ func migrateGaugePanelOptions(panel map[string]interface{}) {
|
||||
|
||||
options["valueOptions"] = valueOptions
|
||||
|
||||
if thresholds, ok := optionsGauge["thresholds"].([]interface{}); ok && len(thresholds) > 0 {
|
||||
reversedThresholds := make([]interface{}, len(thresholds))
|
||||
for i, threshold := range thresholds {
|
||||
reversedThresholds[len(thresholds)-1-i] = threshold
|
||||
if IsArray(optionsGauge["thresholds"]) {
|
||||
thresholds := optionsGauge["thresholds"].([]interface{})
|
||||
if len(thresholds) > 0 {
|
||||
reversedThresholds := make([]interface{}, len(thresholds))
|
||||
for i, threshold := range thresholds {
|
||||
reversedThresholds[len(thresholds)-1-i] = threshold
|
||||
}
|
||||
options["thresholds"] = reversedThresholds
|
||||
}
|
||||
options["thresholds"] = reversedThresholds
|
||||
}
|
||||
|
||||
// Copy any other properties from options-gauge to options
|
||||
|
||||
Reference in New Issue
Block a user