Fix: When sending metrics failed the batch size could be exceeded

This commit is contained in:
Holger Obermaier 2022-06-20 18:06:27 +02:00
parent b732b2d739
commit 580d21d8bb

View File

@ -142,17 +142,20 @@ func (s *InfluxSink) Flush() error {
// Send metrics from batch slice
err := s.writeApi.WritePoint(context.Background(), s.batch...)
if err != nil {
cclog.ComponentError(s.name, "flush failed:", err.Error())
return err
}
// Clear batch slice
// (when sending the metrics failed, metrics get dropped and are lost)
for i := range s.batch {
s.batch[i] = nil
}
s.batch = s.batch[:0]
// Report errors for sending metrics
if err != nil {
cclog.ComponentError(s.name, "flush failed:", err.Error())
return err
}
return nil
}