MCPcopy
hub / github.com/grafana/tempo / running

Method running

pkg/usagestats/reporter.go:248–286  ·  view source on GitHub ↗

running inits the reporter seed and start sending report for every interval

(ctx context.Context)

Source from the content-addressed store, hash-verified

246
247// running inits the reporter seed and start sending report for every interval
248func (rep *Reporter) running(ctx context.Context) error {
249 rep.init(ctx)
250
251 if rep.cluster == nil {
252 <-ctx.Done()
253 return ctx.Err()
254 }
255 // check every minute if we should report.
256 ticker := time.NewTicker(reportCheckInterval)
257 defer ticker.Stop()
258
259 // find when to send the next report.
260 next := nextReport(reportInterval, rep.cluster.CreatedAt, time.Now())
261 if rep.lastReport.IsZero() {
262 // if we never reported assumed it was the last interval.
263 rep.lastReport = next.Add(-reportInterval)
264 }
265 for {
266 select {
267 case <-ticker.C:
268 now := time.Now()
269 if !next.Equal(now) && now.Sub(rep.lastReport) < reportInterval {
270 continue
271 }
272 level.Info(rep.logger).Log("msg", "reporting cluster stats", "date", time.Now())
273 if err := rep.reportUsage(ctx, next); err != nil {
274 level.Info(rep.logger).Log("msg", "failed to report usage", "err", err)
275 continue
276 }
277 rep.lastReport = next
278 next = next.Add(reportInterval)
279 case <-ctx.Done():
280 if errors.Is(ctx.Err(), context.Canceled) {
281 return nil
282 }
283 return ctx.Err()
284 }
285 }
286}
287
288// reportUsage reports the usage to grafana.com.
289func (rep *Reporter) reportUsage(ctx context.Context, interval time.Time) error {

Callers 2

Test_ReportLoopFunction · 0.95
TestWrongKVFunction · 0.95

Calls 9

initMethod · 0.95
reportUsageMethod · 0.95
nextReportFunction · 0.85
DoneMethod · 0.65
StopMethod · 0.65
NowMethod · 0.65
AddMethod · 0.65
LogMethod · 0.65
EqualMethod · 0.45

Tested by 2

Test_ReportLoopFunction · 0.76
TestWrongKVFunction · 0.76