Skip to content

Commit

Permalink
fix(wait_for_log_lines): fix saturating cpu when waiting for log lines
Browse files Browse the repository at this point in the history
We missed waiting time before recreating iterator. This causes
unnecessary high cpu utilization.

refs: #8720
(cherry picked from commit 092da01)
  • Loading branch information
soyacz authored and mergify[bot] committed Sep 23, 2024
1 parent af24244 commit 5e746db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions sdcm/wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ def wait_for_log_lines(node, start_line_patterns, end_line_patterns, start_timeo
started = any(start_follower)
while not started and (time.time() - start_time < start_timeout):
started = any(start_follower)
time.sleep(0.1)
if not started:
raise TimeoutError(start_ctx)
LOGGER.debug("Start line patterns %s were found.%s", start_line_patterns, error_msg_ctx)
ended = any(end_follower)
while not ended and (time.time() - start_time < end_timeout):
ended = any(end_follower)
time.sleep(0.1)
if not ended:
raise TimeoutError(end_ctx)
LOGGER.debug("End line patterns %s were found.%s", end_line_patterns, error_msg_ctx)
10 changes: 5 additions & 5 deletions unit_tests/test_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_wait_for_log_timeout_when_no_start_line(self, tmp_path):
t.daemon = True
file_path.touch()
with pytest.raises(TimeoutError, match="Timeout occurred while waiting for start log line"), \
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.3, end_timeout=1):
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.4, end_timeout=1.2):
t.start()

def test_wait_for_log_timeout_when_no_end_line(self, tmp_path):
Expand All @@ -234,7 +234,7 @@ def test_wait_for_log_timeout_when_no_end_line(self, tmp_path):
t.daemon = True
file_path.touch()
with pytest.raises(TimeoutError, match="Timeout occurred while waiting for end log line"), \
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.1, end_timeout=0.3):
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.5, end_timeout=0.7):
t.start()

def test_wait_for_log_reraises_exception(self, tmp_path):
Expand All @@ -245,7 +245,7 @@ def test_wait_for_log_reraises_exception(self, tmp_path):
t.daemon = True
file_path.touch()
with pytest.raises(ValueError, match="dummy error"), \
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.1, end_timeout=0.3):
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.5, end_timeout=0.7):
t.start()
raise ValueError('dummy error')

Expand All @@ -254,7 +254,7 @@ def test_wait_for_log_reraises_exception_and_timeout_error(self, tmp_path):
node = DummyNode(log_path=file_path)
file_path.touch()
with pytest.raises(TimeoutError, match="Timeout occurred while waiting for start log line") as exc_info, \
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.1, end_timeout=0.3):
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.4, end_timeout=0.7):
raise ValueError('dummy error')
assert "ValueError" in str(exc_info.getrepr())

Expand All @@ -267,5 +267,5 @@ def test_wait_for_log_reraises_timeout_error_with_error_context(self, tmp_path):
file_path.touch()
expected_match = "Timeout occurred while waiting for end log line \['end'\] on node: node_1. Context: Wait end line"
with pytest.raises(TimeoutError, match=expected_match), \
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.1, end_timeout=0.3, error_msg_ctx="Wait end line"):
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.4, end_timeout=0.7, error_msg_ctx="Wait end line"):
t.start()

0 comments on commit 5e746db

Please sign in to comment.