Chore: Fix grafana live stats reset when sending usage stats (#39558)

This commit is contained in:
Tania B
2021-09-23 12:55:00 +03:00
committed by GitHub
parent 65d79d9a30
commit b9acdce837
6 changed files with 24 additions and 2 deletions
+3
View File
@@ -17,8 +17,11 @@ type Report struct {
type MetricsFunc func() (map[string]interface{}, error)
type SendReportCallbackFunc func()
type Service interface {
GetUsageReport(context.Context) (Report, error)
RegisterMetricsFunc(MetricsFunc)
RegisterSendReportCallback(SendReportCallbackFunc)
ShouldBeReported(string) bool
}
+9
View File
@@ -29,6 +29,7 @@ type UsageStats struct {
externalMetrics []usagestats.MetricsFunc
concurrentUserStatsCache memoConcurrentUserStats
startTime time.Time
sendReportCallbacks []usagestats.SendReportCallbackFunc
}
func ProvideService(cfg *setting.Cfg, bus bus.Bus, sqlStore *sqlstore.SQLStore, pluginManager plugins.Manager,
@@ -91,6 +92,10 @@ func (uss *UsageStats) Run(ctx context.Context) error {
nextSendInterval = sendInterval
sendReportTicker.Reset(nextSendInterval)
}
for _, callback := range uss.sendReportCallbacks {
callback()
}
case <-updateStatsTicker.C:
uss.updateTotalStats()
case <-ctx.Done():
@@ -138,3 +143,7 @@ FROM (select count(1) as tokens from user_auth_token group by user_id) uat;`
uss.concurrentUserStatsCache.memoized = time.Now()
return uss.concurrentUserStatsCache.stats, nil
}
func (uss *UsageStats) RegisterSendReportCallback(c usagestats.SendReportCallbackFunc) {
uss.sendReportCallbacks = append(uss.sendReportCallbacks, c)
}