Migrations: Compare backend and frontend outputs to ensure feature parity (#106851)
* wip: trying to understand how to get the ds info from migrator * add datasource info provider * Use DS service to fetch DS data * add more tests cases to match with migrator cases * Add snapshots * Non-existing DS * Add different DS for snapshots * fix import * Fix tests: guard against double initialization * don't use full datasource package in test * min version should be 35 * fix test * fix conversion test * Dashboards: Support schemaVersion v35 migration in backend * Dashboards: Support schemaVersion v34 migration in backend * Dashboards: Support schemaVersion v33 migration in backend * Apply suggestions from code review Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com> * Apply feedback * Remove unused parameters * Refactor to follow Go patterns * Update logic * Only write final migration result as output * Compare backend and frontend results * Improve snapshots to cover all possible use cases * Linter * wip make it consistent v33 * apply feedback * Return default when the ref cannot be found * Update apps/dashboard/pkg/migration/schemaversion/v33.go Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com> * apply feedback * Use same mocks backend/frontend * restore migrations * update snapshots * Adapt migration tests to use min versions * Ensure v40-v41 works * Ensure v39-v40 works * Simplify the naming of the files * adjust jest to new input convention * Ensure every migration v36-v41 works * Improve v38 naming * Ensure v36 migrates correctly * Skip v36 refs migrations on rows * Treat rows as frontend and ensure same results for v36 * Ensure v34 runs with the same logic than the frontend * Leave empty stadistics as valid option * ensure v33 is working as the frontend * Update tests * Undo frontend changes for legend handling * Remove filtering by version in the frontend * linter * Clean up v33 input JSON --------- Co-authored-by: Todd Treece <360020+toddtreece@users.noreply.github.com> Co-authored-by: Haris Rozajac <haris.rozajac12@gmail.com> Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
This commit is contained in:
@@ -40,9 +40,10 @@ func GetInstanceSettings(nameOrRef interface{}, datasources []DataSourceInfo) *D
|
||||
return GetDefaultDSInstanceSettings(datasources)
|
||||
}
|
||||
|
||||
// Check if it's a reference object without UID - should return default
|
||||
// Check if it's a reference object
|
||||
if ref, ok := nameOrRef.(map[string]interface{}); ok {
|
||||
if _, hasUID := ref["uid"]; !hasUID {
|
||||
// Reference object without UID should return default
|
||||
return GetDefaultDSInstanceSettings(datasources)
|
||||
}
|
||||
// It's a reference object with UID, search for matching UID
|
||||
@@ -56,7 +57,8 @@ func GetInstanceSettings(nameOrRef interface{}, datasources []DataSourceInfo) *D
|
||||
}
|
||||
}
|
||||
}
|
||||
return GetDefaultDSInstanceSettings(datasources)
|
||||
// Unknown UID-only reference should return nil (preserve it)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check if it's a string
|
||||
@@ -76,7 +78,7 @@ func GetInstanceSettings(nameOrRef interface{}, datasources []DataSourceInfo) *D
|
||||
}
|
||||
}
|
||||
}
|
||||
return GetDefaultDSInstanceSettings(datasources)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MigrateDatasourceNameToRef converts a datasource name/uid string to a reference object
|
||||
@@ -100,7 +102,13 @@ func MigrateDatasourceNameToRef(nameOrRef interface{}, options map[string]bool,
|
||||
return GetDataSourceRef(ds)
|
||||
}
|
||||
|
||||
if dsName, ok := nameOrRef.(string); ok && dsName != "" {
|
||||
// Handle string cases (including empty strings)
|
||||
if dsName, ok := nameOrRef.(string); ok {
|
||||
if dsName == "" {
|
||||
// Empty string should return empty object (frontend behavior)
|
||||
return map[string]interface{}{}
|
||||
}
|
||||
// Unknown datasource name should be preserved as UID-only reference
|
||||
return map[string]interface{}{
|
||||
"uid": dsName,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user