@@ -130,11 +130,16 @@ class Metrics(Input.Metrics):
130130
131131 librdkafka_replyq : GaugeMetric = field (
132132 factory = lambda : GaugeMetric (
133- description = "Number of ops (callbacks, events, etc) waiting in queue for application to serve with rd_kafka_poll()" ,
133+ description = (
134+ "Number of ops (callbacks, events, etc) waiting in "
135+ "queue for application to serve with rd_kafka_poll()"
136+ ),
134137 name = "confluent_kafka_input_librdkafka_replyq" ,
135138 )
136139 )
137- """Number of ops (callbacks, events, etc) waiting in queue for application to serve with rd_kafka_poll()"""
140+ """Number of ops (callbacks, events, etc) waiting in queue for application
141+ to serve with rd_kafka_poll()
142+ """
138143 librdkafka_tx : GaugeMetric = field (
139144 factory = lambda : GaugeMetric (
140145 description = "Total number of requests sent to Kafka brokers" ,
@@ -166,14 +171,22 @@ class Metrics(Input.Metrics):
166171 """Total number of bytes received from Kafka brokers"""
167172 librdkafka_rxmsgs : GaugeMetric = field (
168173 factory = lambda : GaugeMetric (
169- description = "Total number of messages consumed, not including ignored messages (due to offset, etc), from Kafka brokers." ,
174+ description = (
175+ "Total number of messages consumed, not including ignored messages"
176+ "(due to offset, etc), from Kafka brokers."
177+ ),
170178 name = "confluent_kafka_input_librdkafka_rxmsgs" ,
171179 )
172180 )
173- """Total number of messages consumed, not including ignored messages (due to offset, etc), from Kafka brokers."""
181+ """Total number of messages consumed, not including ignored messages
182+ (due to offset, etc), from Kafka brokers.
183+ """
174184 librdkafka_rxmsg_bytes : GaugeMetric = field (
175185 factory = lambda : GaugeMetric (
176- description = "Total number of message bytes (including framing) received from Kafka brokers" ,
186+ description = (
187+ "Total number of message bytes (including framing)"
188+ "received from Kafka brokers"
189+ ),
177190 name = "confluent_kafka_input_librdkafka_rxmsg_bytes" ,
178191 )
179192 )
@@ -195,11 +208,11 @@ class Metrics(Input.Metrics):
195208 """Time elapsed since last rebalance (assign or revoke) (milliseconds)."""
196209 librdkafka_cgrp_rebalance_cnt : GaugeMetric = field (
197210 factory = lambda : GaugeMetric (
198- description = "Total number of rebalances (assign or revoke)." ,
211+ description = "Total number of rebalance (assign or revoke)." ,
199212 name = "confluent_kafka_input_librdkafka_cgrp_rebalance_cnt" ,
200213 )
201214 )
202- """Total number of rebalances (assign or revoke)."""
215+ """Total number of rebalance (assign or revoke)."""
203216 librdkafka_cgrp_assignment_size : GaugeMetric = field (
204217 factory = lambda : GaugeMetric (
205218 description = "Current assignment's partition count." ,
@@ -316,7 +329,7 @@ def _error_callback(self, error: KafkaException) -> None:
316329 the error that occurred
317330 """
318331 self .metrics .number_of_errors += 1
319- logger .error (f" { self .describe ()} : { error } " )
332+ logger .error ("%s: %s" , self .describe (), error )
320333
321334 def _stats_callback (self , stats_raw : str ) -> None :
322335 """Callback for statistics data. This callback is triggered by poll()
@@ -487,12 +500,13 @@ def batch_finished_callback(self) -> None:
487500 except KafkaException as error :
488501 raise InputWarning (self , f"{ error } , { self ._last_valid_record } " ) from error
489502
490- def _assign_callback (self , consumer , topic_partitions ) :
503+ def _assign_callback (self , topic_partitions : list [ TopicPartition ]) -> None :
491504 for topic_partition in topic_partitions :
492505 offset , partition = topic_partition .offset , topic_partition .partition
506+ member_id = self ._get_memberid ()
493507 logger .info (
494508 "%s was assigned to topic: %s | partition %s" ,
495- consumer . memberid () ,
509+ member_id ,
496510 topic_partition .topic ,
497511 partition ,
498512 )
@@ -503,27 +517,38 @@ def _assign_callback(self, consumer, topic_partitions):
503517 self .metrics .committed_offsets .add_with_labels (offset , labels )
504518 self .metrics .current_offsets .add_with_labels (offset , labels )
505519
506- def _revoke_callback (self , consumer , topic_partitions ):
520+ def _revoke_callback (self , topic_partitions : list [TopicPartition ]) -> None :
521+
507522 for topic_partition in topic_partitions :
508523 self .metrics .number_of_warnings += 1
524+ member_id = self ._get_memberid ()
509525 logger .warning (
510526 "%s to be revoked from topic: %s | partition %s" ,
511- consumer . memberid () ,
527+ member_id ,
512528 topic_partition .topic ,
513529 topic_partition .partition ,
514530 )
515531 self .batch_finished_callback ()
516532
517- def _lost_callback (self , consumer , topic_partitions ) :
533+ def _lost_callback (self , topic_partitions : list [ TopicPartition ]) -> None :
518534 for topic_partition in topic_partitions :
519535 self .metrics .number_of_warnings += 1
536+ member_id = self ._get_memberid ()
520537 logger .warning (
521538 "%s has lost topic: %s | partition %s - try to reassign" ,
522- consumer . memberid () ,
539+ member_id ,
523540 topic_partition .topic ,
524541 topic_partition .partition ,
525542 )
526543
544+ def _get_memberid (self ) -> str | None :
545+ member_id = None
546+ try :
547+ member_id = self ._consumer .memberid ()
548+ except RuntimeError as error :
549+ logger .error ("Failed to retrieve member ID: %s" , error )
550+ return member_id
551+
527552 def shut_down (self ) -> None :
528553 """Close consumer, which also commits kafka offsets."""
529554 self ._consumer .close ()
0 commit comments