Skip to content
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

[KIP-430] Added ACL Operations to Describe Topics, Cluster and ConsumerGroup APIs #1635

Merged
merged 32 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1b05ff2
initial commit for describeCG API
jainruchir Apr 4, 2023
20a0a9b
initial commit for describeCG API(2)
jainruchir Apr 4, 2023
e3609d6
DescribeTopics implemented
jainruchir Apr 5, 2023
7fdf428
Implemented Describe Topic and Describe Cluster with some tests
jainruchir Sep 5, 2023
2944772
Autopep fixes
jainruchir Sep 5, 2023
80e1aa3
Compiling after all the changes related to changes in Request and Res…
pranavrth Sep 6, 2023
4bc60c1
Working after refactoring
pranavrth Sep 7, 2023
efa705d
Added integration tests
pranavrth Sep 10, 2023
ecf9036
Updated integration tests to use generic assert
pranavrth Sep 10, 2023
2487e33
Added more generalization
pranavrth Sep 10, 2023
a1cc0bd
Refactoring
pranavrth Sep 10, 2023
1bfe3cb
Removed moved admin tests
pranavrth Sep 10, 2023
a4a81c3
Some doc updates
pranavrth Sep 10, 2023
4417027
Refactoring and some doc changes
pranavrth Sep 10, 2023
6833620
Some more Refactoring
pranavrth Sep 10, 2023
95d798c
Handled null controller case
pranavrth Sep 10, 2023
c17c228
Updated the fixure to use conf
pranavrth Sep 11, 2023
d56aea8
Added more tests for describe APIs
pranavrth Sep 11, 2023
c883bb6
Added rack information in the Node
pranavrth Sep 18, 2023
5467e51
Introduced TopicCollection in describe_topics API
pranavrth Sep 18, 2023
5791d91
Updated In Sync replica field name to isr for TopicPartitionInfo
pranavrth Sep 20, 2023
9f1f45d
Changed TopicDescription topic field to name
pranavrth Sep 21, 2023
082aadb
PR comments
pranavrth Sep 27, 2023
a025c0f
Handling cluster_id Null case
pranavrth Sep 27, 2023
2fbf2de
PR comments and CHANGELOG added
pranavrth Sep 27, 2023
b776eda
Removed unwanted changes
pranavrth Sep 28, 2023
6d087a7
PR comments addressed
pranavrth Oct 19, 2023
3aab626
Fixed styling issue
pranavrth Oct 19, 2023
52d0946
Updated Changelog to reflect Rack info as well
pranavrth Oct 19, 2023
42f6cb8
Added command for vault dockerhub creds
pranavrth Oct 20, 2023
b5d2e42
Merge branch 'master' into dev_kip430_rebase
pranavrth Oct 23, 2023
8ceb4df
Fixed build issue
pranavrth Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Confluent's Python client for Apache Kafka

## v2.3.0

v2.3.0 is a feature release with the following features, fixes and enhancements:

* Add support for AdminAPI `DescribeCluster()` and `DescribeTopics()`. (@jainruchir, #1635)
* [KIP-430](https://cwiki.apache.org/confluence/display/KAFKA/KIP-430+-+Return+Authorized+Operations+in+Describe+Responses):
Return authorized operations in Describe Responses. (@jainruchir, #1635)
* Add `Rack` to the `Node` type, so AdminAPI calls can expose racks for brokers
(currently, all Describe Responses) (#1635, @jainruchir).

confluent-kafka-python is based on librdkafka v2.3.0, see the
[librdkafka release notes](https://github.com/confluentinc/librdkafka/releases/tag/v2.3.0)
for a complete list of changes, enhancements, fixes and upgrade considerations.


## v2.2.0

v2.2.0 is a feature release with the following features, fixes and enhancements:
Expand Down
183 changes: 183 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Supporting classes
- :ref:`Message <pythonclient_message>`
- :ref:`TopicPartition <pythonclient_topicpartition>`
- :ref:`ThrottleEvent <pythonclient_throttleevent>`
- :ref:`TopicCollection <pythonclient_topic_collection>`
- :ref:`TopicPartitionInfo <pythonclient_topic_partition_info>`
- :ref:`Node <pythonclient_node>`
- :ref:`ConsumerGroupTopicPartitions <pythonclient_consumer_group_topic_partition>`
- :ref:`ConsumerGroupState <pythonclient_consumer_group_state>`

- Errors:
- :ref:`KafkaError <pythonclient_kafkaerror>`
Expand Down Expand Up @@ -55,6 +60,19 @@ Supporting classes
- :ref:`UserScramCredentialAlteration <pythonclient_user_scram_credential_alteration>`
- :ref:`UserScramCredentialUpsertion <pythonclient_user_scram_credential_upsertion>`
- :ref:`UserScramCredentialDeletion <pythonclient_user_scram_credential_deletion>`
- :ref:`TopicDescription <pythonclient_topic_description>`
- :ref:`DescribeClusterResult <pythonclient_describe_cluster_result>`
- :ref:`BrokerMetadata <pythonclient_broker_metadata>`
- :ref:`ClusterMetadata <pythonclient_cluster_metadata>`
- :ref:`GroupMember <pythonclient_group_member>`
- :ref:`GroupMetadata <pythonclient_group_metadata>`
- :ref:`PartitionMetadata <pythonclient_partition_metadata>`
- :ref:`TopicMetadata <pythonclient_topic_metadata>`
- :ref:`ConsumerGroupListing <pythonclient_consumer_group_listing>`
- :ref:`ListConsumerGroupsResult <pythonclient_list_consumer_group_result>`
- :ref:`MemberAssignment <pythonclient_member_assignment>`
- :ref:`MemberDescription <pythonclient_member_description>`
- :ref:`ConsumerGroupDescription <pythonclient_consumer_group_description>`

Experimental
These classes are experimental and are likely to be removed, or subject to incompatible
Expand Down Expand Up @@ -84,6 +102,7 @@ AdminClient

.. automodule:: confluent_kafka.admin
:members:
:noindex:

.. _pyclient_admin_newtopic:

Expand Down Expand Up @@ -247,6 +266,123 @@ UserScramCredentialDeletion
.. autoclass:: confluent_kafka.admin.UserScramCredentialDeletion
:members:

.. _pythonclient_topic_description:

****************
TopicDescription
****************

.. autoclass:: confluent_kafka.admin.TopicDescription
:members:

.. _pythonclient_describe_cluster_result:

*********************
DescribeClusterResult
*********************

.. autoclass:: confluent_kafka.admin.DescribeClusterResult
:members:

.. _pythonclient_broker_metadata:

**************
BrokerMetadata
**************

.. autoclass:: confluent_kafka.admin.BrokerMetadata
:members:

.. _pythonclient_cluster_metadata:

***************
ClusterMetadata
***************

.. autoclass:: confluent_kafka.admin.ClusterMetadata
:members:

.. _pythonclient_group_member:

***********
GroupMember
***********

.. autoclass:: confluent_kafka.admin.GroupMember
:members:

.. _pythonclient_group_metadata:

*************
GroupMetadata
*************

.. autoclass:: confluent_kafka.admin.GroupMetadata
:members:

.. _pythonclient_partition_metadata:

*****************
PartitionMetadata
*****************

.. autoclass:: confluent_kafka.admin.PartitionMetadata
:members:

.. _pythonclient_topic_metadata:

*************
TopicMetadata
*************

.. autoclass:: confluent_kafka.admin.TopicMetadata
:members:

.. _pythonclient_consumer_group_listing:

********************
ConsumerGroupListing
********************

.. autoclass:: confluent_kafka.admin.ConsumerGroupListing
:members:

.. _pythonclient_list_consumer_group_result:

************************
ListConsumerGroupsResult
************************

.. autoclass:: confluent_kafka.admin.ListConsumerGroupsResult
:members:

.. _pythonclient_consumer_group_description:

************************
ConsumerGroupDescription
************************

.. autoclass:: confluent_kafka.admin.ConsumerGroupDescription
:members:

.. _pythonclient_member_assignment:

****************
MemberAssignment
****************

.. autoclass:: confluent_kafka.admin.MemberAssignment
:members:

.. _pythonclient_member_description:

*****************
MemberDescription
*****************

.. autoclass:: confluent_kafka.admin.MemberDescription
:members:

.. _pythonclient_consumer:

********
Expand All @@ -255,6 +391,7 @@ Consumer

.. autoclass:: confluent_kafka.Consumer
:members:
:noindex:

.. _serde_consumer:

Expand All @@ -275,6 +412,7 @@ Producer

.. autoclass:: confluent_kafka.Producer
:members:
:noindex:

.. _serde_producer:

Expand Down Expand Up @@ -477,6 +615,51 @@ TopicPartition
.. autoclass:: confluent_kafka.TopicPartition
:members:

.. _pythonclient_topic_collection:

***************
TopicCollection
***************

.. autoclass:: confluent_kafka.TopicCollection
:members:

.. _pythonclient_topic_partition_info:

******************
TopicPartitionInfo
******************

.. autoclass:: confluent_kafka.TopicPartitionInfo
:members:

.. _pythonclient_node:

****
Node
****

.. autoclass:: confluent_kafka.Node
:members:

.. _pythonclient_consumer_group_topic_partition:

****************************
ConsumerGroupTopicPartitions
****************************

.. autoclass:: confluent_kafka.ConsumerGroupTopicPartitions
:members:

.. _pythonclient_consumer_group_state:

******************
ConsumerGroupState
******************

.. autoclass:: confluent_kafka.ConsumerGroupState
:members:

.. _serde_field:

************
Expand Down
97 changes: 92 additions & 5 deletions examples/adminapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Example use of AdminClient operations.

from confluent_kafka import (KafkaException, ConsumerGroupTopicPartitions,
TopicPartition, ConsumerGroupState)
TopicPartition, ConsumerGroupState, TopicCollection)
emasab marked this conversation as resolved.
Show resolved Hide resolved
from confluent_kafka.admin import (AdminClient, NewTopic, NewPartitions, ConfigResource,
ConfigEntry, ConfigSource, AclBinding,
AclBindingFilter, ResourceType, ResourcePatternType,
Expand Down Expand Up @@ -492,8 +492,9 @@ def example_describe_consumer_groups(a, args):
"""
Describe Consumer Groups
"""

futureMap = a.describe_consumer_groups(args, request_timeout=10)
include_auth_ops = bool(int(args[0]))
args = args[1:]
futureMap = a.describe_consumer_groups(args, include_authorized_operations=include_auth_ops, request_timeout=10)

for group_id, future in futureMap.items():
try:
Expand All @@ -502,7 +503,8 @@ def example_describe_consumer_groups(a, args):
print(" Is Simple : {}".format(g.is_simple_consumer_group))
print(" State : {}".format(g.state))
print(" Partition Assignor : {}".format(g.partition_assignor))
print(" Coordinator : ({}) {}:{}".format(g.coordinator.id, g.coordinator.host, g.coordinator.port))
print(
f" Coordinator : {g.coordinator}")
print(" Members: ")
for member in g.members:
print(" Id : {}".format(member.member_id))
Expand All @@ -513,12 +515,93 @@ def example_describe_consumer_groups(a, args):
print(" Assignments :")
for toppar in member.assignment.topic_partitions:
print(" {} [{}]".format(toppar.topic, toppar.partition))
if (include_auth_ops):
print(" Authorized operations: ")
op_string = ""
for acl_op in g.authorized_operations:
op_string += acl_op.name + " "
print(" {}".format(op_string))
except KafkaException as e:
print("Error while describing group id '{}': {}".format(group_id, e))
except Exception:
raise


def example_describe_topics(a, args):
"""
Describe Topics
"""
include_auth_ops = bool(int(args[0]))
args = args[1:]
topics = TopicCollection(topic_names=args)
futureMap = a.describe_topics(topics, request_timeout=10, include_authorized_operations=include_auth_ops)

for topic_name, future in futureMap.items():
try:
t = future.result()
print("Topic name : {}".format(t.name))
if (t.is_internal):
print("Topic is Internal")

if (include_auth_ops):
print("Authorized operations : ")
op_string = ""
for acl_op in t.authorized_operations:
op_string += acl_op.name + " "
print(" {}".format(op_string))

print("Partition Information")
for partition in t.partitions:
print(" Id : {}".format(partition.id))
leader = partition.leader
print(f" Leader : {leader}")
print(" Replicas : {}".format(len(partition.replicas)))
for replica in partition.replicas:
print(f" Replica : {replica}")
print(" In-Sync Replicas : {}".format(len(partition.isr)))
for isr in partition.isr:
print(f" In-Sync Replica : {isr}")
print("")
print("")

except KafkaException as e:
print("Error while describing topic '{}': {}".format(topic_name, e))
except Exception:
raise


def example_describe_cluster(a, args):
"""
Describe Cluster
"""
include_auth_ops = bool(int(args[0]))
args = args[1:]
future = a.describe_cluster(request_timeout=10, include_authorized_operations=include_auth_ops)
try:
c = future.result()
print("Cluster_id : {}".format(c.cluster_id))

if (c.controller):
print(f"Controller: {c.controller}")
else:
print("No Controller Information Available")

print("Nodes :")
for node in c.nodes:
print(f" Node: {node}")

if (include_auth_ops):
print("Authorized operations: ")
op_string = ""
for acl_op in c.authorized_operations:
op_string += acl_op.name + " "
print(" {}".format(op_string))
except KafkaException as e:
print("Error while describing cluster: {}".format(e))
except Exception:
raise


def example_delete_consumer_groups(a, args):
"""
Delete Consumer Groups
Expand Down Expand Up @@ -704,7 +787,9 @@ def example_alter_user_scram_credentials(a, args):
'<principal1> <host1> <operation1> <permission_type1> ..\n')
sys.stderr.write(' list [<all|topics|brokers|groups>]\n')
sys.stderr.write(' list_consumer_groups [<state1> <state2> ..]\n')
sys.stderr.write(' describe_consumer_groups <group1> <group2> ..\n')
sys.stderr.write(' describe_consumer_groups <include_authorized_operations> <group1> <group2> ..\n')
sys.stderr.write(' describe_topics <include_authorized_operations> <topic1> <topic2> ..\n')
sys.stderr.write(' describe_cluster <include_authorized_operations>\n')
sys.stderr.write(' delete_consumer_groups <group1> <group2> ..\n')
sys.stderr.write(' list_consumer_group_offsets <group> [<topic1> <partition1> <topic2> <partition2> ..]\n')
sys.stderr.write(
Expand Down Expand Up @@ -737,6 +822,8 @@ def example_alter_user_scram_credentials(a, args):
'list': example_list,
'list_consumer_groups': example_list_consumer_groups,
'describe_consumer_groups': example_describe_consumer_groups,
'describe_topics': example_describe_topics,
'describe_cluster': example_describe_cluster,
'delete_consumer_groups': example_delete_consumer_groups,
'list_consumer_group_offsets': example_list_consumer_group_offsets,
'alter_consumer_group_offsets': example_alter_consumer_group_offsets,
Expand Down
Loading