summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith So <kso@eclipseoptions.com>2020-11-06 16:05:55 +1100
committerGitHub <noreply@github.com>2020-11-05 21:05:55 -0800
commit12325c09baefae2396f1083bc8b037603721198c (patch)
tree6b962c392773cf188ea6ebc8ec19bb7522283814
parentb090b21f07a1c7b89afb5dc36114aa2d37c580f0 (diff)
downloadkafka-python-12325c09baefae2396f1083bc8b037603721198c.tar.gz
Only try to update sensors fetch lag if the unpacked list contains elements (#2158)
Previously, if the `unpacked` list was empty, the call to `unpacked[-1]` would throw an `IndexError: list index out of range`
-rw-r--r--kafka/consumer/fetcher.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/kafka/consumer/fetcher.py b/kafka/consumer/fetcher.py
index e4f8c18..7ff9daf 100644
--- a/kafka/consumer/fetcher.py
+++ b/kafka/consumer/fetcher.py
@@ -817,8 +817,9 @@ class Fetcher(six.Iterator):
position)
unpacked = list(self._unpack_message_set(tp, records))
parsed_records = self.PartitionRecords(fetch_offset, tp, unpacked)
- last_offset = unpacked[-1].offset
- self._sensors.records_fetch_lag.record(highwater - last_offset)
+ if unpacked:
+ last_offset = unpacked[-1].offset
+ self._sensors.records_fetch_lag.record(highwater - last_offset)
num_bytes = records.valid_bytes()
records_count = len(unpacked)
elif records.size_in_bytes() > 0: