DashboardStore: Use ReplDB and get dashboard quotas from the ReadReplica (#90235)

* Use ReplDB in dashboard store and update all fixtures - no other changes

* just moving dashboard counts for now

* find the missing test fixture
This commit is contained in:
Kristin Laemmert
2024-07-12 10:47:49 -04:00
committed by GitHub
parent e64ef2245c
commit 8a6107cd35
35 changed files with 256 additions and 244 deletions
@@ -85,7 +85,7 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
Title: "Testing ConnectLibraryPanelsForDashboard",
Data: simplejson.NewFromAny(dashJSON),
}
dashInDB := createDashboard(t, sc.sqlStore, sc.user, &dash)
dashInDB := createDashboard(t, sc.replStore, sc.user, &dash)
err := sc.service.ConnectLibraryPanelsForDashboard(sc.ctx, sc.user, dashInDB)
require.NoError(t, err)
@@ -183,7 +183,7 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
Title: "Testing ConnectLibraryPanelsForDashboard",
Data: simplejson.NewFromAny(dashJSON),
}
dashInDB := createDashboard(t, sc.sqlStore, sc.user, &dash)
dashInDB := createDashboard(t, sc.replStore, sc.user, &dash)
err = sc.service.ConnectLibraryPanelsForDashboard(sc.ctx, sc.user, dashInDB)
require.NoError(t, err)
@@ -229,7 +229,7 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
Title: "Testing ConnectLibraryPanelsForDashboard",
Data: simplejson.NewFromAny(dashJSON),
}
dashInDB := createDashboard(t, sc.sqlStore, sc.user, &dash)
dashInDB := createDashboard(t, sc.replStore, sc.user, &dash)
err := sc.service.ConnectLibraryPanelsForDashboard(sc.ctx, sc.user, dashInDB)
require.EqualError(t, err, errLibraryPanelHeaderUIDMissing.Error())
@@ -285,7 +285,7 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
Title: "Testing ConnectLibraryPanelsForDashboard",
Data: simplejson.NewFromAny(dashJSON),
}
dashInDB := createDashboard(t, sc.sqlStore, sc.user, &dash)
dashInDB := createDashboard(t, sc.replStore, sc.user, &dash)
err = sc.elementService.ConnectElementsToDashboard(sc.ctx, sc.user, []string{sc.initialResult.Result.UID}, dashInDB.ID)
require.NoError(t, err)
@@ -636,6 +636,7 @@ type scenarioContext struct {
folder *folder.Folder
initialResult libraryPanelResult
sqlStore db.DB
replStore db.ReplDB
lps LibraryPanelService
}
@@ -712,7 +713,7 @@ func getExpected(t *testing.T, res model.LibraryElementDTO, UID string, name str
}
}
func createDashboard(t *testing.T, sqlStore db.DB, user *user.SignedInUser, dash *dashboards.Dashboard) *dashboards.Dashboard {
func createDashboard(t *testing.T, sqlStore db.ReplDB, user *user.SignedInUser, dash *dashboards.Dashboard) *dashboards.Dashboard {
dashItem := &dashboards.SaveDashboardDTO{
Dashboard: dash,
Message: "",
@@ -724,10 +725,10 @@ func createDashboard(t *testing.T, sqlStore db.DB, user *user.SignedInUser, dash
features := featuremgmt.WithFeatures()
cfg := setting.NewCfg()
quotaService := quotatest.New(false, nil)
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, features, tagimpl.ProvideService(sqlStore.DB()), quotaService)
require.NoError(t, err)
ac := actest.FakeAccessControl{ExpectedEvaluate: true}
folderStore := folderimpl.ProvideDashboardFolderStore(sqlStore)
folderStore := folderimpl.ProvideDashboardFolderStore(sqlStore.DB())
dashPermissionService := acmock.NewMockedPermissionsService()
dashPermissionService.On("SetPermissions", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]accesscontrol.ResourcePermission{}, nil)
service, err := dashboardservice.ProvideDashboardServiceImpl(
@@ -750,7 +751,7 @@ func createFolder(t *testing.T, sc scenarioContext, title string) *folder.Folder
ac := actest.FakeAccessControl{ExpectedEvaluate: true}
cfg := setting.NewCfg()
quotaService := quotatest.New(false, nil)
dashboardStore, err := database.ProvideDashboardStore(sc.sqlStore, cfg, features, tagimpl.ProvideService(sc.sqlStore), quotaService)
dashboardStore, err := database.ProvideDashboardStore(sc.replStore, cfg, features, tagimpl.ProvideService(sc.sqlStore), quotaService)
require.NoError(t, err)
folderStore := folderimpl.ProvideDashboardFolderStore(sc.sqlStore)
s := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, sc.sqlStore, features, supportbundlestest.NewFakeBundleService(), nil)
@@ -815,7 +816,8 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
t.Run(desc, func(t *testing.T) {
orgID := int64(1)
role := org.RoleAdmin
sqlStore, cfg := db.InitTestDBWithCfg(t)
replStore, cfg := db.InitTestReplDBWithCfg(t)
sqlStore := replStore.DB()
quotaService := quotatest.New(false, nil)
ac := actest.FakeAccessControl{ExpectedEvaluate: true}
@@ -832,7 +834,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
require.NoError(t, err)
guardian.InitAccessControlGuardian(setting.NewCfg(), ac, dashService)
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
dashboardStore, err := database.ProvideDashboardStore(replStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
require.NoError(t, err)
features := featuremgmt.WithFeatures()
folderService := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil)
@@ -885,6 +887,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
service: &service,
elementService: elementService,
sqlStore: sqlStore,
replStore: replStore,
lps: service,
}