Skip to content
Snippets Groups Projects
Commit a093ec1e authored by Cameron Sparr's avatar Cameron Sparr
Browse files

Kafka output fixup

parent d71a42cd
No related branches found
No related tags found
No related merge requests found
......@@ -154,26 +154,23 @@ func (k *Kafka) Write(metrics []telegraf.Metric) error {
}
for _, metric := range metrics {
values, err := k.serializer.Serialize(metric)
buf, err := k.serializer.Serialize(metric)
if err != nil {
return err
}
var pubErr error
for _, value := range values {
m := &sarama.ProducerMessage{
Topic: k.Topic,
Value: sarama.StringEncoder(value),
}
if h, ok := metric.Tags()[k.RoutingTag]; ok {
m.Key = sarama.StringEncoder(h)
}
_, _, pubErr = k.producer.SendMessage(m)
m := &sarama.ProducerMessage{
Topic: k.Topic,
Value: sarama.ByteEncoder(buf),
}
if h, ok := metric.Tags()[k.RoutingTag]; ok {
m.Key = sarama.StringEncoder(h)
}
_, _, err = k.producer.SendMessage(m)
if pubErr != nil {
return fmt.Errorf("FAILED to send kafka message: %s\n", pubErr)
if err != nil {
return fmt.Errorf("FAILED to send kafka message: %s\n", err)
}
}
return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment