mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Add Usage stats providers registry (#48357)
* add usage stats providers * migrate thumbnails service to `registry.ProvidesUsageStats` * snake -> camel * lint fix * migrate accesscontrol to `registry.ProvidesUsageStats` * add accesscontrol to usage stats providers registry * fix test * added a note about errors
This commit is contained in:
@@ -11,6 +11,10 @@ import (
|
||||
// When the feature flag is not enabled we just implement a dummy service
|
||||
type dummyService struct{}
|
||||
|
||||
func (ds *dummyService) GetUsageStats(ctx context.Context) map[string]interface{} {
|
||||
return make(map[string]interface{})
|
||||
}
|
||||
|
||||
func (ds *dummyService) GetImage(c *models.ReqContext) {
|
||||
c.JSON(400, map[string]string{"error": "invalid size"})
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/serverlock"
|
||||
"github.com/grafana/grafana/pkg/infra/usagestats"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/registry"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/live"
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
registry.ProvidesUsageStats
|
||||
Run(ctx context.Context) error
|
||||
Enabled() bool
|
||||
GetImage(c *models.ReqContext)
|
||||
@@ -50,7 +51,6 @@ type thumbService struct {
|
||||
store sqlstore.Store
|
||||
crawlLockServiceActionName string
|
||||
log log.Logger
|
||||
usageStatsService usagestats.Service
|
||||
canRunCrawler bool
|
||||
settings setting.DashboardPreviewsSettings
|
||||
}
|
||||
@@ -65,7 +65,7 @@ type crawlerScheduleOptions struct {
|
||||
auth CrawlerAuth
|
||||
}
|
||||
|
||||
func ProvideService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, lockService *serverlock.ServerLockService, renderService rendering.Service, gl *live.GrafanaLive, store *sqlstore.SQLStore, authSetupService CrawlerAuthSetupService, usageStatsService usagestats.Service) Service {
|
||||
func ProvideService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, lockService *serverlock.ServerLockService, renderService rendering.Service, gl *live.GrafanaLive, store *sqlstore.SQLStore, authSetupService CrawlerAuthSetupService) Service {
|
||||
if !features.IsEnabled(featuremgmt.FlagDashboardPreviews) {
|
||||
return &dummyService{}
|
||||
}
|
||||
@@ -81,7 +81,6 @@ func ProvideService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, lockS
|
||||
canRunCrawler = false
|
||||
}
|
||||
t := &thumbService{
|
||||
usageStatsService: usageStatsService,
|
||||
renderingService: renderService,
|
||||
renderer: newSimpleCrawler(renderService, gl, thumbnailRepo, cfg, cfg.DashboardPreviews),
|
||||
thumbnailRepo: thumbnailRepo,
|
||||
@@ -104,26 +103,23 @@ func ProvideService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, lockS
|
||||
},
|
||||
}
|
||||
|
||||
t.registerUsageStats()
|
||||
return t
|
||||
}
|
||||
|
||||
func (hs *thumbService) registerUsageStats() {
|
||||
hs.usageStatsService.RegisterMetricsFunc(func(ctx context.Context) (map[string]interface{}, error) {
|
||||
s := hs.getDashboardPreviewsSetupSettings(ctx)
|
||||
func (hs *thumbService) GetUsageStats(ctx context.Context) map[string]interface{} {
|
||||
s := hs.getDashboardPreviewsSetupSettings(ctx)
|
||||
|
||||
stats := make(map[string]interface{})
|
||||
stats := make(map[string]interface{})
|
||||
|
||||
if s.SystemRequirements.Met {
|
||||
stats["stats.dashboard_previews.system_req_met.count"] = 1
|
||||
}
|
||||
if s.SystemRequirements.Met {
|
||||
stats["stats.dashboard_previews.system_req_met.count"] = 1
|
||||
}
|
||||
|
||||
if s.ThumbnailsExist {
|
||||
stats["stats.dashboard_previews.thumbnails_exist.count"] = 1
|
||||
}
|
||||
if s.ThumbnailsExist {
|
||||
stats["stats.dashboard_previews.thumbnails_exist.count"] = 1
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
})
|
||||
return stats
|
||||
}
|
||||
|
||||
func (hs *thumbService) Enabled() bool {
|
||||
|
||||
Reference in New Issue
Block a user