Introduce TSDB service (#31520)

* Introduce TSDB service

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
Co-authored-by: Will Browne <will.browne@grafana.com>
Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
Arve Knudsen
2021-03-08 07:02:49 +01:00
committed by GitHub
co-authored by Erik Sundell Will Browne Torkel Ödegaard Will Browne Zoltán Bedi
parent c899bf3592
commit b79e61656a
203 changed files with 5269 additions and 4776 deletions
@@ -8,6 +8,7 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/guardian"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
@@ -34,11 +35,11 @@ func TestIntegratedDashboardService(t *testing.T) {
return nil
})
savedFolder := saveTestFolder("Saved folder", testOrgId)
savedDashInFolder := saveTestDashboard("Saved dash in folder", testOrgId, savedFolder.Id)
saveTestDashboard("Other saved dash in folder", testOrgId, savedFolder.Id)
savedDashInGeneralFolder := saveTestDashboard("Saved dashboard in general folder", testOrgId, 0)
otherSavedFolder := saveTestFolder("Other saved folder", testOrgId)
savedFolder := saveTestFolder(t, "Saved folder", testOrgId)
savedDashInFolder := saveTestDashboard(t, "Saved dash in folder", testOrgId, savedFolder.Id)
saveTestDashboard(t, "Other saved dash in folder", testOrgId, savedFolder.Id)
savedDashInGeneralFolder := saveTestDashboard(t, "Saved dashboard in general folder", testOrgId, 0)
otherSavedFolder := saveTestFolder(t, "Other saved folder", testOrgId)
Convey("Should return dashboard model", func() {
So(savedFolder.Title, ShouldEqual, "Saved folder")
@@ -110,7 +111,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: false,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
Convey("It should create a new dashboard in organization B", func() {
So(res, ShouldNotBeNil)
@@ -385,7 +386,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
So(res, ShouldNotBeNil)
Convey("It should create a new dashboard", func() {
@@ -409,7 +410,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
So(res, ShouldNotBeNil)
Convey("It should create a new dashboard", func() {
@@ -434,7 +435,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
So(res, ShouldNotBeNil)
Convey("It should create a new folder", func() {
@@ -459,7 +460,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
So(res, ShouldNotBeNil)
Convey("It should create a new dashboard", func() {
@@ -484,7 +485,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
So(res, ShouldNotBeNil)
Convey("It should create a new dashboard", func() {
@@ -545,7 +546,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
So(res, ShouldNotBeNil)
Convey("It should update dashboard", func() {
@@ -590,7 +591,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
So(res, ShouldNotBeNil)
Convey("It should update dashboard", func() {
@@ -676,7 +677,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
So(res, ShouldNotBeNil)
Convey("It should update dashboard", func() {
@@ -701,7 +702,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
So(res, ShouldNotBeNil)
Convey("It should update dashboard", func() {
@@ -726,7 +727,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
Convey("It should update dashboard", func() {
So(res, ShouldNotBeNil)
@@ -772,7 +773,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
Convey("It should overwrite existing dashboard", func() {
So(res, ShouldNotBeNil)
@@ -799,7 +800,7 @@ func TestIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
res := callSaveWithResult(cmd)
res := callSaveWithResult(t, cmd)
Convey("It should overwrite existing dashboard", func() {
So(res, ShouldNotBeNil)
@@ -962,19 +963,25 @@ func permissionScenario(desc string, canSave bool, fn dashboardPermissionScenari
dashboardPermissionScenario(desc, mock, fn)
}
func callSaveWithResult(cmd models.SaveDashboardCommand) *models.Dashboard {
func callSaveWithResult(t *testing.T, cmd models.SaveDashboardCommand) *models.Dashboard {
t.Helper()
dto := toSaveDashboardDto(cmd)
res, _ := dashboards.NewService().SaveDashboard(&dto, false)
res, err := dashboards.NewService(nil).SaveDashboard(&dto, false)
require.NoError(t, err)
return res
}
func callSaveWithError(cmd models.SaveDashboardCommand) error {
dto := toSaveDashboardDto(cmd)
_, err := dashboards.NewService().SaveDashboard(&dto, false)
_, err := dashboards.NewService(nil).SaveDashboard(&dto, false)
return err
}
func saveTestDashboard(title string, orgId int64, folderId int64) *models.Dashboard {
func saveTestDashboard(t *testing.T, title string, orgId int64, folderId int64) *models.Dashboard {
t.Helper()
cmd := models.SaveDashboardCommand{
OrgId: orgId,
FolderId: folderId,
@@ -994,13 +1001,14 @@ func saveTestDashboard(title string, orgId int64, folderId int64) *models.Dashbo
},
}
res, err := dashboards.NewService().SaveDashboard(&dto, false)
So(err, ShouldBeNil)
res, err := dashboards.NewService(nil).SaveDashboard(&dto, false)
require.NoError(t, err)
return res
}
func saveTestFolder(title string, orgId int64) *models.Dashboard {
func saveTestFolder(t *testing.T, title string, orgId int64) *models.Dashboard {
t.Helper()
cmd := models.SaveDashboardCommand{
OrgId: orgId,
FolderId: 0,
@@ -1020,8 +1028,8 @@ func saveTestFolder(title string, orgId int64) *models.Dashboard {
},
}
res, err := dashboards.NewService().SaveDashboard(&dto, false)
So(err, ShouldBeNil)
res, err := dashboards.NewService(nil).SaveDashboard(&dto, false)
require.NoError(t, err)
return res
}