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
9 changes: 8 additions & 1 deletion azurelinuxagent/common/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ def __init__(self):
self._common_parameters.append(TelemetryEventParam(CommonTelemetryEventSchema.VMId, "VMId_UNINITIALIZED"))
self._common_parameters.append(TelemetryEventParam(CommonTelemetryEventSchema.ImageOrigin, 0))

@staticmethod
def _get_vm_arch():
return platform.machine()
Copy link
Member

Choose a reason for hiding this comment

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

can this ever raise an exception? should we catch and return 'unknown' on failure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to catch and return 'unknown' on failure


@staticmethod
def _get_os_version():
return "{0}:{1}-{2}-{3}:{4}".format(platform.system(), DISTRO_NAME, DISTRO_VERSION, DISTRO_CODE_NAME, platform.release())
Expand Down Expand Up @@ -592,13 +596,16 @@ def add_common_event_parameters(self, event, event_timestamp):
This method is called for all events and ensures all telemetry fields are added before the event is sent out.
Note that the event timestamp is saved in the OpcodeName field.
"""
keyword_name = {
"CpuArchitecture": self._get_vm_arch()
}
common_params = [TelemetryEventParam(CommonTelemetryEventSchema.GAVersion, CURRENT_AGENT),
TelemetryEventParam(CommonTelemetryEventSchema.ContainerId, AgentGlobals.get_container_id()),
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.KeywordName, json.dumps(keyword_name))]

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
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._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
10 changes: 5 additions & 5 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="KeywordName" Value=\'{7}\' 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="OSVersion" Value="{8}" 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="RAM" Value="{9}" T="mt:uint64" />' \
'<Param Name="Processors" Value="{10}" T="mt:uint64" />' \
'<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 @@ -384,7 +384,7 @@ def test_it_should_enqueue_and_send_events_properly(self, mock_lib_dir, *_):
'<Param Name="VMId" Value="99999999-8888-7777-6666-555555555555" T="mt:wstr" />' \
'<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()),
test_eventpid, test_taskname, json.dumps({"CpuArchitecture": platform.machine()}), osversion, int(osutil.get_total_mem()),
osutil.get_processor_cores()).encode('utf-8')

self.assertIn(sample_message, collected_event)
Expand Down