b232a812ab
* 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 * fix test * 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 --------- Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
253 lines
6.0 KiB
Go
253 lines
6.0 KiB
Go
package schemaversion_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
|
)
|
|
|
|
func TestV8(t *testing.T) {
|
|
tests := []migrationTestCase{
|
|
{
|
|
name: "InfluxDB structured query should be converted to new select format",
|
|
input: map[string]interface{}{
|
|
"title": "V8 InfluxDB Query Migration Test Dashboard",
|
|
"schemaVersion": 7,
|
|
"panels": []interface{}{
|
|
map[string]interface{}{
|
|
"id": 1,
|
|
"targets": []interface{}{
|
|
map[string]interface{}{
|
|
"fields": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "value",
|
|
"func": "mean",
|
|
"mathExpr": "*2",
|
|
"asExpr": "doubled",
|
|
},
|
|
map[string]interface{}{
|
|
"name": "count",
|
|
"func": "sum",
|
|
},
|
|
},
|
|
"tags": []interface{}{
|
|
map[string]interface{}{
|
|
"key": "host",
|
|
"value": "server1",
|
|
},
|
|
},
|
|
"groupBy": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "time",
|
|
"interval": "1m",
|
|
},
|
|
map[string]interface{}{
|
|
"type": "tag",
|
|
"key": "host",
|
|
},
|
|
},
|
|
"fill": "null",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"title": "V8 InfluxDB Query Migration Test Dashboard",
|
|
"schemaVersion": 8,
|
|
"panels": []interface{}{
|
|
map[string]interface{}{
|
|
"id": 1,
|
|
"targets": []interface{}{
|
|
map[string]interface{}{
|
|
"select": []interface{}{
|
|
[]interface{}{
|
|
map[string]interface{}{
|
|
"type": "field",
|
|
"params": []interface{}{"value"},
|
|
},
|
|
map[string]interface{}{
|
|
"type": "mean",
|
|
"params": []interface{}{},
|
|
},
|
|
map[string]interface{}{
|
|
"type": "math",
|
|
"params": []interface{}{"*2"},
|
|
},
|
|
map[string]interface{}{
|
|
"type": "alias",
|
|
"params": []interface{}{"doubled"},
|
|
},
|
|
},
|
|
[]interface{}{
|
|
map[string]interface{}{
|
|
"type": "field",
|
|
"params": []interface{}{"count"},
|
|
},
|
|
map[string]interface{}{
|
|
"type": "sum",
|
|
"params": []interface{}{},
|
|
},
|
|
},
|
|
},
|
|
"tags": []interface{}{
|
|
map[string]interface{}{
|
|
"key": "host",
|
|
"value": "server1",
|
|
},
|
|
},
|
|
"groupBy": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "time",
|
|
"params": []interface{}{"1m"},
|
|
},
|
|
map[string]interface{}{
|
|
"type": "tag",
|
|
"params": []interface{}{"host"},
|
|
},
|
|
map[string]interface{}{
|
|
"type": "fill",
|
|
"params": []interface{}{"null"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "InfluxDB raw query should only remove fields and fill",
|
|
input: map[string]interface{}{
|
|
"title": "V8 InfluxDB Raw Query Migration Test Dashboard",
|
|
"schemaVersion": 7,
|
|
"panels": []interface{}{
|
|
map[string]interface{}{
|
|
"id": 1,
|
|
"targets": []interface{}{
|
|
map[string]interface{}{
|
|
"rawQuery": true,
|
|
"fields": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "value",
|
|
"func": "mean",
|
|
},
|
|
},
|
|
"tags": []interface{}{
|
|
map[string]interface{}{
|
|
"key": "host",
|
|
"value": "server1",
|
|
},
|
|
},
|
|
"groupBy": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "time",
|
|
"interval": "1m",
|
|
},
|
|
},
|
|
"fill": "null",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"title": "V8 InfluxDB Raw Query Migration Test Dashboard",
|
|
"schemaVersion": 8,
|
|
"panels": []interface{}{
|
|
map[string]interface{}{
|
|
"id": 1,
|
|
"targets": []interface{}{
|
|
map[string]interface{}{
|
|
"rawQuery": true,
|
|
"tags": []interface{}{
|
|
map[string]interface{}{
|
|
"key": "host",
|
|
"value": "server1",
|
|
},
|
|
},
|
|
"groupBy": []interface{}{
|
|
map[string]interface{}{
|
|
"type": "time",
|
|
"interval": "1m",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "targets without old InfluxDB schema should remain unchanged",
|
|
input: map[string]interface{}{
|
|
"title": "V8 Non-InfluxDB Target Test Dashboard",
|
|
"schemaVersion": 7,
|
|
"panels": []interface{}{
|
|
map[string]interface{}{
|
|
"id": 1,
|
|
"targets": []interface{}{
|
|
map[string]interface{}{
|
|
"expr": "up",
|
|
"refId": "A",
|
|
"format": "time_series",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"title": "V8 Non-InfluxDB Target Test Dashboard",
|
|
"schemaVersion": 8,
|
|
"panels": []interface{}{
|
|
map[string]interface{}{
|
|
"id": 1,
|
|
"targets": []interface{}{
|
|
map[string]interface{}{
|
|
"expr": "up",
|
|
"refId": "A",
|
|
"format": "time_series",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "panels without targets should remain unchanged",
|
|
input: map[string]interface{}{
|
|
"title": "V8 No Targets Test Dashboard",
|
|
"schemaVersion": 7,
|
|
"panels": []interface{}{
|
|
map[string]interface{}{
|
|
"id": 1,
|
|
"type": "text",
|
|
},
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"title": "V8 No Targets Test Dashboard",
|
|
"schemaVersion": 8,
|
|
"panels": []interface{}{
|
|
map[string]interface{}{
|
|
"id": 1,
|
|
"type": "text",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "dashboard without panels should only update schema version",
|
|
input: map[string]interface{}{
|
|
"title": "V8 No Panels Test Dashboard",
|
|
"schemaVersion": 7,
|
|
},
|
|
expected: map[string]interface{}{
|
|
"title": "V8 No Panels Test Dashboard",
|
|
"schemaVersion": 8,
|
|
},
|
|
},
|
|
}
|
|
runMigrationTests(t, tests, schemaversion.V8)
|
|
}
|