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:
@@ -81,35 +81,35 @@ func TestGetDefaultDSInstanceSettings(t *testing.T) {
|
||||
{
|
||||
name: "no default datasource",
|
||||
datasources: []schemaversion.DataSourceInfo{
|
||||
{UID: "ds1", Type: "prometheus", Name: "DS1", Default: false},
|
||||
{UID: "ds2", Type: "elasticsearch", Name: "DS2", Default: false},
|
||||
{UID: "existing-ref-uid", Type: "prometheus", Name: "Existing Ref Name", Default: false},
|
||||
{UID: "existing-target-uid", Type: "elasticsearch", Name: "Existing Target Name", Default: false},
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
name: "single default datasource",
|
||||
datasources: []schemaversion.DataSourceInfo{
|
||||
{UID: "ds1", Type: "prometheus", Name: "DS1", Default: false},
|
||||
{UID: "default-ds", Type: "prometheus", Name: "Default", Default: true, APIVersion: "v1"},
|
||||
{UID: "ds2", Type: "elasticsearch", Name: "DS2", Default: false},
|
||||
{UID: "existing-ref-uid", Type: "prometheus", Name: "Existing Ref Name", Default: false},
|
||||
{UID: "default-ds-uid", Type: "prometheus", Name: "Default Test Datasource Name", Default: true, APIVersion: "v1"},
|
||||
{UID: "existing-target-uid", Type: "elasticsearch", Name: "Existing Target Name", Default: false},
|
||||
},
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "default-ds",
|
||||
UID: "default-ds-uid",
|
||||
Type: "prometheus",
|
||||
Name: "Default",
|
||||
Name: "Default Test Datasource Name",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multiple default datasources returns first",
|
||||
datasources: []schemaversion.DataSourceInfo{
|
||||
{UID: "ds1", Type: "prometheus", Name: "Default1", Default: true, APIVersion: "v1"},
|
||||
{UID: "ds2", Type: "elasticsearch", Name: "Default2", Default: true, APIVersion: "v2"},
|
||||
{UID: "first-default", Type: "prometheus", Name: "First Default", Default: true, APIVersion: "v1"},
|
||||
{UID: "second-default", Type: "elasticsearch", Name: "Second Default", Default: true, APIVersion: "v2"},
|
||||
},
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "ds1",
|
||||
UID: "first-default",
|
||||
Type: "prometheus",
|
||||
Name: "Default1",
|
||||
Name: "First Default",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
},
|
||||
@@ -125,9 +125,9 @@ func TestGetDefaultDSInstanceSettings(t *testing.T) {
|
||||
|
||||
func TestGetInstanceSettings(t *testing.T) {
|
||||
datasources := []schemaversion.DataSourceInfo{
|
||||
{UID: "default-ds", Type: "prometheus", Name: "Default", Default: true, APIVersion: "v1"},
|
||||
{UID: "other-ds", Type: "elasticsearch", Name: "Elasticsearch", Default: false, APIVersion: "v2"},
|
||||
{UID: "test-uid", Type: "influxdb", Name: "InfluxDB", Default: false},
|
||||
{UID: "default-ds-uid", Type: "prometheus", Name: "Default Test Datasource Name", Default: true, APIVersion: "v1"},
|
||||
{UID: "existing-target-uid", Type: "elasticsearch", Name: "Existing Target Name", Default: false, APIVersion: "v2"},
|
||||
{UID: "existing-ref-uid", Type: "prometheus", Name: "Existing Ref Name", Default: false, APIVersion: "v1"},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -139,9 +139,9 @@ func TestGetInstanceSettings(t *testing.T) {
|
||||
name: "nil should return default",
|
||||
nameOrRef: nil,
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "default-ds",
|
||||
UID: "default-ds-uid",
|
||||
Type: "prometheus",
|
||||
Name: "Default",
|
||||
Name: "Default Test Datasource Name",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
},
|
||||
@@ -149,51 +149,51 @@ func TestGetInstanceSettings(t *testing.T) {
|
||||
name: "default string should return default",
|
||||
nameOrRef: "default",
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "default-ds",
|
||||
UID: "default-ds-uid",
|
||||
Type: "prometheus",
|
||||
Name: "Default",
|
||||
Name: "Default Test Datasource Name",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "lookup by UID",
|
||||
nameOrRef: "other-ds",
|
||||
nameOrRef: "existing-target-uid",
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "other-ds",
|
||||
UID: "existing-target-uid",
|
||||
Type: "elasticsearch",
|
||||
Name: "Elasticsearch",
|
||||
Name: "Existing Target Name",
|
||||
APIVersion: "v2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "lookup by name",
|
||||
nameOrRef: "Elasticsearch",
|
||||
nameOrRef: "Existing Target Name",
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "other-ds",
|
||||
UID: "existing-target-uid",
|
||||
Type: "elasticsearch",
|
||||
Name: "Elasticsearch",
|
||||
Name: "Existing Target Name",
|
||||
APIVersion: "v2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "lookup by UID without apiVersion",
|
||||
nameOrRef: "test-uid",
|
||||
nameOrRef: "existing-ref-uid",
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "test-uid",
|
||||
Type: "influxdb",
|
||||
Name: "InfluxDB",
|
||||
APIVersion: "",
|
||||
UID: "existing-ref-uid",
|
||||
Type: "prometheus",
|
||||
Name: "Existing Ref Name",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "lookup by reference object with UID",
|
||||
nameOrRef: map[string]interface{}{
|
||||
"uid": "other-ds",
|
||||
"uid": "existing-target-uid",
|
||||
},
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "other-ds",
|
||||
UID: "existing-target-uid",
|
||||
Type: "elasticsearch",
|
||||
Name: "Elasticsearch",
|
||||
Name: "Existing Target Name",
|
||||
APIVersion: "v2",
|
||||
},
|
||||
},
|
||||
@@ -203,39 +203,29 @@ func TestGetInstanceSettings(t *testing.T) {
|
||||
"type": "prometheus",
|
||||
},
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "default-ds",
|
||||
UID: "default-ds-uid",
|
||||
Type: "prometheus",
|
||||
Name: "Default",
|
||||
Name: "Default Test Datasource Name",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unknown datasource should return default",
|
||||
name: "unknown datasource should return nil",
|
||||
nameOrRef: "unknown-ds",
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "default-ds",
|
||||
Type: "prometheus",
|
||||
Name: "Default",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
name: "empty string should return default",
|
||||
name: "empty string should return nil",
|
||||
nameOrRef: "",
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "default-ds",
|
||||
Type: "prometheus",
|
||||
Name: "Default",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
name: "unsupported input type should return default",
|
||||
nameOrRef: 123,
|
||||
expected: &schemaversion.DataSourceInfo{
|
||||
UID: "default-ds",
|
||||
UID: "default-ds-uid",
|
||||
Type: "prometheus",
|
||||
Name: "Default",
|
||||
Name: "Default Test Datasource Name",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
},
|
||||
@@ -251,9 +241,9 @@ func TestGetInstanceSettings(t *testing.T) {
|
||||
|
||||
func TestMigrateDatasourceNameToRef(t *testing.T) {
|
||||
datasources := []schemaversion.DataSourceInfo{
|
||||
{UID: "default-ds", Type: "prometheus", Name: "Default", Default: true, APIVersion: "v1"},
|
||||
{UID: "other-ds", Type: "elasticsearch", Name: "Elasticsearch", Default: false, APIVersion: "v2"},
|
||||
{UID: "test-uid", Type: "influxdb", Name: "InfluxDB", Default: false},
|
||||
{UID: "default-ds-uid", Type: "prometheus", Name: "Default Test Datasource Name", Default: true, APIVersion: "v1"},
|
||||
{UID: "existing-target-uid", Type: "elasticsearch", Name: "Existing Target Name", Default: false, APIVersion: "v2"},
|
||||
{UID: "existing-ref-uid", Type: "prometheus", Name: "Existing Ref Name", Default: false, APIVersion: "v1"},
|
||||
}
|
||||
|
||||
t.Run("returnDefaultAsNull: true", func(t *testing.T) {
|
||||
@@ -287,39 +277,33 @@ func TestMigrateDatasourceNameToRef(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "lookup by UID",
|
||||
nameOrRef: "other-ds",
|
||||
nameOrRef: "existing-target-uid",
|
||||
expected: map[string]interface{}{
|
||||
"uid": "other-ds",
|
||||
"uid": "existing-target-uid",
|
||||
"type": "elasticsearch",
|
||||
"apiVersion": "v2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "lookup by name",
|
||||
nameOrRef: "Elasticsearch",
|
||||
nameOrRef: "Existing Target Name",
|
||||
expected: map[string]interface{}{
|
||||
"uid": "other-ds",
|
||||
"uid": "existing-target-uid",
|
||||
"type": "elasticsearch",
|
||||
"apiVersion": "v2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unknown datasource should return default reference",
|
||||
name: "unknown datasource should preserve as UID",
|
||||
nameOrRef: "unknown-ds",
|
||||
expected: map[string]interface{}{
|
||||
"uid": "default-ds",
|
||||
"type": "prometheus",
|
||||
"apiVersion": "v1",
|
||||
"uid": "unknown-ds",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty string should return default reference",
|
||||
name: "empty string should return empty object",
|
||||
nameOrRef: "",
|
||||
expected: map[string]interface{}{
|
||||
"uid": "default-ds",
|
||||
"type": "prometheus",
|
||||
"apiVersion": "v1",
|
||||
},
|
||||
expected: map[string]interface{}{},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -343,7 +327,7 @@ func TestMigrateDatasourceNameToRef(t *testing.T) {
|
||||
name: "nil should return default reference",
|
||||
nameOrRef: nil,
|
||||
expected: map[string]interface{}{
|
||||
"uid": "default-ds",
|
||||
"uid": "default-ds-uid",
|
||||
"type": "prometheus",
|
||||
"apiVersion": "v1",
|
||||
},
|
||||
@@ -352,7 +336,7 @@ func TestMigrateDatasourceNameToRef(t *testing.T) {
|
||||
name: "default should return default reference",
|
||||
nameOrRef: "default",
|
||||
expected: map[string]interface{}{
|
||||
"uid": "default-ds",
|
||||
"uid": "default-ds-uid",
|
||||
"type": "prometheus",
|
||||
"apiVersion": "v1",
|
||||
},
|
||||
@@ -370,30 +354,24 @@ func TestMigrateDatasourceNameToRef(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "lookup by UID",
|
||||
nameOrRef: "other-ds",
|
||||
nameOrRef: "existing-target-uid",
|
||||
expected: map[string]interface{}{
|
||||
"uid": "other-ds",
|
||||
"uid": "existing-target-uid",
|
||||
"type": "elasticsearch",
|
||||
"apiVersion": "v2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unknown datasource should return default reference",
|
||||
name: "unknown datasource should preserve as UID",
|
||||
nameOrRef: "unknown-ds",
|
||||
expected: map[string]interface{}{
|
||||
"uid": "default-ds",
|
||||
"type": "prometheus",
|
||||
"apiVersion": "v1",
|
||||
"uid": "unknown-ds",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty string should return default reference",
|
||||
name: "empty string should return empty object",
|
||||
nameOrRef: "",
|
||||
expected: map[string]interface{}{
|
||||
"uid": "default-ds",
|
||||
"type": "prometheus",
|
||||
"apiVersion": "v1",
|
||||
},
|
||||
expected: map[string]interface{}{},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -414,7 +392,7 @@ func TestMigrateDatasourceNameToRef(t *testing.T) {
|
||||
}
|
||||
result := schemaversion.MigrateDatasourceNameToRef(nameOrRef, options, datasources)
|
||||
expected := map[string]interface{}{
|
||||
"uid": "default-ds",
|
||||
"uid": "default-ds-uid",
|
||||
"type": "prometheus",
|
||||
"apiVersion": "v1",
|
||||
}
|
||||
@@ -424,7 +402,7 @@ func TestMigrateDatasourceNameToRef(t *testing.T) {
|
||||
t.Run("integer input should return default reference", func(t *testing.T) {
|
||||
result := schemaversion.MigrateDatasourceNameToRef(123, options, datasources)
|
||||
expected := map[string]interface{}{
|
||||
"uid": "default-ds",
|
||||
"uid": "default-ds-uid",
|
||||
"type": "prometheus",
|
||||
"apiVersion": "v1",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user