-
Notifications
You must be signed in to change notification settings - Fork 882
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
base: master
Are you sure you want to change the base?
Logger with Admin Client #1758
Conversation
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.
Minor comments
""" | ||
Create a new AdminClient using the provided configuration dictionary. | ||
|
||
The AdminClient is a standard Kafka protocol client, supporting | ||
the standard librdkafka configuration properties as specified at | ||
https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md | ||
|
||
:param dict config: Configuration properties. At a minimum ``bootstrap.servers`` **should** be set\n" |
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.
Shouldn't it be named conf
? And also the trailing \n
can be removed
""" | ||
Create a new AdminClient using the provided configuration dictionary. | ||
|
||
The AdminClient is a standard Kafka protocol client, supporting | ||
the standard librdkafka configuration properties as specified at | ||
https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md | ||
|
||
:param dict config: Configuration properties. At a minimum ``bootstrap.servers`` **should** be set\n" | ||
:param Logger logger: Optional Logger instance to use as a custom log messages handler. | ||
|
||
At least 'bootstrap.servers' should be configured. |
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.
This can be removed as it's included above now
At least 'bootstrap.servers' should be configured. | ||
""" | ||
if logger is not None: |
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.
Do we need to throw an exception here if the conf doesn't includes bootstrap? like
if 'bootstrap.servers' not in conf:
raise ValueError("Configuration must include 'bootstrap.servers'")
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.
We are not doing this anywhere else. Let's not do here as well.
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.
For anchit's comment about bootstrap.servers
: this is checked later by librdkafka, whenever possible we delegate the validation there
tests/test_log.py
Outdated
stringBuffer = StringIO() | ||
logger = logging.getLogger('Admin') | ||
logger.setLevel(logging.DEBUG) | ||
handler = logging.StreamHandler(stringBuffer) | ||
handler.setFormatter(logging.Formatter('%(name)s Logger | %(message)s')) | ||
logger.addHandler(handler) |
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.
This is being repeated here and the above two functions. Can be moved to setup_logger
or some helper function
examples/adminapi.py
Outdated
@@ -920,3 +928,6 @@ def example_list_offsets(a, args): | |||
sys.exit(1) | |||
|
|||
opsmap[operation](a, args) | |||
|
|||
# Log messages through custom logger if provided | |||
a.poll(0) |
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.
Newline missing
tests/test_log.py
Outdated
logMessage = stringBuffer.getvalue().strip() | ||
stringBuffer.close() | ||
|
||
assert "Admin Logger | INIT" in logMessage |
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.
Newline missing
examples/adminapi.py
Outdated
# Create Admin client | ||
a = AdminClient({'bootstrap.servers': broker}) | ||
a = AdminClient({'bootstrap.servers': broker}, |
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.
logger should be a property like in the producer and consumer, not an additional parameter
'logger': logger,
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.
In python, its an additional parameter as well.
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.
right, I delete it so I don't request this change
* Updated examples/adminapi.py to include usage of the custom logger with AdminClient
5479623
to
a2be27b
Compare
At least 'bootstrap.servers' should be configured. | ||
""" | ||
if logger is not None: |
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.
For anchit's comment about bootstrap.servers
: this is checked later by librdkafka, whenever possible we delegate the validation there
""" | ||
if logger is not None: | ||
conf['logger'] = logger | ||
super(AdminClient, self).__init__(conf) |
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.
You can just pass the kwargs here without changing the conf, that'll be done by the C code
super(AdminClient, self).__init__(conf) | |
super(AdminClient, self).__init__(conf, **kwargs) |
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.
This doesn't work in case the logger is None
. I tried this only first.
In general, if the logger is provided in conf as well as in the parameter, parameter gets more priority. By doing this, the logger is always None if it is provided in conf.
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.
Yes, was checking this an updated my comment with kwargs
@@ -109,16 +109,19 @@ class AdminClient (_AdminClientImpl): | |||
Requires broker version v0.11.0.0 or later. | |||
""" | |||
|
|||
def __init__(self, conf): | |||
def __init__(self, conf, logger=None): |
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.
def __init__(self, conf, logger=None): | |
def __init__(self, conf, **kwargs): |
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.
This will start taking all the properties in the conf as parameter. I don't know if we should support this.
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 was thinking of only supporting logger property like this.
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.
That's what happens with the Producer and Consumer too
There is inbetween manipulation of the config properties in python binding as well. Due to that part, I have to check here first. |
logger
not working when provided as an argument toAdminClient
examples/adminapi.py
to include usage of the custom logger withAdminClient