-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use confluent-kafka-python for Kafka admin client instead of kafka-python #757
Conversation
82962fe
to
8a91b03
Compare
The new method is a confluent-kafka-python compatible callback, which will be required by the new Kafka admin client. At the same time, remove the token from the token provider classes' `repr` - while we don't log these, it's better not to accidentally leak tokens.
8a91b03
to
80bb504
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice code 😄, I've left some comments, feel free to disagree with all of them.
I've just left what I was feeling while reading the code. The code looks very auto explicative and you've added doc on all the new methods cool!
PPS before merging just make sure to sync the well doc you added to the commits with the pr description.
I need another round of reading but I've left this to flush my mental buffer :)
119860b
to
485fbb8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving a partial review, I haven't read through everything yet. I left a few comments on the design/interface of the new admin client.
7293345
to
cfdc71a
Compare
This change replaces all Kafka admin client usages with a new implementation, based on confluent-kafka-python's `AdminClient`, aiming to keep the same interface as much as possible for the time being. The goal is not to completely remove kafka-python as a dependency, rather take a step towards that. The kafka-python library is still widely used in the codebase, eg. for error handling (even in the new `KafkaAdminClient`). The new `KafkaAdminClient` takes the place of all previous admin clients used, thus not specific to the REST proxy anymore. Hence it's move to a new module as `karapace.kafka_admin.KafkaAdminClient`, which also consolidates all references to the `confluent_kafka` lib. The test suite has also been moved and expanded. Wherever possible the same interface was kept, only adding new methods to simplify client code (to a minimal extent). This is most notable in tests and the backups functionality. The new admin client aims to hide away confluent-kafka-python's Future-based async client approach by providing wrapper methods that resolve these futures. Typing (issues) from `confluent_kafka` are ignored for now, no typing stubs have been added on purpose. Resources: * confluent-kafka-python documentation: https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html# * librdkafka configuration documentation: https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md
1038d9b
to
79c6198
Compare
@@ -14,6 +14,7 @@ warn_unused_ignores = True | |||
warn_no_return = True | |||
warn_unreachable = True | |||
strict_equality = True | |||
enable_incomplete_feature = Unpack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this was just marked stable in 1.7 that was just released, oddly coincidental timing! https://mypy-lang.blogspot.com/2023/11/mypy-17-released.html
But let's keep this as-is and upgrade mypy separately to limit the scope.
This looks good to me 👍 @eliax1996 Do you want to make another pass on this? |
About this change - What it does
Replace Kafka admin clients (including
KafkaRestAdminClient
and "vanilla" admin clients fromkafka-python
) with a newconfluent_kafka
based one.The main change is:
KafkaAdminClient
in a new moduleKafkaRestAdminClient
from its original location and adapting to the new base class from confluent-kafka-pythonOther changes are mostly a consequence of this, adapting to a slightly different interface, simplifying client code when it was straight forward, etc. Many files have been changed, however, most of these are straightforward renamings or small changes to adapt to the new client.
Why this way
kafka-python
is out of scope for this PR, however there is only one admin client nowKafkaAdminClient
aims to keep the same interface as much as possible as it was before (exceptions include many-manyNewTopic.name
->NewTopic.topic
changes), also in exceptions thrownconfluent_kafka
within the new modulekafka.errors.for_code
and its specific exceptionsNo typing stubs are added for confluent-kafka-python, that's something that could potentially be done after a "full switch"Type stubs are going to be added in a follow-up: Add typing stubs for confluent-kafka #760Request from reviewers
Are there any "what if" kind of scenarios that might not be covered by tests or the code at the moment? (Especially backups and schema registry related.)