From a35e138b229e38dcc3e99eadb4b28cd92d889b7b Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Tue, 17 Sep 2024 17:19:19 +0300 Subject: [PATCH] alternator:test_metrics Add validating the increased value The `check_increases_operation` now allows override the checked metric. Additionally, a custom validation value can now be passed, which make it possible to validate the amount by which a value has changed, rather than just validating that the value increased. The default behavior of validating that values have increased remains unchanged, ensuring backward compatibility. Signed-off-by: Amnon Heiman (cherry picked from commit 4d57a43815738a10fe5c3bf2de826baf1e05f787) --- test/alternator/test_metrics.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/alternator/test_metrics.py b/test/alternator/test_metrics.py index bf1952e8ed..0f5be53b9c 100644 --- a/test/alternator/test_metrics.py +++ b/test/alternator/test_metrics.py @@ -104,13 +104,16 @@ def check_increases_metric(metrics, metric_names): assert saved_metrics[n] < get_metric(metrics, n, None, the_metrics), f'metric {n} did not increase' @contextmanager -def check_increases_operation(metrics, operation_names): +def check_increases_operation(metrics, operation_names, metric_name = 'scylla_alternator_operation', expected_value=None): the_metrics = get_metrics(metrics) - saved_metrics = { x: get_metric(metrics, 'scylla_alternator_operation', {'op': x}, the_metrics) for x in operation_names } + saved_metrics = { x: get_metric(metrics, metric_name, {'op': x}, the_metrics) for x in operation_names } yield the_metrics = get_metrics(metrics) for op in operation_names: - assert saved_metrics[op] < get_metric(metrics, 'scylla_alternator_operation', {'op': op}, the_metrics) + if expected_value: + assert expected_value == get_metric(metrics, metric_name, {'op': op}, the_metrics) - saved_metrics[op] + else: + assert saved_metrics[op] < get_metric(metrics, metric_name, {'op': op}, the_metrics) ###### Test for metrics that count DynamoDB API operations: