394922c4c8
* migrate to v19 * migrate to v18 * Migration to be verified: v17 Convert minSpan to maxPerRow in panels * Migration to be verified: 16 Grid layout migration * Refactor v17 and v19 migrations to use shared helper functions * Migration to be verified: 15 No-op migration for schema consistency * Migration to be verified: 14 Shared crosshair to graph tooltip migration * cleanup * wip * complete migration * fix lint issues * refactor and test with minimal graph config * update tests * migrate to v12 * extract defaults outside the func * lint * lint * add missing showValues prop * migrate to v11 * migrate to v10 * add test files * update * migrate to v9 * migrate to v8 * add context and fix latest version * add context * add context * generate snapshots * v13 should be no-op * clean up * fix tests * add context * snapshots * generate snapshots * update * snapshots * wip * fix test * remove nav when cleaning up defaults * migrate to v6 * update comments * remove v28 * remove singlestat migraiton from frontend migrator because this is an automigration * remove unused function * Remove v24 table plugin logic * cleanup * remove plugin version for automigrate as it was used only in v24 and v28 that have been removed * cleanup * update snapshot * update snapshot * update snapshot * update snapshot * remove test --------- Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
542 lines
12 KiB
Go
542 lines
12 KiB
Go
package schemaversion_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
|
)
|
|
|
|
func TestV6Migration(t *testing.T) {
|
|
testCases := []migrationTestCase{
|
|
{
|
|
name: "pulldowns to annotations conversion with existing annotations",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"pulldowns": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "filtering",
|
|
"enable": true,
|
|
},
|
|
map[string]interface{}{
|
|
"type": "annotations",
|
|
"enable": true,
|
|
"annotations": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "old annotation",
|
|
"datasource": "prometheus",
|
|
"enable": true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "filter",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"pulldowns": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "filtering",
|
|
"enable": true,
|
|
},
|
|
map[string]interface{}{
|
|
"type": "annotations",
|
|
"enable": true,
|
|
"annotations": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "old annotation",
|
|
"datasource": "prometheus",
|
|
"enable": true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"annotations": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "old annotation",
|
|
"datasource": "prometheus",
|
|
"enable": true,
|
|
},
|
|
},
|
|
},
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "query",
|
|
"datasource": nil,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "pulldowns to annotations conversion with empty annotations",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"pulldowns": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "annotations",
|
|
"enable": true,
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"pulldowns": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "annotations",
|
|
"enable": true,
|
|
},
|
|
},
|
|
"annotations": map[string]interface{}{
|
|
"list": []interface{}{},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "no annotations pulldown found",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"pulldowns": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "filtering",
|
|
"enable": true,
|
|
},
|
|
map[string]interface{}{
|
|
"type": "other",
|
|
"enable": false,
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"pulldowns": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "filtering",
|
|
"enable": true,
|
|
},
|
|
map[string]interface{}{
|
|
"type": "other",
|
|
"enable": false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "no pulldowns property",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"title": "Test Dashboard",
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"title": "Test Dashboard",
|
|
},
|
|
},
|
|
{
|
|
name: "empty pulldowns array",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"pulldowns": []interface{}{},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"pulldowns": []interface{}{},
|
|
},
|
|
},
|
|
{
|
|
name: "template variables migration - filter to query type",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "filter",
|
|
},
|
|
map[string]interface{}{
|
|
"name": "metric",
|
|
"type": "query",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "query",
|
|
"datasource": nil,
|
|
},
|
|
map[string]interface{}{
|
|
"name": "metric",
|
|
"type": "query",
|
|
"datasource": nil,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "template variables migration - missing type becomes query",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "query",
|
|
"datasource": nil,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "template variables migration - existing datasource preserved",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "query",
|
|
"datasource": "prometheus",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "query",
|
|
"datasource": "prometheus",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "template variables migration - allFormat removal",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "query",
|
|
"allFormat": nil,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "query",
|
|
"datasource": nil,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "template variables migration - allFormat with value preserved",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "query",
|
|
"allFormat": "glob",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "server",
|
|
"type": "query",
|
|
"datasource": nil,
|
|
"allFormat": "glob",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "no templating property",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"title": "Test Dashboard",
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"title": "Test Dashboard",
|
|
},
|
|
},
|
|
{
|
|
name: "empty templating list",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "complex dashboard with both pulldowns and templating",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"title": "Complex Dashboard",
|
|
"pulldowns": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "filtering",
|
|
"enable": true,
|
|
},
|
|
map[string]interface{}{
|
|
"type": "annotations",
|
|
"enable": true,
|
|
"annotations": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "deployment",
|
|
"datasource": "prometheus",
|
|
"enable": true,
|
|
"iconColor": "red",
|
|
},
|
|
map[string]interface{}{
|
|
"name": "alerts",
|
|
"datasource": "loki",
|
|
"enable": false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "environment",
|
|
"type": "filter",
|
|
"allFormat": nil,
|
|
},
|
|
map[string]interface{}{
|
|
"name": "service",
|
|
"datasource": "prometheus",
|
|
"allFormat": "glob",
|
|
},
|
|
map[string]interface{}{
|
|
"name": "region",
|
|
"type": "custom",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"title": "Complex Dashboard",
|
|
"pulldowns": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "filtering",
|
|
"enable": true,
|
|
},
|
|
map[string]interface{}{
|
|
"type": "annotations",
|
|
"enable": true,
|
|
"annotations": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "deployment",
|
|
"datasource": "prometheus",
|
|
"enable": true,
|
|
"iconColor": "red",
|
|
},
|
|
map[string]interface{}{
|
|
"name": "alerts",
|
|
"datasource": "loki",
|
|
"enable": false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"annotations": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "deployment",
|
|
"datasource": "prometheus",
|
|
"enable": true,
|
|
"iconColor": "red",
|
|
},
|
|
map[string]interface{}{
|
|
"name": "alerts",
|
|
"datasource": "loki",
|
|
"enable": false,
|
|
},
|
|
},
|
|
},
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "environment",
|
|
"type": "query",
|
|
"datasource": nil,
|
|
},
|
|
map[string]interface{}{
|
|
"name": "service",
|
|
"type": "query",
|
|
"datasource": "prometheus",
|
|
"allFormat": "glob",
|
|
},
|
|
map[string]interface{}{
|
|
"name": "region",
|
|
"type": "custom",
|
|
"datasource": nil,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "invalid pulldowns structure",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"pulldowns": "invalid_structure",
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"pulldowns": "invalid_structure",
|
|
},
|
|
},
|
|
{
|
|
name: "invalid templating structure",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"templating": "invalid_structure",
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"templating": "invalid_structure",
|
|
},
|
|
},
|
|
{
|
|
name: "invalid templating list structure",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"templating": map[string]interface{}{
|
|
"list": "invalid_list",
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"templating": map[string]interface{}{
|
|
"list": "invalid_list",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "pulldown item with invalid structure",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"pulldowns": []interface{}{
|
|
"invalid_pulldown",
|
|
map[string]interface{}{
|
|
"type": "annotations",
|
|
"enable": true,
|
|
"annotations": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "valid annotation",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"pulldowns": []interface{}{
|
|
"invalid_pulldown",
|
|
map[string]interface{}{
|
|
"type": "annotations",
|
|
"enable": true,
|
|
"annotations": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "valid annotation",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"annotations": map[string]interface{}{
|
|
"list": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "valid annotation",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "template variable with invalid structure",
|
|
input: map[string]interface{}{
|
|
"schemaVersion": 5,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
"invalid_variable",
|
|
map[string]interface{}{
|
|
"name": "valid_variable",
|
|
"type": "filter",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"schemaVersion": 6,
|
|
"templating": map[string]interface{}{
|
|
"list": []interface{}{
|
|
"invalid_variable",
|
|
map[string]interface{}{
|
|
"name": "valid_variable",
|
|
"type": "query",
|
|
"datasource": nil,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
runMigrationTests(t, testCases, schemaversion.V6)
|
|
}
|