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:
Kat Yang 2022-08-31 16:45:41 -04:00 committed by GitHub
parent 55fe1506ba
commit 58449d42ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 6 deletions

View File

@ -42,6 +42,7 @@ import (
"github.com/grafana/grafana/pkg/services/comments"
"github.com/grafana/grafana/pkg/services/contexthandler"
"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/dashboardsnapshots"
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
@ -182,11 +183,12 @@ type HTTPServer struct {
apiKeyService apikey.Service
kvStore kvstore.KVStore
userService user.Service
tempUserService tempUser.Service
loginAttemptService loginAttempt.Service
orgService org.Service
accesscontrolService accesscontrol.Service
userService user.Service
tempUserService tempUser.Service
dashboardThumbsService dashboardThumbs.Service
loginAttemptService loginAttempt.Service
orgService org.Service
accesscontrolService accesscontrol.Service
}
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,
secretsPluginMigrator *spm.SecretMigrationServiceImpl, secretsStore secretsKV.SecretsKVStore,
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) {
web.Env = cfg.Env
m := web.New()
@ -317,6 +319,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
PublicDashboardsApi: publicDashboardsApi,
userService: userService,
tempUserService: tempUserService,
dashboardThumbsService: dashboardThumbsService,
loginAttemptService: loginAttemptService,
orgService: orgService,
accesscontrolService: accesscontrolService,

View File

@ -53,6 +53,7 @@ import (
"github.com/grafana/grafana/pkg/services/contexthandler"
"github.com/grafana/grafana/pkg/services/contexthandler/authproxy"
"github.com/grafana/grafana/pkg/services/correlations"
"github.com/grafana/grafana/pkg/services/dashboard_thumbs/dashboardthumbsimpl"
"github.com/grafana/grafana/pkg/services/dashboardimport"
dashboardimportservice "github.com/grafana/grafana/pkg/services/dashboardimport/service"
"github.com/grafana/grafana/pkg/services/dashboards"
@ -326,6 +327,7 @@ var wireBasicSet = wire.NewSet(
userimpl.ProvideService,
orgimpl.ProvideService,
tempuserimpl.ProvideService,
dashboardthumbsimpl.ProvideService,
loginattemptimpl.ProvideService,
secretsMigrations.ProvideDataSourceMigrationService,
secretsMigrations.ProvideMigrateToPluginService,

View 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)
}

View File

@ -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
}

View File

@ -0,0 +1 @@
package dashboardthumbsimpl

View File

@ -0,0 +1 @@
package dashboardthumbsimpl