fix(outputs.wavefront): Flush metric buffer before reaching overflow (#13252)

This commit is contained in:
Andrew St Pierre 2023-05-24 00:54:39 -07:00 committed by GitHub
parent 8fa514f73b
commit 8677dd4097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 12 deletions

View File

@ -123,20 +123,22 @@ func (w *Wavefront) Write(metrics []telegraf.Metric) error {
err := w.sender.SendMetric(point.Metric, point.Value, point.Timestamp, point.Source, point.Tags) err := w.sender.SendMetric(point.Metric, point.Value, point.Timestamp, point.Source, point.Tags)
if err != nil { if err != nil {
if isRetryable(err) { if isRetryable(err) {
if flushErr := w.sender.Flush(); flushErr != nil { // The internal buffer in the Wavefront SDK is full. To prevent data loss,
w.Log.Errorf("wavefront flushing error: %v", flushErr) // we flush the buffer (which is a blocking operation) and try again.
w.Log.Debug("SDK buffer overrun, forcibly flushing the buffer")
if err = w.sender.Flush(); err != nil {
return fmt.Errorf("wavefront flushing error: %w", err)
}
// Try again.
err = w.sender.SendMetric(point.Metric, point.Value, point.Timestamp, point.Source, point.Tags)
if err != nil {
if isRetryable(err) {
return fmt.Errorf("wavefront sending error: %w", err)
}
} }
return fmt.Errorf("wavefront sending error: %w", err)
} }
w.Log.Errorf("non-retryable error during Wavefront.Write: %w", err) w.Log.Errorf("non-retryable error during Wavefront.Write: %v", err)
w.Log.Debugf( w.Log.Debugf("non-retryable metric data: %+v", point)
"Non-retryable metric data: Name: %v, Value: %v, Timestamp: %v, Source: %v, PointTags: %v ",
point.Metric,
point.Value,
point.Timestamp,
point.Source,
point.Tags,
)
} }
} }
} }