Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Allow migration of empty panel dashboard #1854

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/api/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
"github.com/perses/perses/internal/api/interface"
apiinterface "github.com/perses/perses/internal/api/interface"
"github.com/perses/perses/internal/api/schemas"
"github.com/perses/perses/pkg/model/api/config"
v1 "github.com/perses/perses/pkg/model/api/v1"
Expand Down Expand Up @@ -231,7 +231,7 @@ func rearrangeGrafanaPanelsWithinExpandedRows(grafanaDashboardRaw json.RawMessag
}

// iterate over the panels & achieve recomposition of parent->children relationship when needed
var newPanelList []map[string]any
newPanelList := make([]map[string]any, 0)
var parentRow map[string]any
for _, panelAsAny := range panels {
panel, ok := panelAsAny.(map[string]any)
Expand Down
6 changes: 6 additions & 0 deletions internal/api/migrate/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ func TestMigrate(t *testing.T) {
expectedPersesDashboardFile: "old_grafana_query_perses_dashboard.json",
expectedErrorStr: "",
},
{
title: "dashboard without panels should be migrated without error",
inputGrafanaDashboardFile: "empty_panels_list_grafana_dashboard.json",
expectedPersesDashboardFile: "empty_panels_list_perses_dashboard.json",
expectedErrorStr: "",
},
}

for _, test := range testSuite {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 28,
"links": [],
"panels": [],
"schemaVersion": 39,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timeRangeUpdatedDuringEditOrView": false,
"timepicker": {},
"timezone": "browser",
"title": "test dashboard",
"uid": "ddgn9k36v60owc",
"version": 1,
"weekStart": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"kind":"Dashboard",
"metadata": {
"createdAt":"0001-01-01T00:00:00Z",
"name":"ddgn9k36v60owc",
"project":"",
"updatedAt":"0001-01-01T00:00:00Z",
"version":0
},
"spec": {
"display":{
"name":"test dashboard"
},
"duration":"1h",
"layouts":[],
"panels":{}
}
}
2 changes: 1 addition & 1 deletion pkg/model/api/v1/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (d *DashboardSpec) UnmarshalYAML(unmarshal func(interface{}) error) error {

func (d *DashboardSpec) validate() error {
if len(d.Panels) == 0 {
return fmt.Errorf("spec.panels cannot be empty")
return nil
}
variables := make(map[string]bool, len(d.Variables))
for i, variable := range d.Variables {
Expand Down
14 changes: 0 additions & 14 deletions pkg/model/api/v1/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,20 +524,6 @@ func TestUnmarshalDashboardError(t *testing.T) {
`,
err: fmt.Errorf("spec cannot be empty"),
},
{
title: "panel list cannot be empty",
jason: `
{
"kind": "Dashboard",
"metadata": {
"name": "test",
"project": "perses"
},
"spec": {}
}
`,
err: fmt.Errorf("spec.panels cannot be empty"),
},
}
for _, test := range testSuite {
t.Run(test.title, func(t *testing.T) {
Expand Down
14 changes: 0 additions & 14 deletions pkg/model/api/v1/ephemeraldashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,20 +536,6 @@ func TestUnmarshalEphemeralDashboardError(t *testing.T) {
`,
err: fmt.Errorf("spec cannot be empty"),
},
{
title: "panel list cannot be empty",
jason: `
{
"kind": "EphemeralDashboard",
"metadata": {
"name": "test",
"project": "perses"
},
"spec": {}
}
`,
err: fmt.Errorf("spec.panels cannot be empty"),
},
}
for _, test := range testSuite {
t.Run(test.title, func(t *testing.T) {
Expand Down
Loading