Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log collector scenario should not pick up runs before service restart #3228

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions tests_e2e/tests/log_collector/log_collector.py
Original file line number Diff line number Diff line change
@@ -21,9 +21,9 @@

from assertpy import fail

import tests_e2e.tests.lib.logging
from azurelinuxagent.common.utils.shellutil import CommandError
from tests_e2e.tests.lib.agent_test import AgentVmTest
from tests_e2e.tests.lib.logging import log


class LogCollector(AgentVmTest):
@@ -32,15 +32,24 @@ class LogCollector(AgentVmTest):
"""
def run(self):
ssh_client = self._context.create_ssh_client()
ssh_client.run_command("update-waagent-conf Logs.Collect=y Debug.EnableCgroupV2ResourceLimiting=y Debug.LogCollectorInitialDelay=60", use_sudo=True)

# Rename the agent log file so that the test does not pick up any incomplete log collector runs that started
# before the config is updated
# Enable Cgroup v2 resource limiting and reduce log collector iniital delay via config
log.info("Renaming agent log file and modifying log collector conf flags")
setup_script = ("agent-service stop && mv /var/log/waagent.log /var/log/waagent.$(date --iso-8601=seconds).log && "
"update-waagent-conf Logs.Collect=y Debug.EnableCgroupV2ResourceLimiting=y Debug.LogCollectorInitialDelay=60")
self._run_remote_test(ssh_client, f"sh -c '{setup_script}'", use_sudo=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be run_command, rather than run_remote_test

log.info('Renamed log file and updated log collector config flags')

# Wait for log collector to finish uploading logs
for _ in range(3):
time.sleep(90)
try:
ssh_client.run_command("grep 'Successfully uploaded logs' /var/log/waagent.log")
break
except CommandError:
tests_e2e.tests.lib.logging.log.info("The Agent has not finished log collection, will check again after a short delay")
log.info("The Agent has not finished log collection, will check again after a short delay")
else:
raise Exception("Timeout while waiting for the Agent to finish log collection")

@@ -70,7 +79,7 @@ def run(self):
# Check that all expected logs exist and are in the correct order
indent = lambda lines: "\n".join([f" {ln}" for ln in lines])
if len(lc_logs) == len(expected) and all([re.match(expected[i], lc_logs[i]) is not None for i in range(len(expected))]):
tests_e2e.tests.lib.logging.log.info("The log collector run completed as expected.\nLog messages:\n%s", indent(lc_logs))
log.info("The log collector run completed as expected.\nLog messages:\n%s", indent(lc_logs))
else:
fail(f"The log collector run did not complete as expected.\nExpected:\n{indent(expected)}\nActual:\n{indent(lc_logs)}")

Loading
Oops, something went wrong.