Chore: fix initialization data race in infra usagestats (#94070)

fix initialization data race in usagestats
pull/93810/head
Diego Augusto Molina 9 months ago committed by GitHub
parent a7497ae846
commit 658c79e1d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      pkg/infra/usagestats/service/service.go

@ -3,6 +3,7 @@ package service
import (
"context"
"encoding/json"
"sync/atomic"
"time"
"github.com/grafana/grafana/pkg/api/routing"
@ -27,7 +28,7 @@ type UsageStats struct {
externalMetrics []usagestats.MetricsFunc
sendReportCallbacks []usagestats.SendReportCallbackFunc
readyToReport bool
readyToReport atomic.Bool
}
func ProvideService(cfg *setting.Cfg,
@ -79,7 +80,7 @@ func (uss *UsageStats) Run(ctx context.Context) error {
for {
select {
case <-sendReportTicker.C:
if !uss.readyToReport {
if !uss.readyToReport.Load() {
nextSendInterval = time.Minute
sendReportTicker.Reset(nextSendInterval)
continue
@ -114,7 +115,7 @@ func (uss *UsageStats) RegisterSendReportCallback(c usagestats.SendReportCallbac
func (uss *UsageStats) SetReadyToReport(context.Context) {
uss.log.Info("Usage stats are ready to report")
uss.readyToReport = true
uss.readyToReport.Store(true)
}
func (uss *UsageStats) supportBundleCollector() supportbundles.Collector {

Loading…
Cancel
Save