mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Licensing: supplies a service to handle licensing information * Licensing: uses the license service further Uses the license service instead of settings.isEnterprise: - external team members - saml - usage stats * Licensing: fixes broken tests due to new Licensing service dependency * Licensing: fixes linting errors * Licensing: exposes license expiry information to the frontend
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package usagestats
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
"github.com/grafana/grafana/pkg/login/social"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/registry"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
var metricsLogger log.Logger = log.New("metrics")
|
|
|
|
func init() {
|
|
registry.RegisterService(&UsageStatsService{})
|
|
}
|
|
|
|
type UsageStatsService struct {
|
|
Cfg *setting.Cfg `inject:""`
|
|
Bus bus.Bus `inject:""`
|
|
SQLStore *sqlstore.SqlStore `inject:""`
|
|
License models.Licensing `inject:""`
|
|
|
|
oauthProviders map[string]bool
|
|
}
|
|
|
|
func (uss *UsageStatsService) Init() error {
|
|
|
|
uss.oauthProviders = social.GetOAuthProviders(uss.Cfg)
|
|
return nil
|
|
}
|
|
|
|
func (uss *UsageStatsService) Run(ctx context.Context) error {
|
|
uss.updateTotalStats()
|
|
|
|
onceEveryDayTick := time.NewTicker(time.Hour * 24)
|
|
everyMinuteTicker := time.NewTicker(time.Minute)
|
|
defer onceEveryDayTick.Stop()
|
|
defer everyMinuteTicker.Stop()
|
|
|
|
for {
|
|
select {
|
|
case <-onceEveryDayTick.C:
|
|
uss.sendUsageStats(uss.oauthProviders)
|
|
case <-everyMinuteTicker.C:
|
|
uss.updateTotalStats()
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
}
|
|
}
|
|
}
|