Dashboard Migrations: V10 - table panel styles.thresholds (#111420)

* 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

* 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

* 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

---------

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
This commit is contained in:
Haris Rozajac
2025-10-09 16:36:24 -06:00
committed by GitHub
parent bba720557c
commit 01ec8e3a4a
6 changed files with 557 additions and 1 deletions
@@ -7,7 +7,7 @@ import (
)
const (
MIN_VERSION = 10
MIN_VERSION = 9
LATEST_VERSION = 42
)
@@ -35,6 +35,7 @@ type PanelPluginInfo struct {
func GetMigrations(dsInfoProvider DataSourceInfoProvider) map[int]SchemaVersionMigrationFunc {
return map[int]SchemaVersionMigrationFunc{
10: V10,
11: V11,
12: V12,
13: V13,
@@ -0,0 +1,97 @@
package schemaversion
import "context"
// V10 migration removes the first threshold value from table panel styles when they have 3 or more thresholds.
// This migration aligns with the frontend schema version 10 changes that addressed aliasYAxis changes
// specifically for table panels with threshold configurations.
//
// Background:
// In earlier versions, table panels stored threshold values as arrays 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": 9,
// "panels": [
// {
// "type": "table",
// "styles": [
// {
// "thresholds": ["10", "20", "30"]
// },
// {
// "thresholds": ["100", "200", "300"]
// }
// ]
// }
// ]
// }
//
// Example after migration:
// {
// "schemaVersion": 10,
// "panels": [
// {
// "type": "table",
// "styles": [
// {
// "thresholds": ["20", "30"]
// },
// {
// "thresholds": ["200", "300"]
// }
// ]
// }
// ]
// }
func V10(_ context.Context, dashboard map[string]interface{}) error {
dashboard["schemaVersion"] = 10
panels, ok := dashboard["panels"].([]interface{})
if !ok {
return nil
}
for _, p := range panels {
panel, ok := p.(map[string]interface{})
if !ok {
continue
}
// Only process table panels
panelType := GetStringValue(panel, "type")
if panelType != "table" {
continue
}
styles, ok := panel["styles"].([]interface{})
if !ok {
continue
}
// Process each style in the table panel
for _, s := range styles {
style, ok := s.(map[string]interface{})
if !ok {
continue
}
thresholds, ok := style["thresholds"].([]interface{})
if !ok {
continue
}
// Only modify thresholds if they have 3 or more values
if len(thresholds) >= 3 {
// Remove the first threshold value
newThresholds := thresholds[1:]
style["thresholds"] = newThresholds
}
}
}
return nil
}
@@ -0,0 +1,209 @@
package schemaversion_test
import (
"testing"
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
)
func TestV10(t *testing.T) {
tests := []migrationTestCase{
{
name: "table panel with thresholds having 3 or more values should have first threshold removed",
input: map[string]interface{}{
"title": "V10 Table Thresholds Migration Test Dashboard",
"schemaVersion": 9,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"10", "20", "30"},
},
map[string]interface{}{
"thresholds": []interface{}{"100", "200", "300"},
},
},
},
},
},
expected: map[string]interface{}{
"title": "V10 Table Thresholds Migration Test Dashboard",
"schemaVersion": 10,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"20", "30"},
},
map[string]interface{}{
"thresholds": []interface{}{"200", "300"},
},
},
},
},
},
},
{
name: "table panel with thresholds having less than 3 values should remain unchanged",
input: map[string]interface{}{
"title": "V10 Table Thresholds No Change Test Dashboard",
"schemaVersion": 9,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"10", "20"},
},
map[string]interface{}{
"thresholds": []interface{}{"100"},
},
},
},
},
},
expected: map[string]interface{}{
"title": "V10 Table Thresholds No Change Test Dashboard",
"schemaVersion": 10,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"10", "20"},
},
map[string]interface{}{
"thresholds": []interface{}{"100"},
},
},
},
},
},
},
{
name: "non-table panels should remain unchanged",
input: map[string]interface{}{
"title": "V10 Non-Table Panel Test Dashboard",
"schemaVersion": 9,
"panels": []interface{}{
map[string]interface{}{
"type": "graph",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"10", "20", "30"},
},
},
},
map[string]interface{}{
"type": "singlestat",
"id": 2,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"100", "200", "300"},
},
},
},
},
},
expected: map[string]interface{}{
"title": "V10 Non-Table Panel Test Dashboard",
"schemaVersion": 10,
"panels": []interface{}{
map[string]interface{}{
"type": "graph",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"10", "20", "30"},
},
},
},
map[string]interface{}{
"type": "singlestat",
"id": 2,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"100", "200", "300"},
},
},
},
},
},
},
{
name: "table panel without styles should remain unchanged",
input: map[string]interface{}{
"title": "V10 Table No Styles Test Dashboard",
"schemaVersion": 9,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
},
},
},
expected: map[string]interface{}{
"title": "V10 Table No Styles Test Dashboard",
"schemaVersion": 10,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
},
},
},
},
{
name: "table panel with styles but no thresholds should remain unchanged",
input: map[string]interface{}{
"title": "V10 Table No Thresholds Test Dashboard",
"schemaVersion": 9,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"colorMode": "cell",
},
},
},
},
},
expected: map[string]interface{}{
"title": "V10 Table No Thresholds Test Dashboard",
"schemaVersion": 10,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"colorMode": "cell",
},
},
},
},
},
},
{
name: "dashboard without panels should only update schema version",
input: map[string]interface{}{
"title": "V10 No Panels Test Dashboard",
"schemaVersion": 9,
},
expected: map[string]interface{}{
"title": "V10 No Panels Test Dashboard",
"schemaVersion": 10,
},
},
}
runMigrationTests(t, tests, schemaversion.V10)
}
@@ -0,0 +1,36 @@
{
"title": "V10 Table Thresholds Test",
"schemaVersion": 9,
"panels": [
{
"id": 1,
"type": "table",
"styles": [
{
"thresholds": ["10", "20", "30"]
},
{
"thresholds": ["100", "200", "300"]
}
]
},
{
"id": 2,
"type": "table",
"styles": [
{
"thresholds": ["50", "75"]
}
]
},
{
"id": 3,
"type": "graph",
"styles": [
{
"thresholds": ["5", "10", "15"]
}
]
}
]
}
@@ -0,0 +1,132 @@
{
"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": "table-old",
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 1,
"styles": [
{
"align": "auto",
"thresholds": [
"20",
"30"
]
},
{
"align": "auto",
"thresholds": [
"200",
"300"
]
}
],
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"refId": "A"
}
],
"type": "table"
},
{
"autoMigrateFrom": "table-old",
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 2,
"styles": [
{
"align": "auto",
"thresholds": [
"50",
"75"
]
}
],
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"refId": "A"
}
],
"type": "table"
},
{
"autoMigrateFrom": "graph",
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 3,
"styles": [
{
"thresholds": [
"5",
"10",
"15"
]
}
],
"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": "V10 Table Thresholds Test",
"weekStart": ""
}
@@ -0,0 +1,81 @@
{
"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,
"styles": [
{
"thresholds": [
"20",
"30"
]
},
{
"thresholds": [
"200",
"300"
]
}
],
"type": "table"
},
{
"id": 2,
"styles": [
{
"thresholds": [
"50",
"75"
]
}
],
"type": "table"
},
{
"autoMigrateFrom": "graph",
"id": 3,
"styles": [
{
"thresholds": [
"5",
"10",
"15"
]
}
],
"type": "timeseries"
}
],
"schemaVersion": 10,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "V10 Table Thresholds Test",
"weekStart": ""
}