First off, I would just like to say that I really appreciate all of the effort that has gone into this project. It has been invaluable to me at work. Over the past few days, I have been trying to update my code from working with kafka-python version 2.3.x to 3.0.x. The admin client improvements have been awesome.
The one problem that I have gotten stuck on is with a custom consumer group assignor that uses the current lag as one of the main drivers for which partitions are assigned to each consumer (i.e., consumers that get assigned partitions with significantly higher lag than the rest will get fewer partitions than other consumers in the group; if lag is low/even, then assignment will be more evenly distributed).
In the past (in 2.3.x and earlier), I was able to relatively easily use fetcher.end_offsets and coordinator._send_offset_fetch_request (followed by coordinator._client.poll to wait for that future), for example, to retrieve the information that was necessary for calculating lag (the public KafkaConsumer.highwater method doesn't work for a cold group leader). Now with 3.0.x, the kafka.net.selector.NetworkSelector.run method ends up raising a RuntimeError if the equivalent methods are called by the assignor from synchronous code.
I tried implementing a version of my custom assignor using asyncio, and got very very close, but calling almost any of the relevant internal/private async methods in kafka-python resulted in a RuntimeError: Task got bad yield: <kafka.future.Future object at ...>.
It looks like #3111 may be addressing at least part of this, possibly? Do you have any other insight or tips you could offer, or is this use case something that would require deeper changes?
First off, I would just like to say that I really appreciate all of the effort that has gone into this project. It has been invaluable to me at work. Over the past few days, I have been trying to update my code from working with kafka-python version 2.3.x to 3.0.x. The admin client improvements have been awesome.
The one problem that I have gotten stuck on is with a custom consumer group assignor that uses the current lag as one of the main drivers for which partitions are assigned to each consumer (i.e., consumers that get assigned partitions with significantly higher lag than the rest will get fewer partitions than other consumers in the group; if lag is low/even, then assignment will be more evenly distributed).
In the past (in 2.3.x and earlier), I was able to relatively easily use
fetcher.end_offsetsandcoordinator._send_offset_fetch_request(followed bycoordinator._client.pollto wait for that future), for example, to retrieve the information that was necessary for calculating lag (the publicKafkaConsumer.highwatermethod doesn't work for a cold group leader). Now with 3.0.x, thekafka.net.selector.NetworkSelector.runmethod ends up raising a RuntimeError if the equivalent methods are called by the assignor from synchronous code.I tried implementing a version of my custom assignor using asyncio, and got very very close, but calling almost any of the relevant internal/private async methods in kafka-python resulted in a
RuntimeError: Task got bad yield: <kafka.future.Future object at ...>.It looks like #3111 may be addressing at least part of this, possibly? Do you have any other insight or tips you could offer, or is this use case something that would require deeper changes?