From c7719ac36530dee844dbcaa57393a54436dc8f7f Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Tue, 26 Apr 2016 10:25:04 -0600 Subject: [PATCH] buffers: fix bug when Write called before AddMetric --- internal/models/running_output.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/models/running_output.go b/internal/models/running_output.go index 91b200799..cab5035f6 100644 --- a/internal/models/running_output.go +++ b/internal/models/running_output.go @@ -124,6 +124,17 @@ func (ro *RunningOutput) Write() error { ro.Lock() defer ro.Unlock() + if ro.tmpmetrics == nil { + size := ro.MetricBufferLimit / ro.MetricBatchSize + // ro.metrics already contains one batch + size = size - 1 + + if size < 1 { + size = 1 + } + ro.tmpmetrics = make([]([]telegraf.Metric), size) + } + // Write any cached metric buffers before, as those metrics are the // oldest for ro.tmpmetrics[ro.readI] != nil {