Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send kafka message in batch #1708

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 6 additions & 10 deletions stats/kafka/collector.go
Expand Up @@ -155,19 +155,15 @@ func (c *Collector) pushMetrics() {

// Send the samples
c.logger.Debug("Kafka: Delivering...")


var msgList []*sarama.ProducerMessage
for _, sample := range formattedSamples {
msg := &sarama.ProducerMessage{Topic: c.Config.Topic.String, Value: sarama.StringEncoder(sample)}
partition, offset, err := c.Producer.SendMessage(msg)
if err != nil {
c.logger.WithError(err).Error("Kafka: failed to send message.")
Copy link
Member

@mostafa mostafa Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to have logging while using c.Producer.SendMessages(msgList) on Line 165?

} else {
c.logger.WithFields(logrus.Fields{
"partition": partition,
"offset": offset,
}).Debug("Kafka: message sent.")
}
msgList = append(msgList, msg)
}
// Send message in batch
c.Producer.SendMessages(msgList)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to have logging while using c.Producer.SendMessages(msgList) on Line 165?

That is, what happens if this line somehow fails?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Let me have a check. Thx @mostafa !

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @RoySunnySean007 any movement on this change?



t := time.Since(startTime)
c.logger.WithField("t", t).Debug("Kafka: Delivered!")
Expand Down