Skip to content

Commit

Permalink
Merge pull request #3774 from weaveworks/probe-skip-empty-reports
Browse files Browse the repository at this point in the history
fix (probe): skip publishing empty reports
  • Loading branch information
bboreham authored Apr 2, 2020
2 parents 103b615 + 951d7a1 commit 6f05b09
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -231,7 +233,7 @@ ForLoop:
t.Controls = report.Controls{}
})
}
return rpt
return rpt, count
}

func (p *Probe) publishLoop() {
Expand All @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 6f05b09

Please sign in to comment.