kafka_neu-76e4d1b5-8b7b-4eb8-ad4b-86e90f693c1d.zip-extract/kafka-4.2.0-src/tests/kafkatest/services/replica_verification_tool.py

Path
kafka_neu-76e4d1b5-8b7b-4eb8-ad4b-86e90f693c1d.zip-extract/kafka-4.2.0-src/tests/kafkatest/services/replica_verification_tool.py
Status
scanned
Type
file
Name
replica_verification_tool.py
Extension
.py
Programming language
Python
Mime type
text/x-script.python
File type
Python script, ASCII text executable
Tag

      
    
Rootfs path

      
    
Size
4086 (4.0 KB)
MD5
5bb21a54238a4855aaea316159d98dd7
SHA1
5ae7938389c94754eb589dc17d7b816a1dc55ec4
SHA256
e5830b3ffbbab4237c25c6511a87efe18dda463fd1f82c3ff3b5b92ce9986e67
SHA512

      
    
SHA1_git
ecc47b2a6dfba504adaec08bad89d2af2267b99e
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
replica_verification_tool.py | 4.0 KB |

# 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.directory_layout.kafka_path import KafkaPathResolverMixin from kafkatest.services.security.security_config import SecurityConfig import re class ReplicaVerificationTool(KafkaPathResolverMixin, 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", stop_timeout_sec=30, tls_version=None): 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.tls_version = tls_version self.security_config = SecurityConfig(self.context, security_protocol, tls_version=tls_version) self.partition_lag = {} self.stop_timeout_sec = stop_timeout_sec 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 ([a-zA-Z0-9._-]+-[0-9]+) 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.get(topic_partition, -1) self.logger.debug("Returning lag for {} as {}".format(topic_partition, lag)) return lag def start_cmd(self, node): cmd = self.path.script("kafka-replica-verification.sh", node) cmd += " --broker-list %s --topics-include %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_java_processes("ReplicaVerificationTool", clean_shutdown=True, allow_fail=True) stopped = self.wait_node(node, timeout_sec=self.stop_timeout_sec) assert stopped, "Node %s: did not stop within the specified timeout of %s seconds" % \ (str(node.account), str(self.stop_timeout_sec)) def clean_node(self, node): node.account.kill_java_processes("ReplicaVerificationTool", clean_shutdown=False, allow_fail=True) node.account.ssh("rm -rf /mnt/replica_verification_tool.log", allow_fail=False)
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
23.8
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 8 8
Package URL License Primary language
pkg:pypi/kafkatest@4.2.0 apache-2.0 Python