danielqsj / kafka_exporter

Kafka exporter for Prometheus
Apache License 2.0
2.1k stars 602 forks source link

Some metrics are missed on non-concurrent Collect function #335

Open mahdinajiga opened 1 year ago

mahdinajiga commented 1 year ago

I noticed that when you change the descriptors and edit the collect method of the Exporter struct, sometimes the last metric is being ignored. I realized that a small time.Sleep (like 100us) before line number 350 in kafka_exporter.go can fix the problem.

Finally I've found out that [sometimes] when the e.collect(original) is called and returned, the original channel is closed before the last metric is added to container array.

A channel (as a flag) can fix the problem, to wait before iterating the e.sgChans until the for loop exits in line number 344.

Let me know if you think I'm wrong or doing something wrong :)