flush influx errors

This commit is contained in:
Cody Lee 2022-12-11 14:37:53 -06:00
parent 6ee728cba6
commit 7b01be9fc6
No known key found for this signature in database
1 changed files with 8 additions and 0 deletions

View File

@ -260,12 +260,14 @@ func (u *InfluxUnifi) ReportMetrics(m *poller.Metrics, e *poller.Events) (*Repor
r.writer = u.influxV2.WriteAPI(u.Org, u.Bucket)
go u.collect(r, r.ch)
go u.drainErrors(r)
// Batch all the points.
u.loopPoints(r)
r.wg.Wait() // wait for all points to finish batching!
// Flush all the points.
r.writer.Flush()
go u.drainErrors(r)
} else {
var err error
@ -292,6 +294,12 @@ func (u *InfluxUnifi) ReportMetrics(m *poller.Metrics, e *poller.Events) (*Repor
return r, nil
}
func (u *InfluxUnifi) drainErrors(r *Report) {
for e := range r.writer.Errors() {
u.LogErrorf("error encountered by influx flush: %v", e)
}
}
// collect runs in a go routine and batches all the points.
func (u *InfluxUnifi) collect(r report, ch chan *metric) {
for m := range ch {