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 <amnon@scylladb.com>
(cherry picked from commit 4d57a43815)
This commit is contained in:
Amnon Heiman
2024-09-17 17:19:19 +03:00
committed by Mergify
parent 3db67faa8a
commit a35e138b22

View File

@@ -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: