From 951d7a14128b535cd06bbe75e101eb31a0f776df Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 26 Mar 2020 20:23:43 +0000 Subject: [PATCH] fix (probe): skip publishing empty reports If the probe is configured with `spy.interval` greater than `publish.interval`, the report to be published can be completely blank. In that case, skip publishing it so the next time we do have some data the time-window is correct. --- probe/probe.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/probe/probe.go b/probe/probe.go index e54ec6c845..d5834fdcb4 100644 --- a/probe/probe.go +++ b/probe/probe.go @@ -213,14 +213,16 @@ func (p *Probe) tag(r report.Report) report.Report { return r } -func (p *Probe) drainAndSanitise(rpt report.Report, rs chan report.Report) report.Report { +func (p *Probe) drainAndSanitise(rpt report.Report, rs chan report.Report) (report.Report, int) { p.rateLimiter.Wait(context.Background()) rpt = rpt.Copy() + count := 0 ForLoop: for { select { case r := <-rs: rpt.UnsafeMerge(r) + count++ default: break ForLoop } @@ -231,7 +233,7 @@ ForLoop: t.Controls = report.Controls{} }) } - return rpt + return rpt, count } func (p *Probe) publishLoop() { @@ -245,7 +247,11 @@ func (p *Probe) publishLoop() { var err error select { case <-pubTick: - rpt := p.drainAndSanitise(report.MakeReport(), p.spiedReports) + rpt, count := p.drainAndSanitise(report.MakeReport(), p.spiedReports) + if count == 0 { + continue // No data has been collected - don't bother publishing. + } + fullReport := (publishCount % p.ticksPerFullReport) == 0 if !fullReport { rpt.UnsafeUnMerge(lastFullReport) @@ -264,7 +270,7 @@ func (p *Probe) publishLoop() { } case rpt := <-p.shortcutReports: - rpt = p.drainAndSanitise(rpt, p.shortcutReports) + rpt, _ = p.drainAndSanitise(rpt, p.shortcutReports) err = p.publisher.Publish(rpt) case <-p.quit: