From 0e29a0a95a41d92c0ba2a633c8e47af16854935a Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Wed, 10 Jul 2024 09:47:10 +0700 Subject: [PATCH] Handle Azure Eventhubs returns list duplicated servers --- kafka_exporter.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kafka_exporter.go b/kafka_exporter.go index 95a70a2d..91daaa75 100644 --- a/kafka_exporter.go +++ b/kafka_exporter.go @@ -661,9 +661,23 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) { klog.V(DEBUG).Info("Fetching consumer group metrics") if len(e.client.Brokers()) > 0 { + uniqueBrokerAddresses := make(map[string]bool) + var servers []string for _, broker := range e.client.Brokers() { - wg.Add(1) - go getConsumerGroupMetrics(broker) + normalizedAddress := strings.ToLower(broker.Addr()) + if !uniqueBrokerAddresses[normalizedAddress] { + uniqueBrokerAddresses[normalizedAddress] = true + servers = append(servers, broker.Addr()) + } + } + klog.Info(servers) + for _, broker := range e.client.Brokers() { + for _, server := range servers { + if server == broker.Addr() { + wg.Add(1) + go getConsumerGroupMetrics(broker) + } + } } wg.Wait() } else {