[#264] fix tests metrics object and logs

This commit is contained in:
Ilyas Niyazov 2024-07-01 13:24:10 +03:00
parent cc440f9c12
commit 0cbf319835
2 changed files with 29 additions and 10 deletions

View file

@ -26,17 +26,25 @@ class TestLogsMetrics(ClusterTestBase):
cluster_state_controller.manager(ConfigStateManager).revert_all() 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, **metrics_greps): def check_metrics_in_node(
counter_exp = self.get_count_logs_by_level(cluster_node, metrics_greps.get("level"), restart_time) self, cluster_node: ClusterNode, restart_time: datetime, log_priority: str = None, **metrics_greps
counter_act = get_metrics_value(cluster_node, **metrics_greps) ):
assert counter_act == counter_exp, f"Expected: {counter_exp}, Actual: {counter_act} in node: {cluster_node}" counter_logs = self.get_count_logs_by_level(
cluster_node, metrics_greps.get("level"), restart_time, log_priority
)
counter_metrics = get_metrics_value(cluster_node, **metrics_greps)
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): def get_count_logs_by_level(cluster_node: ClusterNode, log_level: str, after_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) logs = cluster_node.host.get_filtered_logs(
result = re.findall(rf"Z\s+{log_level}\s+", logs) log_level, unit="frostfs-storage", since=after_time, priority=log_priority
)
result = re.findall(rf"\s+{log_level}\s+", logs)
count_logs += len(result) count_logs += len(result)
except RuntimeError as e: except RuntimeError as e:
... ...
@ -49,7 +57,16 @@ class TestLogsMetrics(ClusterTestBase):
node = random.choice(cluster.cluster_nodes) node = random.choice(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(node, restart_time, command="frostfs_node_logger_entry_count", level="info") self.check_metrics_in_node(
node,
restart_time,
log_priority="6..6",
command="frostfs_node_logger_entry_count",
level="info",
dropped="false",
)
with reporter.step(f"Check metrics count logs with level 'error'"): with reporter.step(f"Check metrics count logs with level 'error'"):
self.check_metrics_in_node(node, restart_time, command="frostfs_node_logger_entry_count", level="error") self.check_metrics_in_node(
node, restart_time, command="frostfs_node_logger_entry_count", level="error", dropped="false"
)

View file

@ -62,7 +62,9 @@ class TestObjectMetrics(ClusterTestBase):
) )
for node in object_nodes: for node in object_nodes:
all_metrics = node.metrics.storage.get_all_metrics() all_metrics = node.metrics.storage.get_metrics_search_by_greps(
command="frostfs_node_engine_container_size_byte"
)
assert ( assert (
cid not in all_metrics.stdout cid not in all_metrics.stdout
), "metrics of removed containers shouldn't appear in the storage node" ), "metrics of removed containers shouldn't appear in the storage node"