mirror of https://github.com/grafana/grafana.git
Migration to be verified: 14 Shared crosshair to graph tooltip migration
This commit is contained in:
parent
d270c641d2
commit
f443f6dc97
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
MIN_VERSION = 14
|
||||
MIN_VERSION = 13
|
||||
LATEST_VERSION = 41
|
||||
)
|
||||
|
||||
|
|
@ -38,6 +38,7 @@ type PanelPluginInfoProvider interface {
|
|||
|
||||
func GetMigrations(dsInfoProvider DataSourceInfoProvider, panelProvider PanelPluginInfoProvider) map[int]SchemaVersionMigrationFunc {
|
||||
return map[int]SchemaVersionMigrationFunc{
|
||||
14: V14,
|
||||
15: V15,
|
||||
16: V16,
|
||||
17: V17,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package schemaversion
|
||||
|
||||
// V14 migrates the sharedCrosshair boolean property to graphTooltip integer property.
|
||||
// This migration converts the old boolean shared crosshair setting to the new integer-based
|
||||
// graph tooltip setting for consistency with updated dashboard tooltip behavior.
|
||||
|
||||
// Example before migration:
|
||||
// {
|
||||
// "schemaVersion": 13,
|
||||
// "title": "My Dashboard",
|
||||
// "sharedCrosshair": true,
|
||||
// "panels": [...]
|
||||
// }
|
||||
|
||||
// Example after migration:
|
||||
// {
|
||||
// "schemaVersion": 14,
|
||||
// "title": "My Dashboard",
|
||||
// "graphTooltip": 1,
|
||||
// "panels": [...]
|
||||
// }
|
||||
|
||||
func V14(dashboard map[string]interface{}) error {
|
||||
// Convert sharedCrosshair boolean to graphTooltip integer
|
||||
sharedCrosshair := GetBoolValue(dashboard, "sharedCrosshair")
|
||||
|
||||
if sharedCrosshair {
|
||||
dashboard["graphTooltip"] = 1
|
||||
} else {
|
||||
dashboard["graphTooltip"] = 0
|
||||
}
|
||||
|
||||
// Remove the old sharedCrosshair property
|
||||
delete(dashboard, "sharedCrosshair")
|
||||
|
||||
dashboard["schemaVersion"] = 14
|
||||
return nil
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package schemaversion_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
||||
)
|
||||
|
||||
func TestV14(t *testing.T) {
|
||||
tests := []migrationTestCase{
|
||||
{
|
||||
name: "v14 migration converts sharedCrosshair true to graphTooltip 1",
|
||||
input: map[string]interface{}{
|
||||
"title": "V14 Migration Test Dashboard",
|
||||
"schemaVersion": 13,
|
||||
"sharedCrosshair": true,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "graph",
|
||||
"title": "CPU Usage",
|
||||
"id": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "V14 Migration Test Dashboard",
|
||||
"schemaVersion": 14,
|
||||
"graphTooltip": 1,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "graph",
|
||||
"title": "CPU Usage",
|
||||
"id": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "v14 migration converts sharedCrosshair false to graphTooltip 0",
|
||||
input: map[string]interface{}{
|
||||
"title": "V14 Migration Test Dashboard",
|
||||
"schemaVersion": 13,
|
||||
"sharedCrosshair": false,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "singlestat",
|
||||
"title": "Memory Usage",
|
||||
"id": 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "V14 Migration Test Dashboard",
|
||||
"schemaVersion": 14,
|
||||
"graphTooltip": 0,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "singlestat",
|
||||
"title": "Memory Usage",
|
||||
"id": 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "v14 migration handles missing sharedCrosshair (defaults to false/0)",
|
||||
input: map[string]interface{}{
|
||||
"title": "V14 Migration Test Dashboard",
|
||||
"schemaVersion": 13,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "table",
|
||||
"title": "Server Stats",
|
||||
"id": 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "V14 Migration Test Dashboard",
|
||||
"schemaVersion": 14,
|
||||
"graphTooltip": 0,
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "table",
|
||||
"title": "Server Stats",
|
||||
"id": 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
runMigrationTests(t, tests, schemaversion.V14)
|
||||
}
|
||||
65
apps/dashboard/pkg/migration/testdata/input/v14.shared_crosshair_to_graph_tooltip.json
vendored
Normal file
65
apps/dashboard/pkg/migration/testdata/input/v14.shared_crosshair_to_graph_tooltip.json
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
{
|
||||
"title": "V14 Shared Crosshair Migration Test Dashboard",
|
||||
"schemaVersion": 13,
|
||||
"sharedCrosshair": true,
|
||||
"panels": [
|
||||
{
|
||||
"type": "graph",
|
||||
"title": "CPU Usage Over Time",
|
||||
"id": 1,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "cpu_usage",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"yAxes": [
|
||||
{
|
||||
"show": true,
|
||||
"min": null,
|
||||
"max": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "graph",
|
||||
"title": "Memory Usage",
|
||||
"id": 2,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "memory_usage",
|
||||
"refId": "B"
|
||||
}
|
||||
],
|
||||
"yAxes": [
|
||||
{
|
||||
"show": true,
|
||||
"min": 0,
|
||||
"max": 100
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"templating": {
|
||||
"list": [
|
||||
{
|
||||
"name": "server",
|
||||
"type": "query",
|
||||
"datasource": "prometheus",
|
||||
"query": "label_values(server)",
|
||||
"refresh": 1,
|
||||
"options": []
|
||||
}
|
||||
]
|
||||
},
|
||||
"time": {
|
||||
"from": "now-1h",
|
||||
"to": "now"
|
||||
},
|
||||
"timepicker": {
|
||||
"refresh_intervals": ["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"]
|
||||
},
|
||||
"annotations": {
|
||||
"list": []
|
||||
}
|
||||
}
|
||||
99
apps/dashboard/pkg/migration/testdata/output/v14.shared_crosshair_to_graph_tooltip.json
vendored
Normal file
99
apps/dashboard/pkg/migration/testdata/output/v14.shared_crosshair_to_graph_tooltip.json
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
{
|
||||
"annotations": {
|
||||
"list": []
|
||||
},
|
||||
"graphTooltip": 1,
|
||||
"panels": [
|
||||
{
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"id": 1,
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"expr": "cpu_usage",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"title": "CPU Usage Over Time",
|
||||
"type": "graph",
|
||||
"yAxes": [
|
||||
{
|
||||
"max": null,
|
||||
"min": null,
|
||||
"show": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"id": 2,
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"apiVersion": "v1",
|
||||
"type": "prometheus",
|
||||
"uid": "default-ds-uid"
|
||||
},
|
||||
"expr": "memory_usage",
|
||||
"refId": "B"
|
||||
}
|
||||
],
|
||||
"title": "Memory Usage",
|
||||
"type": "graph",
|
||||
"yAxes": [
|
||||
{
|
||||
"max": 100,
|
||||
"min": 0,
|
||||
"show": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"refresh": "",
|
||||
"schemaVersion": 41,
|
||||
"templating": {
|
||||
"list": [
|
||||
{
|
||||
"datasource": {
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"name": "server",
|
||||
"options": [],
|
||||
"query": "label_values(server)",
|
||||
"refresh": 1,
|
||||
"type": "query"
|
||||
}
|
||||
]
|
||||
},
|
||||
"time": {
|
||||
"from": "now-1h",
|
||||
"to": "now"
|
||||
},
|
||||
"timepicker": {
|
||||
"refresh_intervals": [
|
||||
"5s",
|
||||
"10s",
|
||||
"30s",
|
||||
"1m",
|
||||
"5m",
|
||||
"15m",
|
||||
"30m",
|
||||
"1h",
|
||||
"2h",
|
||||
"1d"
|
||||
]
|
||||
},
|
||||
"title": "V14 Shared Crosshair Migration Test Dashboard"
|
||||
}
|
||||
Loading…
Reference in New Issue