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

Add Cpu Arch in local logs and telemetry events #2938

Merged
merged 10 commits into from
Oct 8, 2023
7 changes: 5 additions & 2 deletions azurelinuxagent/common/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,14 @@ def __init__(self):

# Parameters from OS
osutil = get_osutil()
keyword_name = {
"CpuArchitecture": osutil.get_vm_arch()
}
self._common_parameters.append(TelemetryEventParam(CommonTelemetryEventSchema.OSVersion, EventLogger._get_os_version()))
self._common_parameters.append(TelemetryEventParam(CommonTelemetryEventSchema.ExecutionMode, AGENT_EXECUTION_MODE))
self._common_parameters.append(TelemetryEventParam(CommonTelemetryEventSchema.RAM, int(EventLogger._get_ram(osutil))))
self._common_parameters.append(TelemetryEventParam(CommonTelemetryEventSchema.Processors, int(EventLogger._get_processors(osutil))))
self._common_parameters.append(TelemetryEventParam(CommonTelemetryEventSchema.KeywordName, json.dumps(keyword_name)))

# Parameters from goal state
self._common_parameters.append(TelemetryEventParam(CommonTelemetryEventSchema.TenantName, "TenantName_UNINITIALIZED"))
Expand Down Expand Up @@ -597,8 +601,7 @@ def add_common_event_parameters(self, event, event_timestamp):
TelemetryEventParam(CommonTelemetryEventSchema.OpcodeName, event_timestamp.strftime(logger.Logger.LogTimeFormatInUTC)),
TelemetryEventParam(CommonTelemetryEventSchema.EventTid, threading.current_thread().ident),
TelemetryEventParam(CommonTelemetryEventSchema.EventPid, os.getpid()),
TelemetryEventParam(CommonTelemetryEventSchema.TaskName, threading.current_thread().getName()),
TelemetryEventParam(CommonTelemetryEventSchema.KeywordName, '')]
TelemetryEventParam(CommonTelemetryEventSchema.TaskName, threading.current_thread().getName())]

if event.eventId == TELEMETRY_EVENT_EVENT_ID and event.providerId == TELEMETRY_EVENT_PROVIDER_ID:
# Currently only the GuestAgentExtensionEvents has these columns, the other tables dont have them so skipping
Expand Down
8 changes: 8 additions & 0 deletions azurelinuxagent/common/osutil/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def get_systemd_unit_file_install_path():
def get_agent_bin_path():
return "/usr/sbin"

@staticmethod
def get_vm_arch():
try:
return platform.machine()
except Exception as e:
logger.warn("Unable to determine cpu architecture: {0}", ustr(e))
return "unknown"

def get_firewall_dropped_packets(self, dst_ip=None):
# If a previous attempt failed, do not retry
global _enable_firewall # pylint: disable=W0603
Expand Down
13 changes: 7 additions & 6 deletions azurelinuxagent/ga/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,18 +315,22 @@ def run(self, debug=False):
logger.info("OS: {0} {1}", DISTRO_NAME, DISTRO_VERSION)
logger.info("Python: {0}.{1}.{2}", PY_VERSION_MAJOR, PY_VERSION_MINOR, PY_VERSION_MICRO)

vm_arch = self.osutil.get_vm_arch()
logger.info("CPU Arch: {0}", vm_arch)
Copy link
Member

Choose a reason for hiding this comment

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

do we need to log here? we are already logging below

Copy link
Member

Choose a reason for hiding this comment

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

ah, i see, this was intentional, following the lead of OS & python. OK as is, I guess.


os_info_msg = u"Distro: {dist_name}-{dist_ver}; "\
u"OSUtil: {util_name}; "\
u"AgentService: {service_name}; "\
u"Python: {py_major}.{py_minor}.{py_micro}; "\
u"Arch: {vm_arch}; "\
u"systemd: {systemd}; "\
u"LISDrivers: {lis_ver}; "\
u"logrotate: {has_logrotate};".format(
dist_name=DISTRO_NAME, dist_ver=DISTRO_VERSION,
util_name=type(self.osutil).__name__,
service_name=self.osutil.service_name,
py_major=PY_VERSION_MAJOR, py_minor=PY_VERSION_MINOR,
py_micro=PY_VERSION_MICRO, systemd=systemd.is_systemd(),
py_micro=PY_VERSION_MICRO, vm_arch=vm_arch, systemd=systemd.is_systemd(),
lis_ver=get_lis_version(), has_logrotate=has_logrotate()
)
logger.info(os_info_msg)
Expand Down Expand Up @@ -1013,13 +1017,10 @@ def _send_heartbeat_telemetry(self, protocol):
if datetime.utcnow() >= (self._last_telemetry_heartbeat + UpdateHandler.TELEMETRY_HEARTBEAT_PERIOD):
dropped_packets = self.osutil.get_firewall_dropped_packets(protocol.get_endpoint())
auto_update_enabled = 1 if conf.get_autoupdate_enabled() else 0
# Include vm architecture in the heartbeat message because the kusto table does not have
# a separate column for it.
vmarch = self._get_vm_arch()
narrieta marked this conversation as resolved.
Show resolved Hide resolved

telemetry_msg = "{0};{1};{2};{3};{4};{5}".format(self._heartbeat_counter, self._heartbeat_id, dropped_packets,
telemetry_msg = "{0};{1};{2};{3};{4}".format(self._heartbeat_counter, self._heartbeat_id, dropped_packets,
self._heartbeat_update_goal_state_error_count,
auto_update_enabled, vmarch)
auto_update_enabled)
debug_log_msg = "[DEBUG HeartbeatCounter: {0};HeartbeatId: {1};DroppedPackets: {2};" \
"UpdateGSErrors: {3};AutoUpdate: {4}]".format(self._heartbeat_counter,
self._heartbeat_id, dropped_packets,
Expand Down
3 changes: 2 additions & 1 deletion tests/common/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import json
import os
import platform
import re
import shutil
import threading
Expand Down Expand Up @@ -70,7 +71,7 @@ def setUp(self):
CommonTelemetryEventSchema.EventTid: threading.current_thread().ident,
CommonTelemetryEventSchema.EventPid: os.getpid(),
CommonTelemetryEventSchema.TaskName: threading.current_thread().getName(),
CommonTelemetryEventSchema.KeywordName: '',
CommonTelemetryEventSchema.KeywordName: json.dumps({"CpuArchitecture": platform.machine()}),
# common parameters computed from the OS platform
CommonTelemetryEventSchema.OSVersion: EventLoggerTools.get_expected_os_version(),
CommonTelemetryEventSchema.ExecutionMode: AGENT_EXECUTION_MODE,
Expand Down
4 changes: 2 additions & 2 deletions tests/ga/test_send_telemetry_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,13 @@ def test_it_should_enqueue_and_send_events_properly(self, mock_lib_dir, *_):
'<Param Name="EventTid" Value="{4}" T="mt:uint64" />' \
'<Param Name="EventPid" Value="{5}" T="mt:uint64" />' \
'<Param Name="TaskName" Value="{6}" T="mt:wstr" />' \
'<Param Name="KeywordName" Value="" T="mt:wstr" />' \
'<Param Name="ExtensionType" Value="json" T="mt:wstr" />' \
'<Param Name="IsInternal" Value="False" T="mt:bool" />' \
'<Param Name="OSVersion" Value="{7}" T="mt:wstr" />' \
'<Param Name="ExecutionMode" Value="IAAS" T="mt:wstr" />' \
'<Param Name="RAM" Value="{8}" T="mt:uint64" />' \
'<Param Name="Processors" Value="{9}" T="mt:uint64" />' \
'<Param Name="KeywordName" Value=\'{10}\' T="mt:wstr" />' \
'<Param Name="TenantName" Value="db00a7755a5e4e8a8fe4b19bc3b330c3" T="mt:wstr" />' \
'<Param Name="RoleName" Value="MachineRole" T="mt:wstr" />' \
'<Param Name="RoleInstanceName" Value="b61f93d0-e1ed-40b2-b067-22c243233448.MachineRole_IN_0" T="mt:wstr" />' \
Expand All @@ -385,7 +385,7 @@ def test_it_should_enqueue_and_send_events_properly(self, mock_lib_dir, *_):
'<Param Name="ImageOrigin" Value="2468" T="mt:uint64" />' \
']]></Event>'.format(AGENT_VERSION, TestSendTelemetryEventsHandler._TEST_EVENT_OPERATION, CURRENT_AGENT, test_opcodename, test_eventtid,
test_eventpid, test_taskname, osversion, int(osutil.get_total_mem()),
osutil.get_processor_cores()).encode('utf-8')
osutil.get_processor_cores(), json.dumps({"CpuArchitecture": platform.machine()})).encode('utf-8')

self.assertIn(sample_message, collected_event)

Expand Down
Loading