Migration v42: HideFrom tooltip consistency migration (#110517)
* Migration to be verified: v42 HideFrom tooltip migration * snap update * make gen cue * Add comments of 42 being the final version
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
const (
|
||||
MIN_VERSION = 13
|
||||
LATEST_VERSION = 41
|
||||
LATEST_VERSION = 42
|
||||
|
||||
// The pluginVersion to set after simulating auto-migrate for angular panels
|
||||
pluginVersionForAutoMigrate = "12.1.0"
|
||||
@@ -66,6 +66,7 @@ func GetMigrations(dsInfoProvider DataSourceInfoProvider) map[int]SchemaVersionM
|
||||
39: V39,
|
||||
40: V40,
|
||||
41: V41,
|
||||
42: V42,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package schemaversion
|
||||
|
||||
import "context"
|
||||
|
||||
// V42 ensures that when a field is hidden from visualization, it is also hidden from tooltips.
|
||||
//
|
||||
// This migration addresses the inconsistency where fields could be hidden from visualizations
|
||||
// (hideFrom.viz = true) but would still appear in tooltips. To prevent user confusion and ensure
|
||||
// consistent behavior, this migration automatically sets hideFrom.tooltip = true for any field
|
||||
// configuration override that has hideFrom.viz = true.
|
||||
//
|
||||
// The migration specifically targets field configuration overrides, including the special
|
||||
// __systemRef override, and updates the hideFrom object to include tooltip: true whenever
|
||||
// viz: true is found.
|
||||
//
|
||||
// Example transformation:
|
||||
//
|
||||
// Before migration:
|
||||
//
|
||||
// fieldConfig: {
|
||||
// overrides: [{
|
||||
// properties: [{
|
||||
// id: "custom.hideFrom",
|
||||
// value: { viz: true }
|
||||
// }]
|
||||
// }]
|
||||
// }
|
||||
//
|
||||
// After migration:
|
||||
//
|
||||
// fieldConfig: {
|
||||
// overrides: [{
|
||||
// properties: [{
|
||||
// id: "custom.hideFrom",
|
||||
// value: { viz: true, tooltip: true }
|
||||
// }]
|
||||
// }]
|
||||
// }
|
||||
func V42(_ context.Context, dash map[string]interface{}) error {
|
||||
dash["schemaVersion"] = int(42)
|
||||
|
||||
// Get panels from dashboard
|
||||
panels, ok := dash["panels"].([]interface{})
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Process each panel
|
||||
for _, panelInterface := range panels {
|
||||
panel, ok := panelInterface.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
migrateHideFromForPanel(panel)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// migrateHideFromForPanel processes a single panel and its nested panels
|
||||
func migrateHideFromForPanel(panel map[string]interface{}) {
|
||||
// Process the panel's field config
|
||||
if fieldConfig, ok := panel["fieldConfig"].(map[string]interface{}); ok {
|
||||
if overrides, ok := fieldConfig["overrides"].([]interface{}); ok {
|
||||
for _, overrideInterface := range overrides {
|
||||
override, ok := overrideInterface.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if properties, ok := override["properties"].([]interface{}); ok {
|
||||
for _, propertyInterface := range properties {
|
||||
property, ok := propertyInterface.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if this is a custom.hideFrom property
|
||||
if id, ok := property["id"].(string); ok && id == "custom.hideFrom" {
|
||||
if value, ok := property["value"].(map[string]interface{}); ok {
|
||||
// If viz is true, also set tooltip to true
|
||||
if GetBoolValue(value, "viz") {
|
||||
value["tooltip"] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process nested panels (for rows)
|
||||
if nestedPanels, ok := panel["panels"].([]interface{}); ok {
|
||||
for _, nestedPanelInterface := range nestedPanels {
|
||||
if nestedPanel, ok := nestedPanelInterface.(map[string]interface{}); ok {
|
||||
migrateHideFromForPanel(nestedPanel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
package schemaversion_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
||||
)
|
||||
|
||||
func TestV42(t *testing.T) {
|
||||
tests := []migrationTestCase{
|
||||
{
|
||||
name: "hideFrom.viz = true should also set hideFrom.tooltip = true",
|
||||
input: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"title": "Panel 1",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"matcher": map[string]interface{}{
|
||||
"id": "byName",
|
||||
"options": "Field 1",
|
||||
},
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"viz": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"schemaVersion": 42,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"title": "Panel 1",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"matcher": map[string]interface{}{
|
||||
"id": "byName",
|
||||
"options": "Field 1",
|
||||
},
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"viz": true,
|
||||
"tooltip": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "hideFrom.viz = false should not change",
|
||||
input: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"title": "Panel 1",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"viz": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"schemaVersion": 42,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"title": "Panel 1",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"viz": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multiple panels with hideFrom.viz = true",
|
||||
input: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"viz": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"id": 2,
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"viz": true,
|
||||
"legend": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"schemaVersion": 42,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"viz": true,
|
||||
"tooltip": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"id": 2,
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"viz": true,
|
||||
"legend": false,
|
||||
"tooltip": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "panel without hideFrom property",
|
||||
input: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"title": "Panel 1",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "unit",
|
||||
"value": "short",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"schemaVersion": 42,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"title": "Panel 1",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "unit",
|
||||
"value": "short",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "nested panels in rows should also be migrated",
|
||||
input: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"type": "row",
|
||||
"title": "Row 1",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 2,
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"viz": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"schemaVersion": 42,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"type": "row",
|
||||
"title": "Row 1",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 2,
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"viz": true,
|
||||
"tooltip": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "__systemRef override should also be migrated",
|
||||
input: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"__systemRef": "hideSeriesFrom",
|
||||
"matcher": map[string]interface{}{
|
||||
"id": "byNames",
|
||||
"options": map[string]interface{}{
|
||||
"mode": "exclude",
|
||||
"names": []interface{}{"foo"},
|
||||
"prefix": "All except:",
|
||||
"readOnly": true,
|
||||
},
|
||||
},
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"legend": false,
|
||||
"tooltip": false,
|
||||
"viz": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"schemaVersion": 42,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"__systemRef": "hideSeriesFrom",
|
||||
"matcher": map[string]interface{}{
|
||||
"id": "byNames",
|
||||
"options": map[string]interface{}{
|
||||
"mode": "exclude",
|
||||
"names": []interface{}{"foo"},
|
||||
"prefix": "All except:",
|
||||
"readOnly": true,
|
||||
},
|
||||
},
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.hideFrom",
|
||||
"value": map[string]interface{}{
|
||||
"legend": false,
|
||||
"tooltip": true,
|
||||
"viz": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "dashboard without panels",
|
||||
input: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"schemaVersion": 42,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "panel without fieldConfig",
|
||||
input: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"title": "Panel 1",
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
"schemaVersion": 42,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"title": "Panel 1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
runMigrationTests(t, tests, schemaversion.V42)
|
||||
}
|
||||
Reference in New Issue
Block a user