mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudMigrations: Don't migrate dashboards that are soft-deleted (#90454)
* skip dashboards that are soft-deleted while building snapshots * add unit test
This commit is contained in:
parent
8e4ec47114
commit
83b309c724
@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/grafana/grafana/pkg/api/routing"
|
"github.com/grafana/grafana/pkg/api/routing"
|
||||||
@ -350,6 +351,36 @@ func Test_OnlyQueriesStatusFromGMSWhenRequired(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_DeletedDashboardsNotMigrated(t *testing.T) {
|
||||||
|
s := setUpServiceTest(t, false).(*Service)
|
||||||
|
// modify what the mock returns for just this test case
|
||||||
|
dashMock := s.dashboardService.(*dashboards.FakeDashboardService)
|
||||||
|
dashMock.On("GetAllDashboards", mock.Anything).Return(
|
||||||
|
[]*dashboards.Dashboard{
|
||||||
|
{
|
||||||
|
UID: "1",
|
||||||
|
Data: simplejson.New(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
UID: "2",
|
||||||
|
Data: simplejson.New(),
|
||||||
|
Deleted: time.Now(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
|
||||||
|
data, err := s.getMigrationDataJSON(context.TODO(), &user.SignedInUser{OrgID: 1})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
dashCount := 0
|
||||||
|
for _, it := range data.Items {
|
||||||
|
if it.Type == cloudmigration.DashboardDataType {
|
||||||
|
dashCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.Equal(t, 1, dashCount)
|
||||||
|
}
|
||||||
|
|
||||||
func ctxWithSignedInUser() context.Context {
|
func ctxWithSignedInUser() context.Context {
|
||||||
c := &contextmodel.ReqContext{
|
c := &contextmodel.ReqContext{
|
||||||
SignedInUser: &user.SignedInUser{OrgID: 1},
|
SignedInUser: &user.SignedInUser{OrgID: 1},
|
||||||
@ -400,7 +431,9 @@ func setUpServiceTest(t *testing.T, withDashboardMock bool) cloudmigration.Servi
|
|||||||
|
|
||||||
s, err := ProvideService(
|
s, err := ProvideService(
|
||||||
cfg,
|
cfg,
|
||||||
featuremgmt.WithFeatures(featuremgmt.FlagOnPremToCloudMigrations),
|
featuremgmt.WithFeatures(
|
||||||
|
featuremgmt.FlagOnPremToCloudMigrations,
|
||||||
|
featuremgmt.FlagDashboardRestore),
|
||||||
sqlStore,
|
sqlStore,
|
||||||
dsService,
|
dsService,
|
||||||
secretsService,
|
secretsService,
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/cloudmigration/slicesext"
|
"github.com/grafana/grafana/pkg/services/cloudmigration/slicesext"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/datasources"
|
"github.com/grafana/grafana/pkg/services/datasources"
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/folder"
|
"github.com/grafana/grafana/pkg/services/folder"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/util/retryer"
|
"github.com/grafana/grafana/pkg/util/retryer"
|
||||||
@ -57,7 +58,13 @@ func (s *Service) getMigrationDataJSON(ctx context.Context, signedInUser *user.S
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
softDeleteEnabled := s.features.IsEnabledGlobally(featuremgmt.FlagDashboardRestore)
|
||||||
|
|
||||||
for _, dashboard := range dashboards {
|
for _, dashboard := range dashboards {
|
||||||
|
if softDeleteEnabled && !dashboard.Deleted.IsZero() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
dashboard.Data.Del("id")
|
dashboard.Data.Del("id")
|
||||||
migrationDataSlice = append(migrationDataSlice, cloudmigration.MigrateDataRequestItem{
|
migrationDataSlice = append(migrationDataSlice, cloudmigration.MigrateDataRequestItem{
|
||||||
Type: cloudmigration.DashboardDataType,
|
Type: cloudmigration.DashboardDataType,
|
||||||
|
Loading…
Reference in New Issue
Block a user