mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 23:12:30 +08:00
add dashboardsnap as service of http server (#45461)
This commit is contained in:
@ -133,7 +133,7 @@ func (hs *HTTPServer) CreateDashboardSnapshot(c *models.ReqContext) response.Res
|
|||||||
metrics.MApiDashboardSnapshotCreate.Inc()
|
metrics.MApiDashboardSnapshotCreate.Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := hs.SQLStore.CreateDashboardSnapshot(c.Req.Context(), &cmd); err != nil {
|
if err := hs.DashboardsnapshotsService.CreateDashboardSnapshot(c.Req.Context(), &cmd); err != nil {
|
||||||
c.JsonApiErr(500, "Failed to create snapshot", err)
|
c.JsonApiErr(500, "Failed to create snapshot", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ func (hs *HTTPServer) GetDashboardSnapshot(c *models.ReqContext) response.Respon
|
|||||||
|
|
||||||
query := &models.GetDashboardSnapshotQuery{Key: key}
|
query := &models.GetDashboardSnapshotQuery{Key: key}
|
||||||
|
|
||||||
err := hs.SQLStore.GetDashboardSnapshot(query)
|
err := hs.DashboardsnapshotsService.GetDashboardSnapshot(c.Req.Context(), query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.Error(500, "Failed to get dashboard snapshot", err)
|
return response.Error(500, "Failed to get dashboard snapshot", err)
|
||||||
}
|
}
|
||||||
@ -224,8 +224,7 @@ func (hs *HTTPServer) DeleteDashboardSnapshotByDeleteKey(c *models.ReqContext) r
|
|||||||
}
|
}
|
||||||
|
|
||||||
query := &models.GetDashboardSnapshotQuery{DeleteKey: key}
|
query := &models.GetDashboardSnapshotQuery{DeleteKey: key}
|
||||||
|
err := hs.DashboardsnapshotsService.GetDashboardSnapshot(c.Req.Context(), query)
|
||||||
err := hs.SQLStore.GetDashboardSnapshot(query)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.Error(500, "Failed to get dashboard snapshot", err)
|
return response.Error(500, "Failed to get dashboard snapshot", err)
|
||||||
}
|
}
|
||||||
@ -239,7 +238,7 @@ func (hs *HTTPServer) DeleteDashboardSnapshotByDeleteKey(c *models.ReqContext) r
|
|||||||
|
|
||||||
cmd := &models.DeleteDashboardSnapshotCommand{DeleteKey: query.Result.DeleteKey}
|
cmd := &models.DeleteDashboardSnapshotCommand{DeleteKey: query.Result.DeleteKey}
|
||||||
|
|
||||||
if err := hs.SQLStore.DeleteDashboardSnapshot(c.Req.Context(), cmd); err != nil {
|
if err := hs.DashboardsnapshotsService.DeleteDashboardSnapshot(c.Req.Context(), cmd); err != nil {
|
||||||
return response.Error(500, "Failed to delete dashboard snapshot", err)
|
return response.Error(500, "Failed to delete dashboard snapshot", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +257,7 @@ func (hs *HTTPServer) DeleteDashboardSnapshot(c *models.ReqContext) response.Res
|
|||||||
|
|
||||||
query := &models.GetDashboardSnapshotQuery{Key: key}
|
query := &models.GetDashboardSnapshotQuery{Key: key}
|
||||||
|
|
||||||
err := hs.SQLStore.GetDashboardSnapshot(query)
|
err := hs.DashboardsnapshotsService.GetDashboardSnapshot(c.Req.Context(), query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.Error(500, "Failed to get dashboard snapshot", err)
|
return response.Error(500, "Failed to get dashboard snapshot", err)
|
||||||
}
|
}
|
||||||
@ -287,7 +286,7 @@ func (hs *HTTPServer) DeleteDashboardSnapshot(c *models.ReqContext) response.Res
|
|||||||
|
|
||||||
cmd := &models.DeleteDashboardSnapshotCommand{DeleteKey: query.Result.DeleteKey}
|
cmd := &models.DeleteDashboardSnapshotCommand{DeleteKey: query.Result.DeleteKey}
|
||||||
|
|
||||||
if err := hs.SQLStore.DeleteDashboardSnapshot(c.Req.Context(), cmd); err != nil {
|
if err := hs.DashboardsnapshotsService.DeleteDashboardSnapshot(c.Req.Context(), cmd); err != nil {
|
||||||
return response.Error(500, "Failed to delete dashboard snapshot", err)
|
return response.Error(500, "Failed to delete dashboard snapshot", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,7 +312,7 @@ func (hs *HTTPServer) SearchDashboardSnapshots(c *models.ReqContext) response.Re
|
|||||||
SignedInUser: c.SignedInUser,
|
SignedInUser: c.SignedInUser,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := hs.SQLStore.SearchDashboardSnapshots(&searchQuery)
|
err := hs.DashboardsnapshotsService.SearchDashboardSnapshots(c.Req.Context(), &searchQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.Error(500, "Search failed", err)
|
return response.Error(500, "Search failed", err)
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
|
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -33,7 +34,7 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
|
|||||||
editorRole := models.ROLE_EDITOR
|
editorRole := models.ROLE_EDITOR
|
||||||
sqlmock := mockstore.NewSQLStoreMock()
|
sqlmock := mockstore.NewSQLStoreMock()
|
||||||
aclMockResp := []*models.DashboardAclInfoDTO{}
|
aclMockResp := []*models.DashboardAclInfoDTO{}
|
||||||
hs := &HTTPServer{SQLStore: sqlmock}
|
hs := &HTTPServer{DashboardsnapshotsService: &dashboardsnapshots.Service{SQLStore: sqlmock}}
|
||||||
|
|
||||||
setUpSnapshotTest := func(t *testing.T) *models.DashboardSnapshot {
|
setUpSnapshotTest := func(t *testing.T) *models.DashboardSnapshot {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/cleanup"
|
"github.com/grafana/grafana/pkg/services/cleanup"
|
||||||
"github.com/grafana/grafana/pkg/services/contexthandler"
|
"github.com/grafana/grafana/pkg/services/contexthandler"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
|
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
|
||||||
"github.com/grafana/grafana/pkg/services/datasourceproxy"
|
"github.com/grafana/grafana/pkg/services/datasourceproxy"
|
||||||
"github.com/grafana/grafana/pkg/services/datasources"
|
"github.com/grafana/grafana/pkg/services/datasources"
|
||||||
"github.com/grafana/grafana/pkg/services/encryption"
|
"github.com/grafana/grafana/pkg/services/encryption"
|
||||||
@ -136,6 +137,7 @@ type HTTPServer struct {
|
|||||||
folderService dashboards.FolderService
|
folderService dashboards.FolderService
|
||||||
DatasourcePermissionsService DatasourcePermissionsService
|
DatasourcePermissionsService DatasourcePermissionsService
|
||||||
AlertNotificationService *alerting.AlertNotificationService
|
AlertNotificationService *alerting.AlertNotificationService
|
||||||
|
DashboardsnapshotsService *dashboardsnapshots.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerOptions struct {
|
type ServerOptions struct {
|
||||||
@ -166,6 +168,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
|||||||
notificationService *notifications.NotificationService, dashboardService dashboards.DashboardService,
|
notificationService *notifications.NotificationService, dashboardService dashboards.DashboardService,
|
||||||
dashboardProvisioningService dashboards.DashboardProvisioningService, folderService dashboards.FolderService,
|
dashboardProvisioningService dashboards.DashboardProvisioningService, folderService dashboards.FolderService,
|
||||||
datasourcePermissionsService DatasourcePermissionsService, alertNotificationService *alerting.AlertNotificationService,
|
datasourcePermissionsService DatasourcePermissionsService, alertNotificationService *alerting.AlertNotificationService,
|
||||||
|
dashboardsnapshotsService *dashboardsnapshots.Service,
|
||||||
) (*HTTPServer, error) {
|
) (*HTTPServer, error) {
|
||||||
web.Env = cfg.Env
|
web.Env = cfg.Env
|
||||||
m := web.New()
|
m := web.New()
|
||||||
@ -232,6 +235,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
|||||||
folderService: folderService,
|
folderService: folderService,
|
||||||
DatasourcePermissionsService: datasourcePermissionsService,
|
DatasourcePermissionsService: datasourcePermissionsService,
|
||||||
AlertNotificationService: alertNotificationService,
|
AlertNotificationService: alertNotificationService,
|
||||||
|
DashboardsnapshotsService: dashboardsnapshotsService,
|
||||||
}
|
}
|
||||||
if hs.Listener != nil {
|
if hs.Listener != nil {
|
||||||
hs.log.Debug("Using provided listener")
|
hs.log.Debug("Using provided listener")
|
||||||
|
@ -12,11 +12,11 @@ import (
|
|||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
Bus bus.Bus
|
Bus bus.Bus
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore sqlstore.Store
|
||||||
SecretsService secrets.Service
|
SecretsService secrets.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProvideService(bus bus.Bus, store *sqlstore.SQLStore, secretsService secrets.Service) *Service {
|
func ProvideService(bus bus.Bus, store sqlstore.Store, secretsService secrets.Service) *Service {
|
||||||
s := &Service{
|
s := &Service{
|
||||||
Bus: bus,
|
Bus: bus,
|
||||||
SQLStore: store,
|
SQLStore: store,
|
||||||
|
Reference in New Issue
Block a user