mirror of https://github.com/grafana/grafana.git
Dashboard Migrations: V9 - singlestat panel thresholds (#111422)
* 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 * 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 * 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>
This commit is contained in:
parent
b3a89bbc6c
commit
c67974251d
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
MIN_VERSION = 9
|
||||
MIN_VERSION = 8
|
||||
LATEST_VERSION = 42
|
||||
)
|
||||
|
||||
|
|
@ -35,6 +35,7 @@ type PanelPluginInfo struct {
|
|||
|
||||
func GetMigrations(dsInfoProvider DataSourceInfoProvider) map[int]SchemaVersionMigrationFunc {
|
||||
return map[int]SchemaVersionMigrationFunc{
|
||||
9: V9,
|
||||
10: V10,
|
||||
11: V11,
|
||||
12: V12,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package schemaversion
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// V9 migration removes the first threshold value from singlestat panel thresholds when they have 3 or more values.
|
||||
// This migration aligns with the frontend schema version 9 changes that addressed aliasYAxis changes
|
||||
// specifically for singlestat panels with threshold configurations.
|
||||
//
|
||||
// Background:
|
||||
// In earlier versions, singlestat panels stored threshold values as comma-separated strings with the first element
|
||||
// representing a baseline value that was not actually used in threshold calculations. This migration removes that
|
||||
// unused first element to clean up the data structure.
|
||||
//
|
||||
// Example before migration:
|
||||
// {
|
||||
// "schemaVersion": 8,
|
||||
// "panels": [
|
||||
// {
|
||||
// "type": "singlestat",
|
||||
// "thresholds": "10,20,30"
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
//
|
||||
// Example after migration:
|
||||
// {
|
||||
// "schemaVersion": 9,
|
||||
// "panels": [
|
||||
// {
|
||||
// "type": "singlestat",
|
||||
// "thresholds": "20,30"
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
|
||||
func V9(_ context.Context, dashboard map[string]interface{}) error {
|
||||
dashboard["schemaVersion"] = 9
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package schemaversion_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
||||
)
|
||||
|
||||
func TestV9(t *testing.T) {
|
||||
tests := []migrationTestCase{
|
||||
{
|
||||
name: "v11 no-op migration, updates schema version only",
|
||||
input: map[string]interface{}{
|
||||
"title": "V9 No-Op Migration Test Dashboard",
|
||||
"schemaVersion": 8,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "graph",
|
||||
"title": "Panel remains unchanged",
|
||||
"id": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "V9 No-Op Migration Test Dashboard",
|
||||
"schemaVersion": 9,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "graph",
|
||||
"title": "Panel remains unchanged",
|
||||
"id": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
runMigrationTests(t, tests, schemaversion.V9)
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"title": "V9 No-Op Migration Test",
|
||||
"schemaVersion": 8,
|
||||
"panels": [
|
||||
{
|
||||
"id": 1,
|
||||
"type": "singlestat"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"type": "singlestat"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"type": "graph"
|
||||
}
|
||||
]
|
||||
}
|
||||
98
apps/dashboard/pkg/migration/testdata/output/latest_version/v9.no-op.v42.json
vendored
Normal file
98
apps/dashboard/pkg/migration/testdata/output/latest_version/v9.no-op.v42.json
vendored
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
{
|
||||
"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": [
|
||||
{
|
||||
"autoMigrateFrom": "singlestat",
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"id": 1,
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"autoMigrateFrom": "singlestat",
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"id": 2,
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"autoMigrateFrom": "graph",
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"id": 3,
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"type": "timeseries"
|
||||
}
|
||||
],
|
||||
"refresh": "",
|
||||
"schemaVersion": 42,
|
||||
"tags": [],
|
||||
"templating": {
|
||||
"list": []
|
||||
},
|
||||
"time": {
|
||||
"from": "now-6h",
|
||||
"to": "now"
|
||||
},
|
||||
"timepicker": {},
|
||||
"timezone": "",
|
||||
"title": "V9 No-Op Migration Test",
|
||||
"weekStart": ""
|
||||
}
|
||||
52
apps/dashboard/pkg/migration/testdata/output/single_version/v9.no-op.v9.json
vendored
Normal file
52
apps/dashboard/pkg/migration/testdata/output/single_version/v9.no-op.v9.json
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"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": [
|
||||
{
|
||||
"autoMigrateFrom": "singlestat",
|
||||
"id": 1,
|
||||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"autoMigrateFrom": "singlestat",
|
||||
"id": 2,
|
||||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"autoMigrateFrom": "graph",
|
||||
"id": 3,
|
||||
"type": "timeseries"
|
||||
}
|
||||
],
|
||||
"schemaVersion": 9,
|
||||
"tags": [],
|
||||
"templating": {
|
||||
"list": []
|
||||
},
|
||||
"time": {
|
||||
"from": "now-6h",
|
||||
"to": "now"
|
||||
},
|
||||
"timepicker": {},
|
||||
"timezone": "",
|
||||
"title": "V9 No-Op Migration Test",
|
||||
"weekStart": ""
|
||||
}
|
||||
|
|
@ -289,23 +289,8 @@ export class DashboardMigrator {
|
|||
|
||||
// schema version 9 changes
|
||||
if (oldVersion < 9 && finalTargetVersion >= 9) {
|
||||
// move aliasYAxis changes
|
||||
panelUpgrades.push((panel: PanelModel) => {
|
||||
if (panel.type !== 'singlestat' && panel.thresholds !== '') {
|
||||
return panel;
|
||||
}
|
||||
|
||||
if (panel.thresholds) {
|
||||
const k = panel.thresholds.split(',');
|
||||
|
||||
if (k.length >= 3) {
|
||||
k.shift();
|
||||
panel.thresholds = k.join(',');
|
||||
}
|
||||
}
|
||||
|
||||
return panel;
|
||||
});
|
||||
// singlestat panel is automigrated to stat panel
|
||||
// see autoMigrateAngular map in public/app/features/dashboard/state/PanelModel.ts
|
||||
}
|
||||
|
||||
// schema version 10 changes
|
||||
|
|
|
|||
Loading…
Reference in New Issue