Dashboard Migrations: V7 - nav to timepicker (#112140)
* 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 * 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 * lint --------- Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
This commit is contained in:
co-authored by
Dominik Prokop
parent
b232a812ab
commit
58915bd384
@@ -1053,6 +1053,7 @@ func cleanupDashboardDefaults(dashboard map[string]interface{}) {
|
||||
// These properties are lost during frontend's property copying loop in getSaveModelCloneOld()
|
||||
delete(dashboard, "preload") // Transient dashboard loading state
|
||||
delete(dashboard, "iteration") // Template variable iteration timestamp
|
||||
delete(dashboard, "nav")
|
||||
}
|
||||
|
||||
// cleanupFieldConfigDefaults removes properties that frontend considers as defaults and omits
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MIN_VERSION = 7
|
||||
MIN_VERSION = 6
|
||||
LATEST_VERSION = 42
|
||||
)
|
||||
|
||||
@@ -35,6 +35,7 @@ type PanelPluginInfo struct {
|
||||
|
||||
func GetMigrations(dsInfoProvider DataSourceInfoProvider) map[int]SchemaVersionMigrationFunc {
|
||||
return map[int]SchemaVersionMigrationFunc{
|
||||
7: V7,
|
||||
8: V8,
|
||||
9: V9,
|
||||
10: V10,
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package schemaversion
|
||||
|
||||
import "context"
|
||||
|
||||
// V7 migration handles the nav to timepicker conversion and ensures query refIds.
|
||||
// This migration transforms the legacy nav property to the newer timepicker format
|
||||
// and ensures all panel targets have refId properties.
|
||||
//
|
||||
// Background:
|
||||
// In earlier versions, dashboards used a "nav" property array to store time picker
|
||||
// configuration. This migration moves the first nav item to the "timepicker" property.
|
||||
// Additionally, it ensures all query targets have refId properties assigned.
|
||||
//
|
||||
// Example before migration:
|
||||
// {
|
||||
// "schemaVersion": 6,
|
||||
// "nav": [
|
||||
// {
|
||||
// "enable": true,
|
||||
// "type": "timepicker",
|
||||
// "status": "Stable",
|
||||
// "time_options": ["5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"],
|
||||
// "refresh_intervals": ["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"],
|
||||
// "now": true,
|
||||
// "collapse": false,
|
||||
// "notice": false
|
||||
// }
|
||||
// ],
|
||||
// "panels": [
|
||||
// {
|
||||
// "targets": [
|
||||
// {"expr": "up"},
|
||||
// {"expr": "cpu_usage", "refId": "B"}
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
//
|
||||
// Example after migration:
|
||||
// {
|
||||
// "schemaVersion": 7,
|
||||
// "timepicker": {
|
||||
// "enable": true,
|
||||
// "type": "timepicker",
|
||||
// "status": "Stable",
|
||||
// "time_options": ["5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"],
|
||||
// "refresh_intervals": ["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"],
|
||||
// "now": true,
|
||||
// "collapse": false,
|
||||
// "notice": false
|
||||
// },
|
||||
// "panels": [
|
||||
// {
|
||||
// "targets": [
|
||||
// {"expr": "up", "refId": "A"},
|
||||
// {"expr": "cpu_usage", "refId": "B"}
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
|
||||
func V7(_ context.Context, dashboard map[string]interface{}) error {
|
||||
dashboard["schemaVersion"] = 7
|
||||
|
||||
// Convert nav to timepicker (matches frontend DashboardMigrator logic)
|
||||
if nav, ok := dashboard["nav"].([]interface{}); ok && len(nav) > 0 {
|
||||
if firstNav, ok := nav[0].(map[string]interface{}); ok {
|
||||
dashboard["timepicker"] = firstNav
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
package schemaversion_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
||||
)
|
||||
|
||||
func TestV7Migration(t *testing.T) {
|
||||
testCases := []migrationTestCase{
|
||||
{
|
||||
name: "nav to timepicker conversion with query refId assignment",
|
||||
input: map[string]interface{}{
|
||||
"schemaVersion": 6,
|
||||
"nav": []interface{}{
|
||||
map[string]interface{}{
|
||||
"enable": true,
|
||||
"type": "timepicker",
|
||||
"status": "Stable",
|
||||
"time_options": []interface{}{"5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"},
|
||||
"refresh_intervals": []interface{}{"5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"},
|
||||
"now": true,
|
||||
"collapse": false,
|
||||
"notice": false,
|
||||
},
|
||||
},
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"targets": []interface{}{
|
||||
map[string]interface{}{"expr": "up"},
|
||||
map[string]interface{}{"expr": "cpu_usage", "refId": "B"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": 7,
|
||||
"nav": []interface{}{
|
||||
map[string]interface{}{
|
||||
"enable": true,
|
||||
"type": "timepicker",
|
||||
"status": "Stable",
|
||||
"time_options": []interface{}{"5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"},
|
||||
"refresh_intervals": []interface{}{"5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"},
|
||||
"now": true,
|
||||
"collapse": false,
|
||||
"notice": false,
|
||||
},
|
||||
},
|
||||
"timepicker": map[string]interface{}{
|
||||
"enable": true,
|
||||
"type": "timepicker",
|
||||
"status": "Stable",
|
||||
"time_options": []interface{}{"5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"},
|
||||
"refresh_intervals": []interface{}{"5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"},
|
||||
"now": true,
|
||||
"collapse": false,
|
||||
"notice": false,
|
||||
},
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"targets": []interface{}{
|
||||
map[string]interface{}{"expr": "up"},
|
||||
map[string]interface{}{"expr": "cpu_usage", "refId": "B"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "nav conversion without panels",
|
||||
input: map[string]interface{}{
|
||||
"schemaVersion": 6,
|
||||
"nav": []interface{}{
|
||||
map[string]interface{}{
|
||||
"enable": true,
|
||||
"type": "timepicker",
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": 7,
|
||||
"timepicker": map[string]interface{}{
|
||||
"enable": true,
|
||||
"type": "timepicker",
|
||||
},
|
||||
"nav": []interface{}{
|
||||
map[string]interface{}{
|
||||
"enable": true,
|
||||
"type": "timepicker",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty nav array",
|
||||
input: map[string]interface{}{
|
||||
"schemaVersion": 6,
|
||||
"nav": []interface{}{},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": 7,
|
||||
"nav": []interface{}{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no nav property",
|
||||
input: map[string]interface{}{
|
||||
"schemaVersion": 6,
|
||||
"title": "Test Dashboard",
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": 7,
|
||||
"title": "Test Dashboard",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "panels with nested panels",
|
||||
input: map[string]interface{}{
|
||||
"schemaVersion": 6,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "row",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"targets": []interface{}{
|
||||
map[string]interface{}{"expr": "memory_usage"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": 7,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "row",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"targets": []interface{}{
|
||||
map[string]interface{}{"expr": "memory_usage"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multiple nav items - only first is used",
|
||||
input: map[string]interface{}{
|
||||
"schemaVersion": 6,
|
||||
"nav": []interface{}{
|
||||
map[string]interface{}{
|
||||
"enable": true,
|
||||
"type": "timepicker",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"enable": false,
|
||||
"type": "other",
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": 7,
|
||||
"timepicker": map[string]interface{}{
|
||||
"enable": true,
|
||||
"type": "timepicker",
|
||||
},
|
||||
"nav": []interface{}{
|
||||
map[string]interface{}{
|
||||
"enable": true,
|
||||
"type": "timepicker",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"enable": false,
|
||||
"type": "other",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid nav structure",
|
||||
input: map[string]interface{}{
|
||||
"schemaVersion": 6,
|
||||
"nav": "invalid",
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": 7,
|
||||
"nav": "invalid",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "panels with invalid structure",
|
||||
input: map[string]interface{}{
|
||||
"schemaVersion": 6,
|
||||
"panels": "invalid",
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": 7,
|
||||
"panels": "invalid",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
runMigrationTests(t, testCases, schemaversion.V7)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"schemaVersion": 6,
|
||||
"nav": [
|
||||
{
|
||||
"enable": true,
|
||||
"type": "timepicker",
|
||||
"status": "Stable",
|
||||
"time_options": ["5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"],
|
||||
"refresh_intervals": ["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"],
|
||||
"now": true,
|
||||
"collapse": false,
|
||||
"notice": false
|
||||
}
|
||||
],
|
||||
"panels": [
|
||||
{
|
||||
"targets": [
|
||||
{"expr": "up"},
|
||||
{"expr": "cpu_usage", "refId": "B"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"annotations": {
|
||||
"list": [
|
||||
{
|
||||
"builtIn": 1,
|
||||
"datasource": {
|
||||
"type": "grafana",
|
||||
"uid": "-- Grafana --"
|
||||
},
|
||||
"enable": true,
|
||||
"hide": true,
|
||||
"iconColor": "rgba(0, 211, 255, 1)",
|
||||
"name": "Annotations \u0026 Alerts",
|
||||
"type": "dashboard"
|
||||
}
|
||||
]
|
||||
},
|
||||
"editable": true,
|
||||
"fiscalYearStartMonth": 0,
|
||||
"graphTooltip": 0,
|
||||
"links": [],
|
||||
"panels": [
|
||||
{
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"id": 1,
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"expr": "up",
|
||||
"refId": "A"
|
||||
},
|
||||
{
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"expr": "cpu_usage",
|
||||
"refId": "B"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"refresh": "",
|
||||
"schemaVersion": 42,
|
||||
"tags": [],
|
||||
"templating": {
|
||||
"list": []
|
||||
},
|
||||
"time": {
|
||||
"from": "now-6h",
|
||||
"to": "now"
|
||||
},
|
||||
"timepicker": {
|
||||
"collapse": false,
|
||||
"enable": true,
|
||||
"notice": false,
|
||||
"now": true,
|
||||
"refresh_intervals": [
|
||||
"5s",
|
||||
"10s",
|
||||
"30s",
|
||||
"1m",
|
||||
"5m",
|
||||
"15m",
|
||||
"30m",
|
||||
"1h",
|
||||
"2h",
|
||||
"1d"
|
||||
],
|
||||
"status": "Stable",
|
||||
"type": "timepicker"
|
||||
},
|
||||
"timezone": "",
|
||||
"title": "No Title",
|
||||
"weekStart": ""
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"annotations": {
|
||||
"list": [
|
||||
{
|
||||
"builtIn": 1,
|
||||
"datasource": {
|
||||
"type": "grafana",
|
||||
"uid": "-- Grafana --"
|
||||
},
|
||||
"enable": true,
|
||||
"hide": true,
|
||||
"iconColor": "rgba(0, 211, 255, 1)",
|
||||
"name": "Annotations \u0026 Alerts",
|
||||
"type": "dashboard"
|
||||
}
|
||||
]
|
||||
},
|
||||
"editable": true,
|
||||
"fiscalYearStartMonth": 0,
|
||||
"graphTooltip": 0,
|
||||
"links": [],
|
||||
"panels": [
|
||||
{
|
||||
"id": 1,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "up",
|
||||
"refId": "A"
|
||||
},
|
||||
{
|
||||
"expr": "cpu_usage",
|
||||
"refId": "B"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"schemaVersion": 7,
|
||||
"tags": [],
|
||||
"templating": {
|
||||
"list": []
|
||||
},
|
||||
"time": {
|
||||
"from": "now-6h",
|
||||
"to": "now"
|
||||
},
|
||||
"timepicker": {
|
||||
"collapse": false,
|
||||
"enable": true,
|
||||
"notice": false,
|
||||
"now": true,
|
||||
"refresh_intervals": [
|
||||
"5s",
|
||||
"10s",
|
||||
"30s",
|
||||
"1m",
|
||||
"5m",
|
||||
"15m",
|
||||
"30m",
|
||||
"1h",
|
||||
"2h",
|
||||
"1d"
|
||||
],
|
||||
"status": "Stable",
|
||||
"time_options": [
|
||||
"5m",
|
||||
"15m",
|
||||
"1h",
|
||||
"6h",
|
||||
"12h",
|
||||
"24h",
|
||||
"2d",
|
||||
"7d",
|
||||
"30d"
|
||||
],
|
||||
"type": "timepicker"
|
||||
},
|
||||
"timezone": "",
|
||||
"title": "No Title",
|
||||
"weekStart": ""
|
||||
}
|
||||
@@ -2531,7 +2531,7 @@
|
||||
"count": 2
|
||||
},
|
||||
"@typescript-eslint/no-explicit-any": {
|
||||
"count": 19
|
||||
"count": 18
|
||||
}
|
||||
},
|
||||
"public/app/features/dashboard/state/DashboardModel.repeat.test.ts": {
|
||||
|
||||
@@ -229,17 +229,6 @@ export class DashboardMigrator {
|
||||
if (old.nav && old.nav.length) {
|
||||
this.dashboard.timepicker = old.nav[0];
|
||||
}
|
||||
|
||||
// ensure query refIds
|
||||
panelUpgrades.push((panel: any) => {
|
||||
each(panel.targets, (target) => {
|
||||
if (!target.refId) {
|
||||
target.refId = panel.getNextQueryLetter && panel.getNextQueryLetter();
|
||||
}
|
||||
});
|
||||
|
||||
return panel;
|
||||
});
|
||||
}
|
||||
|
||||
if (oldVersion < 8 && finalTargetVersion >= 8) {
|
||||
|
||||
Reference in New Issue
Block a user