From 8392ed1234d2e3abd6eb720d9aa0e7acd1c5364e Mon Sep 17 00:00:00 2001 From: Willem Kaufmann Date: Wed, 31 Jul 2024 17:31:05 -0400 Subject: [PATCH] `rptest/admin`: add `key` parameter to `get_cluster_config()` In order to allow for requests to be made by specifying a single key to the admin endpoint. Also adds some test coverage for use of aliased properties with `get` and `set` functionality with the admin endpoint and the new improvements. --- tests/rptest/services/admin.py | 6 +- tests/rptest/tests/cluster_config_test.py | 83 +++++++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/tests/rptest/services/admin.py b/tests/rptest/services/admin.py index 291bdb733f3af..362c88e22a6b3 100644 --- a/tests/rptest/services/admin.py +++ b/tests/rptest/services/admin.py @@ -691,8 +691,10 @@ def _request(self, def get_status_ready(self, node=None): return self._request("GET", "status/ready", node=node).json() - def get_cluster_config(self, node=None, include_defaults=None): - if include_defaults is not None: + def get_cluster_config(self, node=None, include_defaults=None, key=None): + if key is not None: + kwargs = {"params": {"key": key}} + elif include_defaults is not None: kwargs = {"params": {"include_defaults": include_defaults}} else: kwargs = {} diff --git a/tests/rptest/tests/cluster_config_test.py b/tests/rptest/tests/cluster_config_test.py index d039488e465d4..23ed1c116db22 100644 --- a/tests/rptest/tests/cluster_config_test.py +++ b/tests/rptest/tests/cluster_config_test.py @@ -1089,6 +1089,12 @@ class Example(NamedTuple): strval: str yamlval: Any + class AliasedExample(NamedTuple): + key: str + alias: str + strval: str + yamlval: Any + valid_examples = [ Example("kafka_qdc_enable", "true", True), Example("append_chunk_size", "32768", 32768), @@ -1097,6 +1103,17 @@ class Example(NamedTuple): Example("kafka_memory_share_for_fetch", "0.6", 0.6) ] + valid_aliased_examples = [ + AliasedExample("data_transforms_per_core_memory_reservation", + "wasm_per_core_memory_reservation", "123456789", + 123456789), + AliasedExample("cloud_storage_graceful_transfer_timeout_ms", + "cloud_storage_graceful_transfer_timeout", "1024", + 1024), + AliasedExample("cloud_storage_max_segment_readers_per_shard", + "cloud_storage_max_readers_per_shard", "128", 128) + ] + def yamlize(input) -> str: """Create a YAML representation that matches what yaml-cpp produces: PyYAML includes trailing @@ -1127,6 +1144,72 @@ def yamlize(input) -> str: self.logger.info(f"API readback for {e.key} '{api_readback}'") assert api_readback == e.yamlval + # Check that valid changes are accepted when config is set by key, + # and both alias and key are used for get. + for e in valid_aliased_examples: + self.logger.info( + f"Checking aliased {e.key}={e.alias}={e.strval} ({e.yamlval})") + self.rpk.cluster_config_set(e.key, e.strval) + + # CLI readback should give same as we set + cli_readback_key = self.rpk.cluster_config_get(e.key) + cli_readback_alias = self.rpk.cluster_config_get(e.alias) + + expect_cli_readback = yamlize(e.yamlval) + + self.logger.info( + f"CLI readback for key '{cli_readback_key}', for alias '{cli_readback_alias}', expect '{expect_cli_readback}'" + ) + assert cli_readback_key == cli_readback_alias == expect_cli_readback + + # API readback should give properly structured+typed value + api_readback_key = self.admin.get_cluster_config(key=e.key)[e.key] + api_readback_alias = self.admin.get_cluster_config( + key=e.alias)[e.key] + self.logger.info( + f"API readback for {e.key} '{api_readback_key}', for {e.alias} '{api_readback_alias}'" + ) + assert api_readback_key == api_readback_alias == e.yamlval + + #Reset valid_aliased_examples before we attempt to repeat tests by setting with alias. + valid_aliased_examples = [ + AliasedExample("data_transforms_per_core_memory_reservation", + "wasm_per_core_memory_reservation", "987654321", + 987654321), + AliasedExample("cloud_storage_graceful_transfer_timeout_ms", + "cloud_storage_graceful_transfer_timeout", "4096", + 4096), + AliasedExample("cloud_storage_max_segment_readers_per_shard", + "cloud_storage_max_readers_per_shard", "512", 512) + ] + + # Check that valid changes are accepted when config is set by alias, + # and both alias and key are used for get. + for e in valid_aliased_examples: + self.logger.info( + f"Checking aliased {e.key}={e.alias}={e.strval} ({e.yamlval})") + self.rpk.cluster_config_set(e.alias, e.strval) + + # CLI readback should give same as we set + cli_readback_key = self.rpk.cluster_config_get(e.key) + cli_readback_alias = self.rpk.cluster_config_get(e.alias) + + expect_cli_readback = yamlize(e.yamlval) + + self.logger.info( + f"CLI readback for key '{cli_readback_key}', for alias '{cli_readback_alias}', expect '{expect_cli_readback}'" + ) + assert cli_readback_key == cli_readback_alias == expect_cli_readback + + # API readback should give properly structured+typed value + api_readback_key = self.admin.get_cluster_config(key=e.key)[e.key] + api_readback_alias = self.admin.get_cluster_config( + key=e.alias)[e.key] + self.logger.info( + f"API readback for {e.key} '{api_readback_key}', for {e.alias} '{api_readback_alias}'" + ) + assert api_readback_key == api_readback_alias == e.yamlval + # Check that the `set` command hits proper validation paths invalid_examples = [ ("kafka_qdc_enable", "rhubarb"),