fix(outputs.mqtt): Retry metrics for server timeout (#14752)

This commit is contained in:
Sven Rebhan 2024-02-12 21:34:50 +01:00 committed by GitHub
parent db831793a5
commit d8cd59c0cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 0 deletions

View File

@ -167,6 +167,11 @@ func (m *MQTT) Write(metrics []telegraf.Metric) error {
for _, msg := range topicMessages {
if err := m.client.Publish(msg.topic, msg.payload); err != nil {
// We do receive a timeout error if the remote broker is down,
// so let's retry the metrics in this case and drop them otherwise.
if errors.Is(err, internal.ErrTimeout) {
return fmt.Errorf("could not publish message to MQTT server: %w", err)
}
m.Log.Warnf("Could not publish message to MQTT server: %v", err)
}
}