Skip to content

Commit

Permalink
fix(outputs.kafka): Simplify send-error handling (#14154)
Browse files Browse the repository at this point in the history
(cherry picked from commit fd773b3)
  • Loading branch information
srebhan authored and powersj committed Oct 23, 2023
1 parent 8f5aeeb commit 6e444f6
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions plugins/outputs/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,21 @@ func (k *Kafka) Write(metrics []telegraf.Metric) error {
if err != nil {
// We could have many errors, return only the first encountered.
var errs sarama.ProducerErrors
if errors.As(err, &errs) {
for _, prodErr := range errs {
if errors.Is(prodErr.Err, sarama.ErrMessageSizeTooLarge) {
k.Log.Error("Message too large, consider increasing `max_message_bytes`; dropping batch")
return nil
}
if errors.Is(prodErr.Err, sarama.ErrInvalidTimestamp) {
k.Log.Error(
"The timestamp of the message is out of acceptable range, consider increasing broker `message.timestamp.difference.max.ms`; " +
"dropping batch",
)
return nil
}
return prodErr //nolint:staticcheck // Return first error encountered
if errors.As(err, &errs) && len(errs) > 0 {
// Just return the first error encountered
firstErr := errs[0]
if errors.Is(firstErr.Err, sarama.ErrMessageSizeTooLarge) {
k.Log.Error("Message too large, consider increasing `max_message_bytes`; dropping batch")
return nil
}
if errors.Is(firstErr.Err, sarama.ErrInvalidTimestamp) {
k.Log.Error(
"The timestamp of the message is out of acceptable range, consider increasing broker `message.timestamp.difference.max.ms`; " +
"dropping batch",
)
return nil
}
return firstErr
}
return err
}
Expand Down

0 comments on commit 6e444f6

Please sign in to comment.