-
Notifications
You must be signed in to change notification settings - Fork 897
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
Logger with Admin Client #1758
Merged
Merged
Logger with Admin Client #1758
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f9ce50e
* Fixed logger not working when provided as an argument to AdminClient
pranavrth befd9ee
PR comments
pranavrth 6900a21
Fixed tests
pranavrth 610d48d
PR comments
pranavrth 5abfee1
Added a separate logger example file for admin apis
pranavrth 9fae015
PR comments
pranavrth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,10 +4,12 @@ | |||||
|
||||||
v2.4.1 is a maintenance release with the following fixes and enhancements: | ||||||
|
||||||
- Added an example to show the usage of the custom logger with `AdminClient` | ||||||
- Removed usage of `strcpy` to enhance security of the client (#1745) | ||||||
- Fixed invalid write in `OAUTHBEARER/OIDC` extensions copy (#1745) | ||||||
- Fixed an issue related to import error of `TopicCollection` and `TopicPartitionInfo` classes when importing through other module like mypy. | ||||||
- Fixed a segfault when `commit` or `store_offsets` consumer method is called incorrectly with errored Message object | ||||||
- Fixed `logger` not working when provided as an argument to `AdminClient` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify it was possible before:
Suggested change
|
||||||
|
||||||
confluent-kafka-python is based on librdkafka v2.4.1, see the | ||||||
[librdkafka release notes](https://github.com/confluentinc/librdkafka/releases/tag/v2.4.1) | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,47 @@ | ||||||||||||||||||
import sys | ||||||||||||||||||
import logging | ||||||||||||||||||
|
||||||||||||||||||
from confluent_kafka.admin import AdminClient | ||||||||||||||||||
|
||||||||||||||||||
if len(sys.argv) != 2: | ||||||||||||||||||
sys.stderr.write("Usage: %s <broker>\n" % sys.argv[0]) | ||||||||||||||||||
sys.exit(1) | ||||||||||||||||||
|
||||||||||||||||||
broker = sys.argv[1] | ||||||||||||||||||
|
||||||||||||||||||
# Custom logger | ||||||||||||||||||
logger = logging.getLogger('AdminClient') | ||||||||||||||||||
logger.setLevel(logging.DEBUG) | ||||||||||||||||||
handler = logging.StreamHandler() | ||||||||||||||||||
handler.setFormatter(logging.Formatter('%(asctime)-15s %(levelname)-8s %(message)s')) | ||||||||||||||||||
logger.addHandler(handler) | ||||||||||||||||||
|
||||||||||||||||||
# Create Admin client | ||||||||||||||||||
a = AdminClient({'bootstrap.servers': broker, | ||||||||||||||||||
'debug': 'all'}, | ||||||||||||||||||
logger=logger) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
# Sample Admin API call | ||||||||||||||||||
future = a.list_consumer_groups(request_timeout=10) | ||||||||||||||||||
|
||||||||||||||||||
while not future.done(): | ||||||||||||||||||
# Log messages through custom logger while waiting for the result | ||||||||||||||||||
a.poll(0.1) | ||||||||||||||||||
|
||||||||||||||||||
try: | ||||||||||||||||||
list_consumer_groups_result = future.result() | ||||||||||||||||||
print("\n\n\n========================= List consumer groups result Start =========================") | ||||||||||||||||||
print("{} consumer groups".format(len(list_consumer_groups_result.valid))) | ||||||||||||||||||
for valid in list_consumer_groups_result.valid: | ||||||||||||||||||
print(" id: {} is_simple: {} state: {}".format( | ||||||||||||||||||
valid.group_id, valid.is_simple_consumer_group, valid.state)) | ||||||||||||||||||
print("{} errors".format(len(list_consumer_groups_result.errors))) | ||||||||||||||||||
for error in list_consumer_groups_result.errors: | ||||||||||||||||||
print(" error: {}".format(error)) | ||||||||||||||||||
print("========================= List consumer groups result End =========================\n\n\n") | ||||||||||||||||||
|
||||||||||||||||||
except Exception: | ||||||||||||||||||
raise | ||||||||||||||||||
|
||||||||||||||||||
# Log final log messages | ||||||||||||||||||
a.poll(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Version can be changed to 2.5.0 when we merge
delete_records
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.
Already done that in delete_records as that is a new feature.