deviceinsight / kafkactl

Command Line Tool for managing Apache Kafka
https://deviceinsight.github.io/kafkactl/
Apache License 2.0
829 stars 79 forks source link

Can't reset consumer group offsets in Azure EventHub #217

Open mwalser opened 1 month ago

mwalser commented 1 month ago

We recently had to adjust the offsets of a partition in Azure EventHub. However, it didn't work:

When resetting the offsets while a consumer was active, kafkactl refused to do so. This is expected:

❯ kafkactl reset consumer-group-offset some-consumer-group --topic some-topic --partition 10 --offset 847082914 --execute
cannot reset offsets on consumer group some-consumer-group. There are consumers assigned (state: Stable)

However, after stopping the consumer, resetting the offset was still not possible;:

❯ kafkactl reset consumer-group-offset some-consumer-group --topic some-topic --partition 10 --offset 847082914 --execute
cannot reset offsets on consumer group some-consumer-group. There are consumers assigned (state: Dead)

Looking at the code, setting offsets is only allowed when the consumer group is in state Empty. However, it seems like the Azure EventHub Kafka interface skips the Empty state and goes directly to Dead once no consumer is present on the group. At least that's the observation. I wasn't able to find documentation from Microsoft regarding this behavior.

Using a locally built kafkactl version with the check patched out, resetting the offsets worked even with the consumer group being in the Dead state. Looking at the Kafka command line tool, it also allows resetting the offsets when a group is in the Dead state.

If wanted, I can try to create a PR.

d-rk commented 1 month ago

Hey @mwalser

The check was introduced to prevent resetting offsets when the group is in Stable state: https://github.com/deviceinsight/kafkactl/commit/c5991de0cf033dcd9ee8a4be614e1ac0feea8632 / https://github.com/deviceinsight/kafkactl/issues/43

I guess it is safe to do it in Dead state also. I would be happy to review your PR for this :slightly_smiling_face: