-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
FIX add error_cb to confluent.Consumer
config in ConsumerFromTopic
#44307
base: main
Are you sure you want to change the base?
Conversation
|
||
def error_callback(err): | ||
"""Handle kafka errors.""" | ||
print("Exception received: ", err) |
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.
should we try to use logger instead of a print here?
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 think in other operators they use logger instead
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 think, the approach looks good and similar to what I have tested. Please update tests.
pass | ||
|
||
|
||
def error_callback(err): |
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.
Looks promising!
error_cb(kafka.KafkaError)
: Callback for generic/global error events
We have to filter only related one ( https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html#pythonclient-kafkaerror ).
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.
Is this what you meant?
def error_callback(err):
"""Handle kafka errors."""
if err.code() == KafkaError.NO_ERROR:
return
else:
print("Exception received: ", err)
raise KafkaAuthenticationError(f"Authentication failed: {err}")
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 think that we would like to catch only Authentication issue while error_callback consume all errors (https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html#pythonclient-kafkaerror).
@@ -36,6 +48,7 @@ def __init__(self, topics: Sequence[str], kafka_config_id=KafkaBaseHook.default_ | |||
self.topics = topics | |||
|
|||
def _get_client(self, config) -> Consumer: | |||
config["error_cb"] = error_callback |
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.
It might not be the best practice to update user-provided data. As an alternative, we could create a shallow copy instead.
Additionally, we can assume that the user has already provided an error_cb. In this case, we need to decide how to handle this behavior, which is an open question. One possible solution is to call the user-defined error_cb first and then invoke our custom implementation if the user does not raise an exception. This approach makes sense because authentication errors are not recoverable, so they should interrupt execution.
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.
Additionally, we can assume that the user has already provided an error_cb.
Is there a parameter for user defined error_cb?
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.
Additionally, we can assume that the user has already provided an error_cb.
config
may already contain handler. In this case you will override user defined handler.
closes: #43569