-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-2581: Run some existing ducktape tests with SSL #271
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
Changes from all commits
26ae395
d0385af
8958dd3
2356230
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| from ducktape.services.background_thread import BackgroundThreadService | ||
| from ducktape.utils.util import wait_until | ||
| from kafkatest.utils.security_config import SecurityConfig | ||
|
|
||
| import os | ||
| import subprocess | ||
|
|
@@ -93,13 +94,15 @@ class ConsoleConsumer(BackgroundThreadService): | |
| "collect_default": True} | ||
| } | ||
|
|
||
| def __init__(self, context, num_nodes, kafka, topic, message_validator=None, from_beginning=True, consumer_timeout_ms=None): | ||
| def __init__(self, context, num_nodes, kafka, topic, security_protocol=None, new_consumer=None, message_validator=None, from_beginning=True, consumer_timeout_ms=None): | ||
| """ | ||
| Args: | ||
| context: standard context | ||
| num_nodes: number of nodes to use (this should be 1) | ||
| kafka: kafka service | ||
| topic: consume from this topic | ||
| security_protocol: security protocol for Kafka connections | ||
| new_consumer: use new Kafka consumer if True | ||
| message_validator: function which returns message or None | ||
| from_beginning: consume from beginning if True, else from the end | ||
| consumer_timeout_ms: corresponds to consumer.timeout.ms. consumer process ends if time between | ||
|
|
@@ -109,6 +112,7 @@ def __init__(self, context, num_nodes, kafka, topic, message_validator=None, fro | |
| """ | ||
| super(ConsoleConsumer, self).__init__(context, num_nodes) | ||
| self.kafka = kafka | ||
| self.new_consumer = new_consumer | ||
| self.args = { | ||
| 'topic': topic, | ||
| } | ||
|
|
@@ -119,6 +123,19 @@ def __init__(self, context, num_nodes, kafka, topic, message_validator=None, fro | |
| self.message_validator = message_validator | ||
| self.messages_consumed = {idx: [] for idx in range(1, num_nodes + 1)} | ||
|
|
||
| # Process client configuration | ||
|
Contributor
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. You can simply do The properties file already does the "null/None" check:
Contributor
Author
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. @granders Have made these changes.
Contributor
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. This seems not done in the latest patch.
Contributor
Author
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. @guozhangwang I think the change suggested by @granders was to remove the if-then-else around render() which was in the code earlier. That was removed in the latest patch (the code selection above is slightly confusing). Can you let me know if I have misunderstood the comment?
Contributor
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. @rajinisivaram @guozhangwang |
||
| self.prop_file = self.render('console_consumer.properties', consumer_timeout_ms=self.consumer_timeout_ms) | ||
|
|
||
| # Add security properties to the config. If security protocol is not specified, | ||
| # use the default in the template properties. | ||
| self.security_config = SecurityConfig(security_protocol, self.prop_file) | ||
| self.security_protocol = self.security_config.security_protocol | ||
| if self.new_consumer is None: | ||
| self.new_consumer = self.security_protocol == SecurityConfig.SSL | ||
| if self.security_protocol == SecurityConfig.SSL and not self.new_consumer: | ||
| raise Exception("SSL protocol is supported only with the new consumer") | ||
| self.prop_file += str(self.security_config) | ||
|
|
||
| @property | ||
| def start_cmd(self): | ||
| args = self.args.copy() | ||
|
|
@@ -129,9 +146,13 @@ def start_cmd(self): | |
|
|
||
| cmd = "export LOG_DIR=%s;" % ConsoleConsumer.LOG_DIR | ||
| cmd += " export KAFKA_LOG4J_OPTS=\"-Dlog4j.configuration=file:%s\";" % ConsoleConsumer.LOG4J_CONFIG | ||
| cmd += " /opt/kafka/bin/kafka-console-consumer.sh --topic %(topic)s --zookeeper %(zk_connect)s" \ | ||
| cmd += " /opt/kafka/bin/kafka-console-consumer.sh --topic %(topic)s" \ | ||
| " --consumer.config %(config_file)s" % args | ||
|
|
||
| if self.new_consumer: | ||
| cmd += " --new-consumer --bootstrap-server %s" % self.kafka.bootstrap_servers() | ||
| else: | ||
| cmd += " --zookeeper %(zk_connect)s" % args | ||
| if self.from_beginning: | ||
| cmd += " --from-beginning" | ||
|
|
||
|
|
@@ -152,15 +173,10 @@ def alive(self, node): | |
| def _worker(self, idx, node): | ||
| node.account.ssh("mkdir -p %s" % ConsoleConsumer.PERSISTENT_ROOT, allow_fail=False) | ||
|
|
||
| # Create and upload config file | ||
| if self.consumer_timeout_ms is not None: | ||
| prop_file = self.render('console_consumer.properties', consumer_timeout_ms=self.consumer_timeout_ms) | ||
| else: | ||
| prop_file = self.render('console_consumer.properties') | ||
|
|
||
| self.logger.info("console_consumer.properties:") | ||
| self.logger.info(prop_file) | ||
| node.account.create_file(ConsoleConsumer.CONFIG_FILE, prop_file) | ||
| self.logger.info(self.prop_file) | ||
| node.account.create_file(ConsoleConsumer.CONFIG_FILE, self.prop_file) | ||
| self.security_config.setup_node(node) | ||
|
|
||
| # Create and upload log properties | ||
| log_config = self.render('tools_log4j.properties', log_file=ConsoleConsumer.LOG_FILE) | ||
|
|
@@ -190,4 +206,5 @@ def clean_node(self, node): | |
| (self.__class__.__name__, node.account)) | ||
| node.account.kill_process("java", clean_shutdown=False, allow_fail=True) | ||
| node.account.ssh("rm -rf %s" % ConsoleConsumer.PERSISTENT_ROOT, allow_fail=False) | ||
| self.security_config.clean_node(node) | ||
|
|
||
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 these be added before or after the command line options? If we load them before, the default values for options would override custom settings from the
consumer.configfile even if the command line parameters were not specified.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.
Interesting. Ideally, specified command-line settings would override the properties, but it seems like that would be a bigger change. Perhaps this should behave as the
ConsoleConsumeruntil we can overhaul this. It looks like the change here does that, right?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.
Agreed, ideally if they were specified they would override, but if unspecified it would use values from the file. Not sure how easy that is to get working with this options library. I could have sworn I checked one of the other tools and found it using the behavior I expected, but now can't find it. I don't think this is make-or-break. I was just raising it since the behavior is unintuitive to me and although the performance tools are less critical, we probably wouldn't want to change their behavior that significantly after releasing a version with support for the
consumer.configoption.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 do completely agree. However, I think all the tools currently do it this way and so I have kept it consistent. I will raise another JIRA to fix all the tools.