2024-05-30 09:25:04 +00:00
|
|
|
import random
|
|
|
|
import re
|
2024-06-25 13:23:25 +00:00
|
|
|
from datetime import datetime, timezone
|
2024-05-30 09:25:04 +00:00
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
|
|
|
from frostfs_testlib import reporter
|
2024-06-25 13:23:25 +00:00
|
|
|
from frostfs_testlib.steps.metrics import get_metrics_value
|
2024-05-30 09:25:04 +00:00
|
|
|
from frostfs_testlib.storage.cluster import Cluster, ClusterNode
|
|
|
|
from frostfs_testlib.storage.controllers.cluster_state_controller import ClusterStateController
|
|
|
|
from frostfs_testlib.storage.controllers.state_managers.config_state_manager import ConfigStateManager
|
|
|
|
from frostfs_testlib.storage.dataclasses.frostfs_services import StorageNode
|
|
|
|
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
|
|
|
|
from frostfs_testlib.testing.test_control import wait_for_success
|
|
|
|
|
|
|
|
|
2024-10-11 09:30:23 +00:00
|
|
|
@pytest.mark.nightly
|
2024-05-30 09:25:04 +00:00
|
|
|
class TestLogsMetrics(ClusterTestBase):
|
|
|
|
@pytest.fixture
|
2024-08-14 16:54:42 +00:00
|
|
|
def revert_all(self, cluster_state_controller: ClusterStateController):
|
|
|
|
yield
|
|
|
|
cluster_state_controller.manager(ConfigStateManager).revert_all()
|
|
|
|
|
2024-06-25 13:23:25 +00:00
|
|
|
def restart_storage_service(self, cluster_state_controller: ClusterStateController) -> datetime:
|
2024-05-30 09:25:04 +00:00
|
|
|
config_manager = cluster_state_controller.manager(ConfigStateManager)
|
|
|
|
config_manager.csc.stop_services_of_type(StorageNode)
|
2024-06-25 13:23:25 +00:00
|
|
|
restart_time = datetime.now(timezone.utc)
|
2024-05-30 09:25:04 +00:00
|
|
|
config_manager.csc.start_services_of_type(StorageNode)
|
2024-08-14 16:54:42 +00:00
|
|
|
return restart_time
|
2024-05-30 09:25:04 +00:00
|
|
|
|
|
|
|
@wait_for_success(interval=10)
|
2024-07-02 13:23:02 +00:00
|
|
|
def check_metrics_in_node(self, cluster_node: ClusterNode, restart_time: datetime, log_priority: str = None, **metrics_greps):
|
2024-08-14 16:54:42 +00:00
|
|
|
current_time = datetime.now(timezone.utc)
|
2024-07-02 13:23:02 +00:00
|
|
|
counter_metrics = get_metrics_value(cluster_node, **metrics_greps)
|
2024-08-14 16:54:42 +00:00
|
|
|
counter_logs = self.get_count_logs_by_level(cluster_node, metrics_greps.get("level"), restart_time, current_time, log_priority)
|
2024-07-02 13:23:02 +00:00
|
|
|
assert counter_logs == counter_metrics, f"counter_logs: {counter_logs}, counter_metrics: {counter_metrics} in node: {cluster_node}"
|
2024-05-30 09:25:04 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2024-08-14 16:54:42 +00:00
|
|
|
def get_count_logs_by_level(cluster_node: ClusterNode, log_level: str, after_time: datetime, until_time: datetime, log_priority: str):
|
2024-05-30 09:25:04 +00:00
|
|
|
count_logs = 0
|
|
|
|
try:
|
2024-08-14 16:54:42 +00:00
|
|
|
logs = cluster_node.host.get_filtered_logs(
|
|
|
|
log_level, unit="frostfs-storage", since=after_time, until=until_time, priority=log_priority
|
|
|
|
)
|
2024-10-08 05:56:15 +00:00
|
|
|
result = re.findall(rf":\s+{log_level}\s+", logs)
|
2024-05-30 09:25:04 +00:00
|
|
|
count_logs += len(result)
|
|
|
|
except RuntimeError as e:
|
|
|
|
...
|
|
|
|
return count_logs
|
|
|
|
|
|
|
|
@allure.title("Metrics for the log counter")
|
2024-08-14 16:54:42 +00:00
|
|
|
def test_log_counter_metrics(self, cluster_state_controller: ClusterStateController, revert_all):
|
|
|
|
restart_time = self.restart_storage_service(cluster_state_controller)
|
2024-05-30 09:25:04 +00:00
|
|
|
with reporter.step("Select random node"):
|
2024-08-14 16:54:42 +00:00
|
|
|
node = random.choice(self.cluster.cluster_nodes)
|
2024-05-30 09:25:04 +00:00
|
|
|
|
|
|
|
with reporter.step(f"Check metrics count logs with level 'info'"):
|
2024-07-02 13:23:02 +00:00
|
|
|
self.check_metrics_in_node(
|
|
|
|
node,
|
|
|
|
restart_time,
|
|
|
|
log_priority="6..6",
|
|
|
|
command="frostfs_node_logger_entry_count",
|
|
|
|
level="info",
|
|
|
|
dropped="false",
|
|
|
|
)
|
2024-05-30 09:25:04 +00:00
|
|
|
|
|
|
|
with reporter.step(f"Check metrics count logs with level 'error'"):
|
2024-07-02 13:23:02 +00:00
|
|
|
self.check_metrics_in_node(node, restart_time, command="frostfs_node_logger_entry_count", level="error", dropped="false")
|