@@ -343,60 +343,43 @@ def get_highwater_offsets(self, consumer_offsets):
343343 self .log .debug ('Getting highwater offsets' )
344344
345345 cluster_id = ""
346+ dd_consumer_group = "datadog-agent"
346347 highwater_offsets = {}
347- topics_with_consumer_offset = set ()
348- topic_partition_with_consumer_offset = set ()
348+ topic_partitions_to_check = set ()
349349
350- for consumer_group , offsets in consumer_offsets .items ():
351- self .log .debug ('CONSUMER GROUP: %s' , consumer_group )
352- topic_partitions_for_highwater_offsets = set ()
353- self .client .open_consumer (consumer_group )
354- cluster_id , topics = self .client .consumer_get_cluster_id_and_list_topics (consumer_group )
355-
356- if not self .config ._monitor_all_broker_highwatermarks :
357- for topic , partition in offsets :
358- topics_with_consumer_offset .add (topic )
359- topic_partition_with_consumer_offset .add ((topic , partition ))
360-
361- for topic , partitions in topics :
350+ if self .config ._monitor_all_broker_highwatermarks :
351+ all_topic_partitions = self .client .get_topic_partitions ()
352+ for topic in all_topic_partitions :
362353 if topic in KAFKA_INTERNAL_TOPICS :
363354 self .log .debug ("Skipping internal topic %s" , topic )
364355 continue
365- if not self .config ._monitor_all_broker_highwatermarks and topic not in topics_with_consumer_offset :
366- self .log .debug ("Skipping non-relevant topic %s" , topic )
367- continue
368356
369- for partition in partitions :
370- if (topic , partition ) in highwater_offsets :
371- self .log .debug (
372- 'Highwater offset already collected for topic %s with partition %s' , topic , partition
373- )
357+ for partition in all_topic_partitions [topic ]:
358+ topic_partitions_to_check .add ((topic , partition ))
359+
360+ else :
361+ for _ , offsets in consumer_offsets .items ():
362+ for topic , partition in offsets :
363+ if topic in KAFKA_INTERNAL_TOPICS :
364+ self .log .debug ("Skipping internal topic %s" , topic )
374365 continue
375- if (
376- self .config ._monitor_all_broker_highwatermarks
377- or (topic , partition ) in topic_partition_with_consumer_offset
378- ):
379- topic_partitions_for_highwater_offsets .add ((topic , partition ))
380- self .log .debug ('TOPIC: %s' , topic )
381- self .log .debug ('PARTITION: %s' , partition )
382- else :
383- self .log .debug ("Skipping non-relevant partition %s of topic %s" , partition , topic )
384366
385- if topic_partitions_for_highwater_offsets :
386- self .log .debug (
387- 'Querying %s highwater offsets for consumer group %s' ,
388- len (topic_partitions_for_highwater_offsets ),
389- consumer_group ,
390- )
391- for topic , partition , offset in self .client .consumer_offsets_for_times (
392- partitions = topic_partitions_for_highwater_offsets
393- ):
394- highwater_offsets [(topic , partition )] = offset
395- else :
396- self .log .debug ('No new highwater offsets to query for consumer group %s' , consumer_group )
367+ topic_partitions_to_check .add ((topic , partition ))
397368
398- self .client .close_consumer ()
369+ self .client .open_consumer (dd_consumer_group )
370+ cluster_id , _ = self .client .consumer_get_cluster_id_and_list_topics (dd_consumer_group )
371+ self .log .debug (
372+ 'Querying %s highwater offsets for consumer group %s' ,
373+ len (topic_partitions_to_check ),
374+ dd_consumer_group ,
375+ )
376+ if topic_partitions_to_check :
377+ for topic , partition , offset in self .client .consumer_offsets_for_times (
378+ partitions = topic_partitions_to_check
379+ ):
380+ highwater_offsets [(topic , partition )] = offset
399381
382+ self .client .close_consumer ()
400383 self .log .debug ('Got %s highwater offsets' , len (highwater_offsets ))
401384 return highwater_offsets , cluster_id
402385
0 commit comments