Skip to content
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

MINOR: add wait_for_assigned_partitions to console-consumer #8192

Merged
merged 4 commits into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions tests/kafkatest/services/console_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import os

from ducktape.services.background_thread import BackgroundThreadService
from ducktape.utils.util import wait_until

from kafkatest.directory_layout.kafka_path import KafkaPathResolverMixin
from kafkatest.services.monitor.jmx import JmxMixin
from kafkatest.services.monitor.jmx import JmxMixin, JmxTool
from kafkatest.version import DEV_BRANCH, LATEST_0_8_2, LATEST_0_9, LATEST_0_10_0, V_0_9_0_0, V_0_10_0_0, V_0_11_0_0, V_2_0_0

"""
Expand Down Expand Up @@ -62,7 +63,8 @@ def __init__(self, context, num_nodes, kafka, topic, group_id="test-consumer-gro
client_id="console-consumer", print_key=False, jmx_object_names=None, jmx_attributes=None,
enable_systest_events=False, stop_timeout_sec=35, print_timestamp=False, print_partition=False,
isolation_level="read_uncommitted", jaas_override_variables=None,
kafka_opts_override="", client_prop_file_override="", consumer_properties={}):
kafka_opts_override="", client_prop_file_override="", consumer_properties={},
wait_until_partitions_assigned=False):
"""
Args:
context: standard context
Expand Down Expand Up @@ -124,6 +126,7 @@ def __init__(self, context, num_nodes, kafka, topic, group_id="test-consumer-gro
self.kafka_opts_override = kafka_opts_override
self.client_prop_file_override = client_prop_file_override
self.consumer_properties = consumer_properties
self.wait_until_partitions_assigned = wait_until_partitions_assigned


def prop_file(self, node):
Expand Down Expand Up @@ -273,8 +276,25 @@ def _worker(self, idx, node):
with self.lock:
self.read_jmx_output(idx, node)

def _wait_until_partitions_assigned(self, node, timeout_sec=60):
if self.jmx_object_names is not None:
raise Exception("'wait_until_partitions_assigned' is not supported while using 'jmx_object_names'/'jmx_attributes'")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not ideal but requires more refactoring to be able support multiple JmxTools running at once

jmx_tool = JmxTool(self.context, jmx_poll_ms=100)
jmx_tool.jmx_object_names = ["kafka.consumer:type=consumer-coordinator-metrics,client-id=%s" % self.client_id]
jmx_tool.jmx_attributes = ["assigned-partitions"]
jmx_tool.assigned_partitions_jmx_attr = "kafka.consumer:type=consumer-coordinator-metrics,client-id=%s:assigned-partitions" % self.client_id
jmx_tool.start_jmx_tool(self.idx(node), node)
jmx_tool.read_jmx_output(self.idx(node), node)
assigned_partitions_jmx_attr = "kafka.consumer:type=consumer-coordinator-metrics,client-id=%s:assigned-partitions" % self.client_id
wait_until(lambda: assigned_partitions_jmx_attr in jmx_tool.maximum_jmx_value,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be re-running read_jmx_output before checking this condition

timeout_sec=timeout_sec,
backoff_sec=.5,
err_msg="consumer was not assigned partitions within %d seconds" % timeout_sec)

def start_node(self, node):
BackgroundThreadService.start_node(self, node)
if self.wait_until_partitions_assigned:
self._wait_until_partitions_assigned(node)

def stop_node(self, node):
self.logger.info("%s Stopping node %s" % (self.__class__.__name__, str(node.account)))
Expand Down
19 changes: 17 additions & 2 deletions tests/kafkatest/services/monitor/jmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from ducktape.cluster.remoteaccount import RemoteCommandError
from ducktape.utils.util import wait_until

from kafkatest.directory_layout.kafka_path import KafkaPathResolverMixin
from kafkatest.version import get_version, V_0_11_0_0, DEV_BRANCH

class JmxMixin(object):
Expand All @@ -41,10 +43,11 @@ def __init__(self, num_nodes, jmx_object_names=None, jmx_attributes=None, jmx_po
self.jmx_tool_log = os.path.join(root, "jmx_tool.log")
self.jmx_tool_err_log = os.path.join(root, "jmx_tool.err.log")

def clean_node(self, node):
def clean_node(self, node, idx=None):
node.account.kill_java_processes(self.jmx_class_name(), clean_shutdown=False,
allow_fail=True)
idx = self.idx(node)
if idx is None:
idx = self.idx(node)
self.started[idx-1] = False
node.account.ssh("rm -f -- %s %s" % (self.jmx_tool_log, self.jmx_tool_err_log), allow_fail=False)

Expand Down Expand Up @@ -139,3 +142,15 @@ def read_jmx_output_all_nodes(self):

def jmx_class_name(self):
return "kafka.tools.JmxTool"

class JmxTool(JmxMixin, KafkaPathResolverMixin):
"""
Simple helper class for using the JmxTool directly instead of as a mix-in
"""
def __init__(self, text_context, *args, **kwargs):
JmxMixin.__init__(self, num_nodes=1, *args, **kwargs)
self.context = text_context

@property
def logger(self):
return self.context.logger
16 changes: 1 addition & 15 deletions tests/kafkatest/tests/core/fetch_from_follower_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,15 @@

from ducktape.mark.resource import cluster

from kafkatest.directory_layout.kafka_path import KafkaPathResolverMixin
from kafkatest.services.console_consumer import ConsoleConsumer
from kafkatest.services.kafka import KafkaService
from kafkatest.services.monitor.jmx import JmxMixin
from kafkatest.services.monitor.jmx import JmxTool
from kafkatest.services.verifiable_producer import VerifiableProducer
from kafkatest.services.zookeeper import ZookeeperService
from kafkatest.tests.produce_consume_validate import ProduceConsumeValidateTest
from kafkatest.utils import is_int


class JmxTool(JmxMixin, KafkaPathResolverMixin):
"""
Simple helper class for using the JmxTool directly instead of as a mix-in
"""
def __init__(self, text_context, *args, **kwargs):
JmxMixin.__init__(self, num_nodes=1, *args, **kwargs)
self.context = text_context

@property
def logger(self):
return self.context.logger


class FetchFromFollowerTest(ProduceConsumeValidateTest):

RACK_AWARE_REPLICA_SELECTOR = "org.apache.kafka.common.replica.RackAwareReplicaSelector"
Expand Down
5 changes: 3 additions & 2 deletions tests/kafkatest/tests/core/throttling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, test_context):
# ensure that the consumer is fully started before the producer starts
# so that we don't miss any messages. This timeout ensures the sufficient
# condition.
self.consumer_init_timeout_sec = 60
self.consumer_init_timeout_sec = 20
brianbushree marked this conversation as resolved.
Show resolved Hide resolved
self.num_brokers = 6
self.num_partitions = 3
self.kafka = KafkaService(test_context,
Expand Down Expand Up @@ -165,7 +165,8 @@ def test_throttled_reassignment(self, bounce_brokers):
self.topic,
consumer_timeout_ms=60000,
message_validator=is_int,
from_beginning=False)
from_beginning=False,
wait_until_partitions_assigned=True)

self.kafka.start()
bulk_producer.run()
Expand Down