87 lines
4.1 KiB
Python
87 lines
4.1 KiB
Python
import math
|
|
|
|
import allure
|
|
import pytest
|
|
from frostfs_testlib import reporter
|
|
from frostfs_testlib.steps.cli.container import create_container
|
|
from frostfs_testlib.steps.cli.object import delete_object, put_object_to_random_node
|
|
from frostfs_testlib.steps.metrics import check_metrics_counter
|
|
from frostfs_testlib.steps.storage_policy import get_nodes_with_object
|
|
from frostfs_testlib.storage.cluster import Cluster
|
|
from frostfs_testlib.storage.dataclasses.object_size import ObjectSize
|
|
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
|
|
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
|
|
from frostfs_testlib.utils.file_utils import generate_file
|
|
|
|
|
|
@pytest.mark.container
|
|
class TestContainerMetrics(ClusterTestBase):
|
|
@allure.title("Container metrics (obj_size={object_size})")
|
|
def test_container_metrics(
|
|
self, object_size: ObjectSize, max_object_size: int, default_wallet: WalletInfo, cluster: Cluster
|
|
):
|
|
file_path = generate_file(object_size.value)
|
|
placement_policy = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X"
|
|
copies = 2
|
|
object_chunks = 0
|
|
head_object = 1
|
|
link_object = 0
|
|
if object_size.value > max_object_size:
|
|
object_chunks = math.ceil(object_size.value / max_object_size)
|
|
link_object = 1
|
|
|
|
with reporter.step(f"Create container with policy {placement_policy}"):
|
|
cid = create_container(default_wallet, self.shell, cluster.default_rpc_endpoint, placement_policy)
|
|
|
|
with reporter.step("Put object to random node"):
|
|
oid = put_object_to_random_node(
|
|
wallet=default_wallet,
|
|
path=file_path,
|
|
cid=cid,
|
|
shell=self.shell,
|
|
cluster=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("Check metric appears in node where the object is located"):
|
|
count_metrics = (object_chunks + head_object + link_object) * copies
|
|
check_metrics_counter(
|
|
object_nodes, counter_exp=count_metrics, command="container_objects_total", cid=cid, type="phy"
|
|
)
|
|
check_metrics_counter(
|
|
object_nodes, counter_exp=count_metrics, command="container_objects_total", cid=cid, type="logic"
|
|
)
|
|
check_metrics_counter(
|
|
object_nodes, counter_exp=copies, command="container_objects_total", cid=cid, type="user"
|
|
)
|
|
|
|
with reporter.step("Delete file, wait until gc remove object"):
|
|
delete_object(default_wallet, cid, oid, self.shell, cluster.default_rpc_endpoint)
|
|
|
|
with reporter.step(f"Check container metrics 'the counter should equal {len(object_nodes)}' in object nodes"):
|
|
check_metrics_counter(
|
|
object_nodes, counter_exp=len(object_nodes), command="container_objects_total", cid=cid, type="phy"
|
|
)
|
|
check_metrics_counter(
|
|
object_nodes, counter_exp=len(object_nodes), command="container_objects_total", cid=cid, type="logic"
|
|
)
|
|
check_metrics_counter(object_nodes, counter_exp=0, command="container_objects_total", cid=cid, type="user")
|
|
|
|
with reporter.step("Check metrics(Phy, Logic, User) in each nodes"):
|
|
# Phy and Logic metrics are 4, because in rule 'CBF 2 SELECT 2 FROM', cbf2*sel2=4
|
|
check_metrics_counter(
|
|
cluster.cluster_nodes, counter_exp=4, command="container_objects_total", cid=cid, type="phy"
|
|
)
|
|
check_metrics_counter(
|
|
cluster.cluster_nodes, counter_exp=4, command="container_objects_total", cid=cid, type="logic"
|
|
)
|
|
check_metrics_counter(
|
|
cluster.cluster_nodes, counter_exp=0, command="container_objects_total", cid=cid, type="user"
|
|
)
|