mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Add dashboard thumbnails service (#54500)
* Chore: Add dashboard thumbnails service * Fix errors in dashboard thumbs impl * Inject dashboardThumbsService into wire
This commit is contained in:
parent
55fe1506ba
commit
58449d42ed
@ -42,6 +42,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/comments"
|
"github.com/grafana/grafana/pkg/services/comments"
|
||||||
"github.com/grafana/grafana/pkg/services/contexthandler"
|
"github.com/grafana/grafana/pkg/services/contexthandler"
|
||||||
"github.com/grafana/grafana/pkg/services/correlations"
|
"github.com/grafana/grafana/pkg/services/correlations"
|
||||||
|
dashboardThumbs "github.com/grafana/grafana/pkg/services/dashboard_thumbs"
|
||||||
"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/dashboardsnapshots"
|
||||||
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
|
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
|
||||||
@ -182,11 +183,12 @@ type HTTPServer struct {
|
|||||||
apiKeyService apikey.Service
|
apiKeyService apikey.Service
|
||||||
kvStore kvstore.KVStore
|
kvStore kvstore.KVStore
|
||||||
|
|
||||||
userService user.Service
|
userService user.Service
|
||||||
tempUserService tempUser.Service
|
tempUserService tempUser.Service
|
||||||
loginAttemptService loginAttempt.Service
|
dashboardThumbsService dashboardThumbs.Service
|
||||||
orgService org.Service
|
loginAttemptService loginAttempt.Service
|
||||||
accesscontrolService accesscontrol.Service
|
orgService org.Service
|
||||||
|
accesscontrolService accesscontrol.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerOptions struct {
|
type ServerOptions struct {
|
||||||
@ -225,7 +227,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
|||||||
secretsMigrator secrets.Migrator, secretsPluginManager plugins.SecretsPluginManager, secretsService secrets.Service,
|
secretsMigrator secrets.Migrator, secretsPluginManager plugins.SecretsPluginManager, secretsService secrets.Service,
|
||||||
secretsPluginMigrator *spm.SecretMigrationServiceImpl, secretsStore secretsKV.SecretsKVStore,
|
secretsPluginMigrator *spm.SecretMigrationServiceImpl, secretsStore secretsKV.SecretsKVStore,
|
||||||
publicDashboardsApi *publicdashboardsApi.Api, userService user.Service, tempUserService tempUser.Service, loginAttemptService loginAttempt.Service, orgService org.Service,
|
publicDashboardsApi *publicdashboardsApi.Api, userService user.Service, tempUserService tempUser.Service, loginAttemptService loginAttempt.Service, orgService org.Service,
|
||||||
accesscontrolService accesscontrol.Service,
|
accesscontrolService accesscontrol.Service, dashboardThumbsService dashboardThumbs.Service,
|
||||||
) (*HTTPServer, error) {
|
) (*HTTPServer, error) {
|
||||||
web.Env = cfg.Env
|
web.Env = cfg.Env
|
||||||
m := web.New()
|
m := web.New()
|
||||||
@ -317,6 +319,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
|||||||
PublicDashboardsApi: publicDashboardsApi,
|
PublicDashboardsApi: publicDashboardsApi,
|
||||||
userService: userService,
|
userService: userService,
|
||||||
tempUserService: tempUserService,
|
tempUserService: tempUserService,
|
||||||
|
dashboardThumbsService: dashboardThumbsService,
|
||||||
loginAttemptService: loginAttemptService,
|
loginAttemptService: loginAttemptService,
|
||||||
orgService: orgService,
|
orgService: orgService,
|
||||||
accesscontrolService: accesscontrolService,
|
accesscontrolService: accesscontrolService,
|
||||||
|
@ -53,6 +53,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/contexthandler"
|
"github.com/grafana/grafana/pkg/services/contexthandler"
|
||||||
"github.com/grafana/grafana/pkg/services/contexthandler/authproxy"
|
"github.com/grafana/grafana/pkg/services/contexthandler/authproxy"
|
||||||
"github.com/grafana/grafana/pkg/services/correlations"
|
"github.com/grafana/grafana/pkg/services/correlations"
|
||||||
|
"github.com/grafana/grafana/pkg/services/dashboard_thumbs/dashboardthumbsimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboardimport"
|
"github.com/grafana/grafana/pkg/services/dashboardimport"
|
||||||
dashboardimportservice "github.com/grafana/grafana/pkg/services/dashboardimport/service"
|
dashboardimportservice "github.com/grafana/grafana/pkg/services/dashboardimport/service"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
@ -326,6 +327,7 @@ var wireBasicSet = wire.NewSet(
|
|||||||
userimpl.ProvideService,
|
userimpl.ProvideService,
|
||||||
orgimpl.ProvideService,
|
orgimpl.ProvideService,
|
||||||
tempuserimpl.ProvideService,
|
tempuserimpl.ProvideService,
|
||||||
|
dashboardthumbsimpl.ProvideService,
|
||||||
loginattemptimpl.ProvideService,
|
loginattemptimpl.ProvideService,
|
||||||
secretsMigrations.ProvideDataSourceMigrationService,
|
secretsMigrations.ProvideDataSourceMigrationService,
|
||||||
secretsMigrations.ProvideMigrateToPluginService,
|
secretsMigrations.ProvideMigrateToPluginService,
|
||||||
|
15
pkg/services/dashboard_thumbs/dashboard_thumbs.go
Normal file
15
pkg/services/dashboard_thumbs/dashboard_thumbs.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package dashboardthumbs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Service interface {
|
||||||
|
GetThumbnail(ctx context.Context, query *models.GetDashboardThumbnailCommand) (*models.DashboardThumbnail, error)
|
||||||
|
SaveThumbnail(ctx context.Context, cmd *models.SaveDashboardThumbnailCommand) (*models.DashboardThumbnail, error)
|
||||||
|
UpdateThumbnailState(ctx context.Context, cmd *models.UpdateThumbnailStateCommand) error
|
||||||
|
FindThumbnailCount(ctx context.Context, cmd *models.FindDashboardThumbnailCountCommand) (int64, error)
|
||||||
|
FindDashboardsWithStaleThumbnails(ctx context.Context, cmd *models.FindDashboardsWithStaleThumbnailsCommand) ([]*models.DashboardWithStaleThumbnail, error)
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package dashboardthumbsimpl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/models"
|
||||||
|
dashboardthumbs "github.com/grafana/grafana/pkg/services/dashboard_thumbs"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Service struct {
|
||||||
|
// TODO remove sqlstore
|
||||||
|
sqlStore *sqlstore.SQLStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProvideService(
|
||||||
|
ss *sqlstore.SQLStore,
|
||||||
|
) dashboardthumbs.Service {
|
||||||
|
return &Service{
|
||||||
|
sqlStore: ss,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) GetThumbnail(ctx context.Context, query *models.GetDashboardThumbnailCommand) (*models.DashboardThumbnail, error) {
|
||||||
|
dt, err := s.sqlStore.GetThumbnail(ctx, query)
|
||||||
|
if err != nil {
|
||||||
|
return dt, err
|
||||||
|
}
|
||||||
|
return dt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) SaveThumbnail(ctx context.Context, cmd *models.SaveDashboardThumbnailCommand) (*models.DashboardThumbnail, error) {
|
||||||
|
dt, err := s.sqlStore.SaveThumbnail(ctx, cmd)
|
||||||
|
if err != nil {
|
||||||
|
return dt, err
|
||||||
|
}
|
||||||
|
return dt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) UpdateThumbnailState(ctx context.Context, cmd *models.UpdateThumbnailStateCommand) error {
|
||||||
|
err := s.sqlStore.UpdateThumbnailState(ctx, cmd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) FindThumbnailCount(ctx context.Context, cmd *models.FindDashboardThumbnailCountCommand) (int64, error) {
|
||||||
|
i, err := s.sqlStore.FindThumbnailCount(ctx, cmd)
|
||||||
|
if err != nil {
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) FindDashboardsWithStaleThumbnails(ctx context.Context, cmd *models.FindDashboardsWithStaleThumbnailsCommand) ([]*models.DashboardWithStaleThumbnail, error) {
|
||||||
|
d, err := s.sqlStore.FindDashboardsWithStaleThumbnails(ctx, cmd)
|
||||||
|
if err != nil {
|
||||||
|
return d, err
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
package dashboardthumbsimpl
|
@ -0,0 +1 @@
|
|||||||
|
package dashboardthumbsimpl
|
Loading…
Reference in New Issue
Block a user