From 19a690361d7b1e8aed79a4b60085105816ab0742 Mon Sep 17 00:00:00 2001 From: Ilyas Niyazov Date: Tue, 27 Aug 2024 08:33:55 +0300 Subject: [PATCH] [#294] Fixed test metrics garbage collector --- .../metrics/test_garbage_collector_metrics.py | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/pytest_tests/testsuites/metrics/test_garbage_collector_metrics.py b/pytest_tests/testsuites/metrics/test_garbage_collector_metrics.py index d59e2cd7..58d0be94 100644 --- a/pytest_tests/testsuites/metrics/test_garbage_collector_metrics.py +++ b/pytest_tests/testsuites/metrics/test_garbage_collector_metrics.py @@ -33,9 +33,7 @@ class TestGarbageCollectorMetrics(ClusterTestBase): return sum(map(int, result)) @allure.title("Garbage collector expire_at object") - def test_garbage_collector_metrics_expire_at_object( - self, simple_object_size: ObjectSize, default_wallet: WalletInfo, cluster: Cluster - ): + def test_garbage_collector_metrics_expire_at_object(self, simple_object_size: ObjectSize, default_wallet: WalletInfo, cluster: Cluster): file_path = generate_file(simple_object_size.value) placement_policy = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X" metrics_step = 1 @@ -43,9 +41,7 @@ class TestGarbageCollectorMetrics(ClusterTestBase): with reporter.step("Get current garbage collector metrics for each nodes"): metrics_counter = {} for node in cluster.cluster_nodes: - metrics_counter[node] = get_metrics_value( - node, command="frostfs_node_garbage_collector_marked_for_removal_objects_total" - ) + metrics_counter[node] = get_metrics_value(node, command="frostfs_node_garbage_collector_marked_for_removal_objects_total") with reporter.step(f"Create container with policy {placement_policy}"): cid = create_container(default_wallet, self.shell, cluster.default_rpc_endpoint, placement_policy) @@ -63,18 +59,12 @@ class TestGarbageCollectorMetrics(ClusterTestBase): with reporter.step("Get object nodes"): object_storage_nodes = get_nodes_with_object(cid, oid, self.shell, cluster.storage_nodes) - object_nodes = [ - cluster_node - for cluster_node in cluster.cluster_nodes - if cluster_node.storage_node in object_storage_nodes - ] + object_nodes = [cluster_node for cluster_node in cluster.cluster_nodes if cluster_node.storage_node in object_storage_nodes] with reporter.step("Tick Epoch"): self.tick_epochs(epochs_to_tick=2, wait_block=2) - with reporter.step( - f"Check garbage collector metrics 'the counter should increase by {metrics_step}' in object nodes" - ): + with reporter.step(f"Check garbage collector metrics 'the counter should increase by {metrics_step}' in object nodes"): for node in object_nodes: metrics_counter[node] += metrics_step @@ -86,30 +76,38 @@ class TestGarbageCollectorMetrics(ClusterTestBase): ) @allure.title("Garbage collector delete object") - def test_garbage_collector_metrics_deleted_objects( - self, simple_object_size: ObjectSize, default_wallet: WalletInfo, cluster: Cluster - ): + def test_garbage_collector_metrics_deleted_objects(self, simple_object_size: ObjectSize, default_wallet: WalletInfo, cluster: Cluster): file_path = generate_file(simple_object_size.value) placement_policy = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X" metrics_step = 1 - with reporter.step("Select random node"): - node = random.choice(cluster.cluster_nodes) - - with reporter.step("Get current garbage collector metrics for selected node"): - metrics_counter = get_metrics_value(node, command="frostfs_node_garbage_collector_deleted_objects_total") + with reporter.step("Get current garbage collector metrics for each nodes"): + metrics_counter = {} + for node in cluster.cluster_nodes: + metrics_counter[node] = get_metrics_value(node, command="frostfs_node_garbage_collector_deleted_objects_total") with reporter.step(f"Create container with policy {placement_policy}"): cid = create_container(default_wallet, self.shell, node.storage_node.get_rpc_endpoint(), placement_policy) - with reporter.step("Put object to selected node"): - oid = put_object(default_wallet, file_path, cid, self.shell, node.storage_node.get_rpc_endpoint()) + with reporter.step("Put object to random node"): + oid = put_object_to_random_node( + default_wallet, + file_path, + cid, + self.shell, + cluster, + ) + + with reporter.step("Get object nodes"): + object_storage_nodes = get_nodes_with_object(cid, oid, self.shell, cluster.storage_nodes) + object_nodes = [cluster_node for cluster_node in cluster.cluster_nodes if cluster_node.storage_node in object_storage_nodes] with reporter.step("Delete file, wait until gc remove object"): delete_object(default_wallet, cid, oid, self.shell, node.storage_node.get_rpc_endpoint()) with reporter.step(f"Check garbage collector metrics 'the counter should increase by {metrics_step}'"): - metrics_counter += metrics_step - check_metrics_counter( - [node], counter_exp=metrics_counter, command="frostfs_node_garbage_collector_deleted_objects_total" - ) + for node in object_nodes: + exp_metrics_counter = metrics_counter[node] + metrics_step + check_metrics_counter( + [node], counter_exp=exp_metrics_counter, command="frostfs_node_garbage_collector_deleted_objects_total" + )