Files
grafana/apps/dashboard/pkg/migration/schemaversion/v39_test.go
Ivan Ortega Alba 93c14c52da 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>
2025-07-03 12:23:51 +02:00

333 lines
9.3 KiB
Go

package schemaversion_test
import (
"testing"
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
)
func TestV39(t *testing.T) {
tests := []migrationTestCase{
{
name: "comprehensive timeSeriesTable transformation migration with nested panels",
input: map[string]interface{}{
"title": "V39 TimeSeriesTable Transformation Migration Test Dashboard",
"schemaVersion": 38,
"panels": []interface{}{
// Single stat timeSeriesTable
map[string]interface{}{
"type": "table",
"title": "Panel with TimeSeriesTable Transformation - Single Stat",
"id": 1,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"refIdToStat": map[string]interface{}{
"A": "mean",
},
},
},
},
},
// Multiple stats timeSeriesTable
map[string]interface{}{
"type": "table",
"title": "Panel with TimeSeriesTable Transformation - Multiple Stats",
"id": 2,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"refIdToStat": map[string]interface{}{
"A": "mean",
"B": "max",
"C": "min",
"D": "sum",
},
},
},
},
},
// Mixed transformations
map[string]interface{}{
"type": "graph",
"title": "Panel with TimeSeriesTable Transformation - Mixed with Other Transforms",
"id": 3,
"transformations": []interface{}{
map[string]interface{}{
"id": "reduce",
"options": map[string]interface{}{
"reducers": []interface{}{"mean"},
},
},
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"refIdToStat": map[string]interface{}{
"A": "last",
"B": "first",
},
},
},
map[string]interface{}{
"id": "organize",
"options": map[string]interface{}{
"excludeByName": map[string]interface{}{},
},
},
},
},
// Non-timeSeriesTable transformation
map[string]interface{}{
"type": "stat",
"title": "Panel with Non-TimeSeriesTable Transformation (Should Remain Unchanged)",
"id": 4,
"transformations": []interface{}{
map[string]interface{}{
"id": "reduce",
"options": map[string]interface{}{
"reducers": []interface{}{"mean", "max"},
},
},
},
},
// Empty refIdToStat
map[string]interface{}{
"type": "table",
"title": "Panel with TimeSeriesTable - Empty RefIdToStat",
"id": 5,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"refIdToStat": map[string]interface{}{},
},
},
},
},
// No options (should skip)
map[string]interface{}{
"type": "table",
"title": "Panel with TimeSeriesTable - No Options (Should Skip)",
"id": 6,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
},
},
},
// Invalid options (should skip)
map[string]interface{}{
"type": "table",
"title": "Panel with TimeSeriesTable - Invalid Options (Should Skip)",
"id": 7,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"someOtherOption": "value",
},
},
},
},
// No transformations
map[string]interface{}{
"type": "graph",
"title": "Panel with No Transformations (Should Remain Unchanged)",
"id": 8,
},
// Row with nested panels
map[string]interface{}{
"type": "row",
"title": "Row with Nested Panels Having TimeSeriesTable Transformations",
"id": 9,
"collapsed": false,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"title": "Nested Panel with TimeSeriesTable",
"id": 10,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"refIdToStat": map[string]interface{}{
"NestedA": "median",
"NestedB": "stdDev",
},
},
},
},
},
},
},
},
},
expected: map[string]interface{}{
"title": "V39 TimeSeriesTable Transformation Migration Test Dashboard",
"schemaVersion": 39,
"panels": []interface{}{
// Single stat timeSeriesTable (migrated)
map[string]interface{}{
"type": "table",
"title": "Panel with TimeSeriesTable Transformation - Single Stat",
"id": 1,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"A": map[string]interface{}{
"stat": "mean",
},
},
},
},
},
// Multiple stats timeSeriesTable (migrated)
map[string]interface{}{
"type": "table",
"title": "Panel with TimeSeriesTable Transformation - Multiple Stats",
"id": 2,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"A": map[string]interface{}{
"stat": "mean",
},
"B": map[string]interface{}{
"stat": "max",
},
"C": map[string]interface{}{
"stat": "min",
},
"D": map[string]interface{}{
"stat": "sum",
},
},
},
},
},
// Mixed transformations (timeSeriesTable migrated, others unchanged)
map[string]interface{}{
"type": "graph",
"title": "Panel with TimeSeriesTable Transformation - Mixed with Other Transforms",
"id": 3,
"transformations": []interface{}{
map[string]interface{}{
"id": "reduce",
"options": map[string]interface{}{
"reducers": []interface{}{"mean"},
},
},
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"A": map[string]interface{}{
"stat": "last",
},
"B": map[string]interface{}{
"stat": "first",
},
},
},
map[string]interface{}{
"id": "organize",
"options": map[string]interface{}{
"excludeByName": map[string]interface{}{},
},
},
},
},
// Non-timeSeriesTable transformation (unchanged)
map[string]interface{}{
"type": "stat",
"title": "Panel with Non-TimeSeriesTable Transformation (Should Remain Unchanged)",
"id": 4,
"transformations": []interface{}{
map[string]interface{}{
"id": "reduce",
"options": map[string]interface{}{
"reducers": []interface{}{"mean", "max"},
},
},
},
},
// Empty refIdToStat (migrated to empty options)
map[string]interface{}{
"type": "table",
"title": "Panel with TimeSeriesTable - Empty RefIdToStat",
"id": 5,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{},
},
},
},
// No options (unchanged - should skip)
map[string]interface{}{
"type": "table",
"title": "Panel with TimeSeriesTable - No Options (Should Skip)",
"id": 6,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
},
},
},
// Invalid options (unchanged - should skip)
map[string]interface{}{
"type": "table",
"title": "Panel with TimeSeriesTable - Invalid Options (Should Skip)",
"id": 7,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"someOtherOption": "value",
},
},
},
},
// No transformations (unchanged)
map[string]interface{}{
"type": "graph",
"title": "Panel with No Transformations (Should Remain Unchanged)",
"id": 8,
},
// Row with nested panels (nested panel migrated)
map[string]interface{}{
"type": "row",
"title": "Row with Nested Panels Having TimeSeriesTable Transformations",
"id": 9,
"collapsed": false,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"title": "Nested Panel with TimeSeriesTable",
"id": 10,
"transformations": []interface{}{
map[string]interface{}{
"id": "timeSeriesTable",
"options": map[string]interface{}{
"NestedA": map[string]interface{}{
"stat": "median",
},
"NestedB": map[string]interface{}{
"stat": "stdDev",
},
},
},
},
},
},
},
},
},
},
}
runMigrationTests(t, tests, schemaversion.V39)
}