From 12325c09baefae2396f1083bc8b037603721198c Mon Sep 17 00:00:00 2001 From: Keith So Date: Fri, 6 Nov 2020 16:05:55 +1100 Subject: 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` --- kafka/consumer/fetcher.py | 5 +++-- 1 file 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: -- cgit v1.2.1