[#290] Fixed tests logs metrics
Some checks reported warnings
DCO check / Commits Check (pull_request) Has been cancelled
Some checks reported warnings
DCO check / Commits Check (pull_request) Has been cancelled
This commit is contained in:
parent
108aae59dd
commit
d9c6346984
1 changed files with 15 additions and 10 deletions
|
@ -16,37 +16,42 @@ from frostfs_testlib.testing.test_control import wait_for_success
|
||||||
|
|
||||||
class TestLogsMetrics(ClusterTestBase):
|
class TestLogsMetrics(ClusterTestBase):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
def revert_all(self, cluster_state_controller: ClusterStateController):
|
||||||
|
yield
|
||||||
|
cluster_state_controller.manager(ConfigStateManager).revert_all()
|
||||||
|
|
||||||
def restart_storage_service(self, cluster_state_controller: ClusterStateController) -> datetime:
|
def restart_storage_service(self, cluster_state_controller: ClusterStateController) -> datetime:
|
||||||
config_manager = cluster_state_controller.manager(ConfigStateManager)
|
config_manager = cluster_state_controller.manager(ConfigStateManager)
|
||||||
config_manager.csc.stop_services_of_type(StorageNode)
|
config_manager.csc.stop_services_of_type(StorageNode)
|
||||||
restart_time = datetime.now(timezone.utc)
|
restart_time = datetime.now(timezone.utc)
|
||||||
config_manager.csc.start_services_of_type(StorageNode)
|
config_manager.csc.start_services_of_type(StorageNode)
|
||||||
yield restart_time
|
return restart_time
|
||||||
|
|
||||||
cluster_state_controller.manager(ConfigStateManager).revert_all()
|
|
||||||
|
|
||||||
@wait_for_success(interval=10)
|
@wait_for_success(interval=10)
|
||||||
def check_metrics_in_node(self, cluster_node: ClusterNode, restart_time: datetime, log_priority: str = None, **metrics_greps):
|
def check_metrics_in_node(self, cluster_node: ClusterNode, restart_time: datetime, log_priority: str = None, **metrics_greps):
|
||||||
counter_logs = self.get_count_logs_by_level(cluster_node, metrics_greps.get("level"), restart_time, log_priority)
|
current_time = datetime.now(timezone.utc)
|
||||||
counter_metrics = get_metrics_value(cluster_node, **metrics_greps)
|
counter_metrics = get_metrics_value(cluster_node, **metrics_greps)
|
||||||
|
counter_logs = self.get_count_logs_by_level(cluster_node, metrics_greps.get("level"), restart_time, current_time, log_priority)
|
||||||
assert counter_logs == counter_metrics, f"counter_logs: {counter_logs}, counter_metrics: {counter_metrics} in node: {cluster_node}"
|
assert counter_logs == counter_metrics, f"counter_logs: {counter_logs}, counter_metrics: {counter_metrics} in node: {cluster_node}"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_count_logs_by_level(cluster_node: ClusterNode, log_level: str, after_time: datetime, log_priority: str):
|
def get_count_logs_by_level(cluster_node: ClusterNode, log_level: str, after_time: datetime, until_time: datetime, log_priority: str):
|
||||||
count_logs = 0
|
count_logs = 0
|
||||||
try:
|
try:
|
||||||
logs = cluster_node.host.get_filtered_logs(log_level, unit="frostfs-storage", since=after_time, priority=log_priority)
|
logs = cluster_node.host.get_filtered_logs(
|
||||||
result = re.findall(rf"\s+{log_level}\s+", logs)
|
log_level, unit="frostfs-storage", since=after_time, until=until_time, priority=log_priority
|
||||||
|
)
|
||||||
|
result = re.findall(rf"Z\s+{log_level}\s+", logs)
|
||||||
count_logs += len(result)
|
count_logs += len(result)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
...
|
...
|
||||||
return count_logs
|
return count_logs
|
||||||
|
|
||||||
@allure.title("Metrics for the log counter")
|
@allure.title("Metrics for the log counter")
|
||||||
def test_log_counter_metrics(self, cluster: Cluster, restart_storage_service: datetime):
|
def test_log_counter_metrics(self, cluster_state_controller: ClusterStateController, revert_all):
|
||||||
restart_time = restart_storage_service
|
restart_time = self.restart_storage_service(cluster_state_controller)
|
||||||
with reporter.step("Select random node"):
|
with reporter.step("Select random node"):
|
||||||
node = random.choice(cluster.cluster_nodes)
|
node = random.choice(self.cluster.cluster_nodes)
|
||||||
|
|
||||||
with reporter.step(f"Check metrics count logs with level 'info'"):
|
with reporter.step(f"Check metrics count logs with level 'info'"):
|
||||||
self.check_metrics_in_node(
|
self.check_metrics_in_node(
|
||||||
|
|
Loading…
Reference in a new issue