Skip to content

Commit

Permalink
rptest/admin: add key parameter to get_cluster_config()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
WillemKauf committed Jul 31, 2024
1 parent 82f4f3b commit 8392ed1
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/rptest/services/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
83 changes: 83 additions & 0 deletions tests/rptest/tests/cluster_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 8392ed1

Please sign in to comment.