Skip to content

Commit d79966d

Browse files
authored
Update logcollector telemetry with common properties (#3242)
* Update logcollector telemetry * LogCollector telemetry should have LogCollector operation * Use event.warn instead of log_cgroup_warning
1 parent e85ea1d commit d79966d

File tree

3 files changed

+31
-34
lines changed

3 files changed

+31
-34
lines changed

azurelinuxagent/agent.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
from azurelinuxagent.ga import logcollector, cgroupconfigurator
3535
from azurelinuxagent.ga.cgroupcontroller import AGENT_LOG_COLLECTOR
3636
from azurelinuxagent.ga.cpucontroller import _CpuController
37-
from azurelinuxagent.ga.cgroupapi import get_cgroup_api, log_cgroup_warning, InvalidCgroupMountpointException
37+
from azurelinuxagent.ga.cgroupapi import get_cgroup_api, InvalidCgroupMountpointException
3838
from azurelinuxagent.ga.firewall_manager import FirewallManager
3939

4040
import azurelinuxagent.common.conf as conf
4141
import azurelinuxagent.common.event as event
4242
import azurelinuxagent.common.logger as logger
43+
from azurelinuxagent.common.event import WALAEventOperation
4344
from azurelinuxagent.common.future import ustr
4445
from azurelinuxagent.ga.logcollector import LogCollector, OUTPUT_RESULTS_FILE_PATH
4546
from azurelinuxagent.common.osutil import get_osutil
@@ -208,28 +209,31 @@ def collect_logs(self, is_full_mode):
208209
else:
209210
logger.info("Running log collector mode normal")
210211

212+
LogCollector.initialize_telemetry()
213+
211214
# Check the cgroups unit
212215
log_collector_monitor = None
213216
tracked_controllers = []
214217
if CollectLogsHandler.is_enabled_monitor_cgroups_check():
215218
try:
216219
cgroup_api = get_cgroup_api()
217220
except InvalidCgroupMountpointException as e:
218-
log_cgroup_warning("The agent does not support cgroups if the default systemd mountpoint is not being used: {0}".format(ustr(e)), send_event=True)
221+
event.warn(WALAEventOperation.LogCollection, "The agent does not support cgroups if the default systemd mountpoint is not being used: {0}", ustr(e))
219222
sys.exit(logcollector.INVALID_CGROUPS_ERRCODE)
220223
except CGroupsException as e:
221-
log_cgroup_warning("Unable to determine which cgroup version to use: {0}".format(ustr(e)), send_event=True)
224+
event.warn(WALAEventOperation.LogCollection, "Unable to determine which cgroup version to use: {0}", ustr(e))
222225
sys.exit(logcollector.INVALID_CGROUPS_ERRCODE)
223226

224227
log_collector_cgroup = cgroup_api.get_process_cgroup(process_id="self", cgroup_name=AGENT_LOG_COLLECTOR)
225228
tracked_controllers = log_collector_cgroup.get_controllers()
226229

227230
if len(tracked_controllers) != len(log_collector_cgroup.get_supported_controller_names()):
228-
log_cgroup_warning("At least one required controller is missing. The following controllers are required for the log collector to run: {0}".format(log_collector_cgroup.get_supported_controller_names()))
231+
event.warn(WALAEventOperation.LogCollection, "At least one required controller is missing. The following controllers are required for the log collector to run: {0}", log_collector_cgroup.get_supported_controller_names())
229232
sys.exit(logcollector.INVALID_CGROUPS_ERRCODE)
230233

231-
if not log_collector_cgroup.check_in_expected_slice(cgroupconfigurator.LOGCOLLECTOR_SLICE):
232-
log_cgroup_warning("The Log Collector process is not in the proper cgroups", send_event=False)
234+
expected_slice = cgroupconfigurator.LOGCOLLECTOR_SLICE
235+
if not log_collector_cgroup.check_in_expected_slice(expected_slice):
236+
event.warn(WALAEventOperation.LogCollection, "The Log Collector process is not in the proper cgroups. Expected slice: {0}", expected_slice)
233237
sys.exit(logcollector.INVALID_CGROUPS_ERRCODE)
234238

235239
try:

azurelinuxagent/ga/logcollector.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from heapq import heappush, heappop
2828

2929
from azurelinuxagent.common.conf import get_lib_dir, get_ext_log_dir, get_agent_log_file
30-
from azurelinuxagent.common.event import initialize_event_logger_vminfo_common_parameters
30+
from azurelinuxagent.common.event import initialize_event_logger_vminfo_common_parameters, add_event, WALAEventOperation
3131
from azurelinuxagent.common.future import ustr
3232
from azurelinuxagent.ga.logcollector_manifests import MANIFEST_NORMAL, MANIFEST_FULL
3333

@@ -76,7 +76,6 @@ def __init__(self, is_full_mode=False):
7676
self._must_collect_files = self._expand_must_collect_files()
7777
self._create_base_dirs()
7878
self._set_logger()
79-
self._initialize_telemetry()
8079

8180
@staticmethod
8281
def _mkdir(dirname):
@@ -104,7 +103,7 @@ def _set_logger():
104103
_LOGGER.setLevel(logging.INFO)
105104

106105
@staticmethod
107-
def _initialize_telemetry():
106+
def initialize_telemetry():
108107
protocol = get_protocol_util().get_protocol(init_goal_state=False)
109108
protocol.client.reset_goal_state(goal_state_properties=GoalStateProperties.RoleConfig | GoalStateProperties.HostingEnv)
110109
# Initialize the common parameters for telemetry events
@@ -326,7 +325,9 @@ def _get_final_list_for_archive(self, priority_file_queue):
326325
if e.errno == 2: # [Errno 2] No such file or directory
327326
_LOGGER.warning("File %s does not exist, skipping collection for this file", file_path)
328327

329-
_LOGGER.info("Uncompressed archive size is %s b", total_uncompressed_size)
328+
msg = "Uncompressed archive size is {0} b".format(total_uncompressed_size)
329+
_LOGGER.info(msg)
330+
add_event(op=WALAEventOperation.LogCollection, message=msg)
330331

331332
return final_files_to_collect, total_uncompressed_size
332333

tests/ga/test_logcollector.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,8 @@ def test_log_collector_parses_commands_in_manifest(self):
211211
diskinfo,""".format(folder_to_list, file_to_collect)
212212

213213
with patch("azurelinuxagent.ga.logcollector.MANIFEST_NORMAL", manifest):
214-
with patch('azurelinuxagent.ga.logcollector.LogCollector._initialize_telemetry'):
215-
log_collector = LogCollector()
216-
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
214+
log_collector = LogCollector()
215+
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
217216

218217
with open(self.output_results_file_path, "r") as fh:
219218
results = fh.readlines()
@@ -241,9 +240,8 @@ def test_log_collector_uses_full_manifest_when_full_mode_enabled(self):
241240
""".format(file_to_collect)
242241

243242
with patch("azurelinuxagent.ga.logcollector.MANIFEST_FULL", manifest):
244-
with patch('azurelinuxagent.ga.logcollector.LogCollector._initialize_telemetry'):
245-
log_collector = LogCollector(is_full_mode=True)
246-
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
243+
log_collector = LogCollector(is_full_mode=True)
244+
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
247245

248246
self._assert_archive_created(archive)
249247
self._assert_files_are_in_archive(expected_files=[file_to_collect])
@@ -256,9 +254,8 @@ def test_log_collector_should_collect_all_files(self):
256254
# All files in the manifest should be collected, since none of them are over the individual file size limit,
257255
# and combined they do not cross the archive size threshold.
258256

259-
with patch('azurelinuxagent.ga.logcollector.LogCollector._initialize_telemetry'):
260-
log_collector = LogCollector()
261-
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
257+
log_collector = LogCollector()
258+
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
262259

263260
self._assert_archive_created(archive)
264261

@@ -282,9 +279,8 @@ def test_log_collector_should_collect_all_files(self):
282279
def test_log_collector_should_truncate_large_text_files_and_ignore_large_binary_files(self):
283280
# Set the size limit so that some files are too large to collect in full.
284281
with patch("azurelinuxagent.ga.logcollector._FILE_SIZE_LIMIT", SMALL_FILE_SIZE):
285-
with patch('azurelinuxagent.ga.logcollector.LogCollector._initialize_telemetry'):
286-
log_collector = LogCollector()
287-
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
282+
log_collector = LogCollector()
283+
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
288284

289285
self._assert_archive_created(archive)
290286

@@ -323,9 +319,8 @@ def test_log_collector_should_prioritize_important_files_if_archive_too_big(self
323319

324320
with patch("azurelinuxagent.ga.logcollector._UNCOMPRESSED_ARCHIVE_SIZE_LIMIT", 10 * 1024 * 1024):
325321
with patch("azurelinuxagent.ga.logcollector._MUST_COLLECT_FILES", must_collect_files):
326-
with patch('azurelinuxagent.ga.logcollector.LogCollector._initialize_telemetry'):
327-
log_collector = LogCollector()
328-
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
322+
log_collector = LogCollector()
323+
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
329324

330325
self._assert_archive_created(archive)
331326

@@ -382,9 +377,8 @@ def test_log_collector_should_prioritize_important_files_if_archive_too_big(self
382377
def test_log_collector_should_update_archive_when_files_are_new_or_modified_or_deleted(self):
383378
# Ensure the archive reflects the state of files on the disk at collection time. If a file was updated, it
384379
# needs to be updated in the archive, deleted if removed from disk, and added if not previously seen.
385-
with patch('azurelinuxagent.ga.logcollector.LogCollector._initialize_telemetry'):
386-
log_collector = LogCollector()
387-
first_archive, first_uncompressed_file_size = log_collector.collect_logs_and_get_archive()
380+
log_collector = LogCollector()
381+
first_archive, first_uncompressed_file_size = log_collector.collect_logs_and_get_archive()
388382
self._assert_archive_created(first_archive)
389383

390384
# Everything should be in the archive
@@ -461,9 +455,8 @@ def test_log_collector_should_clean_up_uncollected_truncated_files(self):
461455
with patch("azurelinuxagent.ga.logcollector._UNCOMPRESSED_ARCHIVE_SIZE_LIMIT", 2 * SMALL_FILE_SIZE):
462456
with patch("azurelinuxagent.ga.logcollector._MUST_COLLECT_FILES", must_collect_files):
463457
with patch("azurelinuxagent.ga.logcollector._FILE_SIZE_LIMIT", SMALL_FILE_SIZE):
464-
with patch('azurelinuxagent.ga.logcollector.LogCollector._initialize_telemetry'):
465-
log_collector = LogCollector()
466-
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
458+
log_collector = LogCollector()
459+
archive, uncompressed_file_size = log_collector.collect_logs_and_get_archive()
467460

468461
self._assert_archive_created(archive)
469462

@@ -490,9 +483,8 @@ def test_log_collector_should_clean_up_uncollected_truncated_files(self):
490483
with patch("azurelinuxagent.ga.logcollector._UNCOMPRESSED_ARCHIVE_SIZE_LIMIT", 2 * SMALL_FILE_SIZE):
491484
with patch("azurelinuxagent.ga.logcollector._MUST_COLLECT_FILES", must_collect_files):
492485
with patch("azurelinuxagent.ga.logcollector._FILE_SIZE_LIMIT", SMALL_FILE_SIZE):
493-
with patch('azurelinuxagent.ga.logcollector.LogCollector._initialize_telemetry'):
494-
log_collector = LogCollector()
495-
second_archive, second_uncompressed_file_size = log_collector.collect_logs_and_get_archive()
486+
log_collector = LogCollector()
487+
second_archive, second_uncompressed_file_size = log_collector.collect_logs_and_get_archive()
496488

497489
expected_files = [
498490
os.path.join(self.root_collect_dir, "waagent.log"),

0 commit comments

Comments
 (0)