Skip to content

Commit

Permalink
#414: Ignore rsyslogd related errors in db
Browse files Browse the repository at this point in the history
  • Loading branch information
tomuben committed Sep 18, 2024
1 parent 92cc67b commit 1b38c48
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def __init__(self, container: Container, logger, log_file: Path, description: st
self.previous_timestamp = None
self.current_timestamp = None
self.error_message = None
self.ignore_error_return_codes = (
"(membership) returned with state 1", # exclude webui not found in 7.0.0
"rsyslogd) returned with state 1" # exclude rsyslogd which might crash when running itde under lima
)

def stop(self):
self.logger.info("Stop ContainerLogThread")
Expand All @@ -41,7 +45,8 @@ def run(self):
if ("error" in log_line and not "sshd was not started" in log_line) \
or "exception" in log_line \
or ("returned with state 1" in log_line
and not "(membership) returned with state 1" in log_line): # exclude webui not found in 7.0.0
and not any((ignore_error_return_code in log_line for ignore_error_return_code in
self.ignore_error_return_codes))):
self.logger.info("ContainerLogHandler error message, %s", log_line)
self.error_message = log_line
self.finish = True
Expand All @@ -50,4 +55,4 @@ def run(self):
time.sleep(1)
except Exception as e:
self.finish = True
self.logger.exception("Caught exception in DBContainerLogThread.run.")
self.logger.exception("Caught exception in DBContainerLogThread.run.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import logging
import tempfile
import time
import unittest
from pathlib import Path
from typing import List

from exasol_integration_test_docker_environment.lib.docker import ContextDockerClient
from exasol_integration_test_docker_environment.lib.test_environment.database_waiters.db_container_log_thread import \
DBContainerLogThread


class ReturnValueRunTaskTest(unittest.TestCase):

def setUp(self):
self.logger = logging.getLogger(self.__class__.__name__)

def _build_docker_command(self, logs: List[str]):
"""
Builds a bash while loop command which can be used to print logs.
Args:
logs: List of logs to print, each in one line.
Returns:
Something like ["bash", "-c", "while true; do echo 'Test'; done"]
"""
echo_commands = [f"echo '{log}'" for log in logs]
echo_commdands_str = ";".join(echo_commands)
bash_command = f"while true; do {echo_commdands_str}; sleep 0.1; done"
return ["bash", "-c", bash_command]

def _run_container_log_thread(self, logs: List[str]) -> str:
with tempfile.TemporaryDirectory() as tmpDir:
with ContextDockerClient(timeout=3600) as client:
try:
container = client.containers.run("ubuntu", self._build_docker_command(logs), detach=True)
thread = DBContainerLogThread(container, self.logger, Path(tmpDir) / "log.txt", "test")
thread.start()
time.sleep(2)
thread.stop()
finally:
container.stop()
container.remove()
return thread.error_message

def test_container_log_thread_no_error(self) -> None:
"""
Integration test which verifies that the DBContainerLogThread returns no error message if no error is logged.
"""
error_message = self._run_container_log_thread(["test", "something", "db started"])
self.assertEqual(None, error_message)

def test_container_log_thread_error(self) -> None:
"""
Integration test which verifies that the DBContainerLogThread returns error message if error is logged.
"""
error_message = self._run_container_log_thread(["confd returned with state 1"])
self.assertIn("confd returned with state 1\n", error_message)

def test_container_ignore_rsyslogd(self) -> None:
"""
Integration test which verifies that the DBContainerLogThread returns no error message if rsyslogd crashes.
"""
rsys_logd_logs = [
"[2024-09-17 14:12:20.335085 +00:00] child 58687 (Part:9 Node:0 rsyslogd) returned with state 1.",
"[2024-09-17 14:12:20.336886 +00:00] Started /sbin/rsyslogd with PID:58688 UID:0 GID:0 Part:9 Node:0",
"[2024-09-17 14:12:20.336967 +00:00] 30 auto-restarted processes exited in the last 0 seconds. Starting to delay process death handling."
]
error_message = self._run_container_log_thread(rsys_logd_logs)
self.assertEqual(None, error_message)

if __name__ == '__main__':
unittest.main()

0 comments on commit 1b38c48

Please sign in to comment.