-
Notifications
You must be signed in to change notification settings - Fork 15.2k
KAFKA-3382: Add system test for ReplicationVerificationTool #1160
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e7db74
KAFKA-3382: Add system test for ReplicationVerificationTool
b0a68b6
Address review feedback.
1af30f6
Revert unwanted change.
b2a513d
Track latest lag, instead of max lag.
71bd055
Move replica_verification_test under tools
9c10c67
Kill ReplicaVerificationTool during node cleanup
e86769e
Add stop_node to replica_verification_tool
11c084c
Move doc string inside method, python way.
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 hidden or 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,81 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from ducktape.services.background_thread import BackgroundThreadService | ||
|
|
||
| from kafkatest.services.kafka.directory import kafka_dir | ||
| from kafkatest.services.security.security_config import SecurityConfig | ||
|
|
||
| import re | ||
|
|
||
| class ReplicaVerificationTool(BackgroundThreadService): | ||
|
|
||
| logs = { | ||
| "producer_log": { | ||
| "path": "/mnt/replica_verification_tool.log", | ||
| "collect_default": False} | ||
| } | ||
|
|
||
| def __init__(self, context, num_nodes, kafka, topic, report_interval_ms, security_protocol="PLAINTEXT"): | ||
| super(ReplicaVerificationTool, self).__init__(context, num_nodes) | ||
|
|
||
| self.kafka = kafka | ||
| self.topic = topic | ||
| self.report_interval_ms = report_interval_ms | ||
| self.security_protocol = security_protocol | ||
| self.security_config = SecurityConfig(security_protocol) | ||
| self.partition_lag = {} | ||
|
|
||
| def _worker(self, idx, node): | ||
| cmd = self.start_cmd(node) | ||
| self.logger.debug("ReplicaVerificationTool %d command: %s" % (idx, cmd)) | ||
| self.security_config.setup_node(node) | ||
| for line in node.account.ssh_capture(cmd): | ||
| self.logger.debug("Parsing line:{}".format(line)) | ||
|
|
||
| parsed = re.search('.*max lag is (.+?) for partition \[(.+?)\] at', line) | ||
| if parsed: | ||
| lag = int(parsed.group(1)) | ||
| topic_partition = parsed.group(2) | ||
| self.logger.debug("Setting max lag for {} as {}".format(topic_partition, lag)) | ||
| self.partition_lag[topic_partition] = lag | ||
|
|
||
| def get_lag_for_partition(self, topic, partition): | ||
| """ | ||
| Get latest lag for given topic-partition | ||
|
|
||
| Args: | ||
| topic: a topic | ||
| partition: a partition of the topic | ||
| """ | ||
| topic_partition = topic + ',' + str(partition) | ||
| lag = self.partition_lag[topic_partition] | ||
| self.logger.debug("Retuning lag for {} as {}".format(topic_partition, lag)) | ||
| return lag | ||
|
|
||
| def start_cmd(self, node): | ||
| cmd = "/opt/%s/bin/" % kafka_dir(node) | ||
| cmd += "kafka-run-class.sh kafka.tools.ReplicaVerificationTool" | ||
| cmd += " --broker-list %s --topic-white-list %s --time -2 --report-interval-ms %s" % (self.kafka.bootstrap_servers(self.security_protocol), self.topic, self.report_interval_ms) | ||
|
|
||
| cmd += " 2>> /mnt/replica_verification_tool.log | tee -a /mnt/replica_verification_tool.log &" | ||
| return cmd | ||
|
|
||
| def stop_node(self, node): | ||
| node.account.kill_process("java", clean_shutdown=True, allow_fail=True) | ||
|
|
||
| def clean_node(self, node): | ||
| node.account.kill_process("java", clean_shutdown=False, allow_fail=True) | ||
| node.account.ssh("rm -rf /mnt/replica_verification_tool.log", allow_fail=False) | ||
This file contains hidden or 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 hidden or 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,88 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| from ducktape.utils.util import wait_until | ||
| from ducktape.tests.test import Test | ||
| from kafkatest.services.verifiable_producer import VerifiableProducer | ||
|
|
||
| from kafkatest.services.zookeeper import ZookeeperService | ||
| from kafkatest.services.kafka import KafkaService | ||
| from kafkatest.services.replica_verification_tool import ReplicaVerificationTool | ||
|
|
||
| TOPIC = "topic-replica-verification" | ||
| REPORT_INTERVAL_MS = 1000 | ||
|
|
||
| class ReplicaVerificationToolTest(Test): | ||
| """ | ||
| Tests ReplicaVerificationTool | ||
| """ | ||
| def __init__(self, test_context): | ||
| super(ReplicaVerificationToolTest, self).__init__(test_context) | ||
| self.num_zk = 1 | ||
| self.num_brokers = 2 | ||
| self.messages_received_count = 0 | ||
| self.topics = { | ||
| TOPIC: {'partitions': 1, 'replication-factor': 2} | ||
| } | ||
|
|
||
| self.zk = ZookeeperService(test_context, self.num_zk) | ||
| self.kafka = None | ||
| self.producer = None | ||
| self.replica_verifier = None | ||
|
|
||
| def setUp(self): | ||
| self.zk.start() | ||
|
|
||
| def start_kafka(self, security_protocol, interbroker_security_protocol): | ||
| self.kafka = KafkaService( | ||
| self.test_context, self.num_brokers, | ||
| self.zk, security_protocol=security_protocol, | ||
| interbroker_security_protocol=interbroker_security_protocol, topics=self.topics) | ||
| self.kafka.start() | ||
|
|
||
| def start_replica_verification_tool(self, security_protocol): | ||
| self.replica_verifier = ReplicaVerificationTool(self.test_context, 1, self.kafka, TOPIC, report_interval_ms=REPORT_INTERVAL_MS, security_protocol=security_protocol) | ||
| self.replica_verifier.start() | ||
|
|
||
| def start_producer(self, max_messages, acks, timeout): | ||
| # This will produce to kafka cluster | ||
| self.producer = VerifiableProducer(self.test_context, num_nodes=1, kafka=self.kafka, topic=TOPIC, throughput=1000, acks=acks, max_messages=max_messages) | ||
| current_acked = self.producer.num_acked | ||
| self.logger.info("current_acked = %s" % current_acked) | ||
| self.producer.start() | ||
| wait_until(lambda: acks == 0 or self.producer.num_acked >= current_acked + max_messages, timeout_sec=timeout, | ||
| err_msg="Timeout awaiting messages to be produced and acked") | ||
|
|
||
| def stop_producer(self): | ||
| self.producer.stop() | ||
|
|
||
| def test_replica_lags(self, security_protocol='PLAINTEXT'): | ||
| """ | ||
| Tests ReplicaVerificationTool | ||
| :return: None | ||
| """ | ||
| self.start_kafka(security_protocol, security_protocol) | ||
| self.start_replica_verification_tool(security_protocol) | ||
| self.start_producer(max_messages=10, acks=-1, timeout=15) | ||
| # Verify that there is no lag in replicas and is correctly reported by ReplicaVerificationTool | ||
| wait_until(lambda: self.replica_verifier.get_lag_for_partition(TOPIC, 0) == 0, timeout_sec=10, | ||
| err_msg="Timed out waiting to reach zero replica lags.") | ||
| self.stop_producer() | ||
|
|
||
| self.start_producer(max_messages=1000, acks=0, timeout=5) | ||
| # Verify that there is lag in replicas and is correctly reported by ReplicaVerificationTool | ||
| wait_until(lambda: self.replica_verifier.get_lag_for_partition(TOPIC, 0) > 0, timeout_sec=10, | ||
| err_msg="Timed out waiting to reach non-zero number of replica lags.") |
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.
Was there a
stop_nodemethod here before? It's a good idea to have bothstop_nodeandclean_nodedefined.Or, if you expect the process to actually be gone by the time we hit the "stop" portion of the service lifecycle (
stop_nodeis the "graceful shutdown" option), it's helpful to do a check that the process is actually gone (i.e. check that the actual state matches our expectations of what the state should be) and at least log a warning if the process is still running