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

fix initialization data race in usagestats
This commit is contained in:
Diego Augusto Molina
2024-10-02 07:30:44 -03:00
committed by GitHub
parent a7497ae846
commit 658c79e1d5
+4 -3
View File
@@ -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 {