Dashboard Migrations: V35 ensures X-axis visibility in timeseries (#106633)
* Add datasource info provider * Dashboards: Support schemaVersion v35 migration in backend * update go mods --------- Co-authored-by: Todd Treece <360020+toddtreece@users.noreply.github.com> Co-authored-by: Haris Rozajac <haris.rozajac12@gmail.com> Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
This commit is contained in:
co-authored by
Todd Treece
Haris Rozajac
Stephanie Hingtgen
parent
25fe2b54fb
commit
09bbdfe8ab
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MIN_VERSION = 35
|
||||
MIN_VERSION = 34
|
||||
LATEST_VERSION = 41
|
||||
)
|
||||
|
||||
@@ -26,6 +26,7 @@ type DataSourceInfoProvider interface {
|
||||
|
||||
func GetMigrations(dsInfoProvider DataSourceInfoProvider) map[int]SchemaVersionMigrationFunc {
|
||||
return map[int]SchemaVersionMigrationFunc{
|
||||
35: V35,
|
||||
36: V36(dsInfoProvider),
|
||||
37: V37,
|
||||
38: V38,
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package schemaversion
|
||||
|
||||
// V35 ensures x-axis visibility in timeseries panels to prevent dashboard breakage.
|
||||
//
|
||||
// This migration addresses a specific issue where timeseries panels with all axes
|
||||
// configured as hidden (axisPlacement: "hidden") would result in completely unusable
|
||||
// visualizations, as users would lose the ability to see time progression along the x-axis.
|
||||
//
|
||||
// The migration works by:
|
||||
// 1. Identifying timeseries panels where the default axis placement is set to "hidden"
|
||||
// 2. Adding a field override that specifically targets time-type fields (x-axis)
|
||||
// 3. Setting the axis placement for time fields to "auto" to ensure x-axis visibility
|
||||
//
|
||||
// This preserves the original intent of hiding other axes while maintaining the critical
|
||||
// time axis that makes timeseries data comprehensible. The override uses field matching
|
||||
// by type ("time") to selectively restore visibility only for temporal data.
|
||||
//
|
||||
// Example transformation:
|
||||
//
|
||||
// Before migration:
|
||||
//
|
||||
// fieldConfig: {
|
||||
// defaults: { custom: { axisPlacement: "hidden" } },
|
||||
// overrides: []
|
||||
// }
|
||||
//
|
||||
// After migration:
|
||||
//
|
||||
// fieldConfig: {
|
||||
// defaults: { custom: { axisPlacement: "hidden" } },
|
||||
// overrides: [{
|
||||
// matcher: { id: "byType", options: "time" },
|
||||
// properties: [{ id: "custom.axisPlacement", value: "auto" }]
|
||||
// }]
|
||||
// }
|
||||
func V35(dashboard map[string]interface{}) error {
|
||||
dashboard["schemaVersion"] = int(35)
|
||||
|
||||
panels, ok := dashboard["panels"].([]interface{})
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, panel := range panels {
|
||||
p, ok := panel.(map[string]interface{})
|
||||
if !ok || p["type"] != "timeseries" {
|
||||
continue
|
||||
}
|
||||
|
||||
applyXAxisVisibilityOverride(p)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// applyXAxisVisibilityOverride adds a field override to ensure x-axis visibility
|
||||
// when the panel's default axis placement is set to hidden.
|
||||
func applyXAxisVisibilityOverride(panel map[string]interface{}) {
|
||||
fieldConfig, _ := panel["fieldConfig"].(map[string]interface{})
|
||||
defaults, _ := fieldConfig["defaults"].(map[string]interface{})
|
||||
custom, _ := defaults["custom"].(map[string]interface{})
|
||||
|
||||
if custom["axisPlacement"] != "hidden" {
|
||||
return
|
||||
}
|
||||
|
||||
overrides, _ := fieldConfig["overrides"].([]interface{})
|
||||
fieldConfig["overrides"] = append(overrides, map[string]interface{}{
|
||||
"matcher": map[string]interface{}{
|
||||
"id": "byType",
|
||||
"options": "time",
|
||||
},
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.axisPlacement",
|
||||
"value": "auto",
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
package schemaversion_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
||||
)
|
||||
|
||||
func TestV35(t *testing.T) {
|
||||
tests := []migrationTestCase{
|
||||
{
|
||||
name: "preserves x axis visibility for timeseries with hidden axes",
|
||||
input: map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"custom": map[string]interface{}{
|
||||
"axisPlacement": "hidden",
|
||||
},
|
||||
},
|
||||
"overrides": []interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": int(35),
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"custom": map[string]interface{}{
|
||||
"axisPlacement": "hidden",
|
||||
},
|
||||
},
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"matcher": map[string]interface{}{
|
||||
"id": "byType",
|
||||
"options": "time",
|
||||
},
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.axisPlacement",
|
||||
"value": "auto",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "appends to existing overrides for timeseries with hidden axes",
|
||||
input: map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"custom": map[string]interface{}{
|
||||
"axisPlacement": "hidden",
|
||||
},
|
||||
},
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"matcher": map[string]interface{}{
|
||||
"id": "byName",
|
||||
"options": "Series A",
|
||||
},
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "color.mode",
|
||||
"value": "palette-classic",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": int(35),
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"custom": map[string]interface{}{
|
||||
"axisPlacement": "hidden",
|
||||
},
|
||||
},
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"matcher": map[string]interface{}{
|
||||
"id": "byName",
|
||||
"options": "Series A",
|
||||
},
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "color.mode",
|
||||
"value": "palette-classic",
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"matcher": map[string]interface{}{
|
||||
"id": "byType",
|
||||
"options": "time",
|
||||
},
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.axisPlacement",
|
||||
"value": "auto",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "does not migrate timeseries with non-hidden axis placement",
|
||||
input: map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"custom": map[string]interface{}{
|
||||
"axisPlacement": "auto",
|
||||
},
|
||||
},
|
||||
"overrides": []interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": int(35),
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"custom": map[string]interface{}{
|
||||
"axisPlacement": "auto",
|
||||
},
|
||||
},
|
||||
"overrides": []interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "does not migrate non-timeseries panels",
|
||||
input: map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "stat",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"custom": map[string]interface{}{
|
||||
"axisPlacement": "hidden",
|
||||
},
|
||||
},
|
||||
"overrides": []interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": int(35),
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "stat",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"custom": map[string]interface{}{
|
||||
"axisPlacement": "hidden",
|
||||
},
|
||||
},
|
||||
"overrides": []interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "handles missing fieldConfig gracefully",
|
||||
input: map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"id": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": int(35),
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"id": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "handles missing defaults gracefully",
|
||||
input: map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": int(35),
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"overrides": []interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "handles missing custom config gracefully",
|
||||
input: map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"unit": "bytes",
|
||||
},
|
||||
"overrides": []interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": int(35),
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"unit": "bytes",
|
||||
},
|
||||
"overrides": []interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "handles missing overrides array",
|
||||
input: map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"custom": map[string]interface{}{
|
||||
"axisPlacement": "hidden",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": int(35),
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "timeseries",
|
||||
"fieldConfig": map[string]interface{}{
|
||||
"defaults": map[string]interface{}{
|
||||
"custom": map[string]interface{}{
|
||||
"axisPlacement": "hidden",
|
||||
},
|
||||
},
|
||||
"overrides": []interface{}{
|
||||
map[string]interface{}{
|
||||
"matcher": map[string]interface{}{
|
||||
"id": "byType",
|
||||
"options": "time",
|
||||
},
|
||||
"properties": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": "custom.axisPlacement",
|
||||
"value": "auto",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "handles empty panels array",
|
||||
input: map[string]interface{}{
|
||||
"panels": []interface{}{},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": int(35),
|
||||
"panels": []interface{}{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "handles missing panels",
|
||||
input: map[string]interface{}{
|
||||
"title": "Test Dashboard",
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"schemaVersion": int(35),
|
||||
"title": "Test Dashboard",
|
||||
},
|
||||
},
|
||||
}
|
||||
runMigrationTests(t, tests, schemaversion.V35)
|
||||
}
|
||||
Reference in New Issue
Block a user