Skip to content

Commit

Permalink
Move AutoUpdate reporting to HeartBeat event (Azure#1919)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgombar committed Jun 26, 2020
1 parent 71654c4 commit 924c989
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
2 changes: 0 additions & 2 deletions azurelinuxagent/common/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class WALAEventOperation:
AgentBlacklisted = "AgentBlacklisted"
AgentEnabled = "AgentEnabled"
ArtifactsProfileBlob = "ArtifactsProfileBlob"
AutoUpdate = "AutoUpdate"
CGroupsCleanUp = "CGroupsCleanUp"
CGroupsDebug = "CGroupsDebug"
CGroupsInfo = "CGroupsInfo"
Expand Down Expand Up @@ -181,7 +180,6 @@ def _save(self):

__event_status__ = EventStatus()
__event_status_operations__ = [
WALAEventOperation.AutoUpdate,
WALAEventOperation.ReportStatus
]

Expand Down
23 changes: 12 additions & 11 deletions azurelinuxagent/ga/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def run(self, debug=False):
PY_VERSION_MINOR, PY_VERSION_MICRO)
logger.info(os_info_msg)
add_event(AGENT_NAME, op=WALAEventOperation.OSInfo, message=os_info_msg)

# Launch monitoring threads
from azurelinuxagent.ga.monitor import get_monitor_handler
monitor_thread = get_monitor_handler()
Expand Down Expand Up @@ -350,7 +350,6 @@ def run(self, debug=False):
message="Incarnation {0}".format(exthandlers_handler.last_etag))

self._send_heartbeat_telemetry(protocol)

time.sleep(goal_state_interval)

except Exception as e:
Expand Down Expand Up @@ -446,11 +445,6 @@ def log_if_int_changed_from_default(name, current):
logger.info(message)
add_event(AGENT_NAME, op=WALAEventOperation.ConfigurationChange, message=message)

# Always report the value of AutoUpdate
auto_update_enabled = conf.get_autoupdate_enabled()
logger.info("AutoUpdate.Enabled: {0}}", auto_update_enabled)
add_event(op=WALAEventOperation.AutoUpdate, is_success=auto_update_enabled, log_event=False)

except Exception as e:
logger.warn("Failed to log changes in configuration: {0}", ustr(e))

Expand Down Expand Up @@ -672,7 +666,6 @@ def _shutdown(self):
def _upgrade_available(self, protocol, base_version=CURRENT_VERSION):
# Ignore new agents if updating is disabled
if not conf.get_autoupdate_enabled():
logger.warn(u"Agent auto-update is disabled.")
return False

now = time.time()
Expand Down Expand Up @@ -756,13 +749,21 @@ 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())
msg = "{0};{1};{2};{3}".format(self._heartbeat_counter, self._heartbeat_id, dropped_packets, self._heartbeat_update_goal_state_error_count)
auto_update_enabled = 1 if conf.get_autoupdate_enabled() else 0
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)

add_event(name=AGENT_NAME, version=CURRENT_VERSION, op=WALAEventOperation.HeartBeat, is_success=True, message=msg, log_event=False)
add_event(name=AGENT_NAME, version=CURRENT_VERSION, op=WALAEventOperation.HeartBeat, is_success=True,
message=telemetry_msg, log_event=False)
self._heartbeat_counter += 1
self._heartbeat_update_goal_state_error_count = 0

logger.info(u"[HEARTBEAT] Agent {0} is running as the goal state agent", CURRENT_AGENT)
debug_log_msg = "[DEBUG HeartbeatCounter: {0};HeartbeatId: {1};DroppedPackets: {2};" \
"UpdateGSErrors: {3};AutoUpdate: {4}]".format(self._heartbeat_counter,
self._heartbeat_id, dropped_packets,
self._heartbeat_update_goal_state_error_count,
auto_update_enabled)
logger.info(u"[HEARTBEAT] Agent {0} is running as the goal state agent {1}", CURRENT_AGENT, debug_log_msg)
self._last_telemetry_heartbeat = datetime.utcnow()


Expand Down
6 changes: 2 additions & 4 deletions tests/ga/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,10 +1476,8 @@ def test_telemetry_heartbeat_creates_event(self, patch_add_event, patch_info, *_
update_handler.last_telemetry_heartbeat = datetime.utcnow() - timedelta(hours=1)
update_handler._send_heartbeat_telemetry(mock_protocol)
self.assertEqual(1, patch_add_event.call_count)
self.assertTrue(
any(call_args[0] == "[HEARTBEAT] Agent {0} is running as the goal state agent" for call_args in patch_info.call_args),
"The heartbeat was not written to the agent's log"
)
self.assertTrue(any(call_args[0] == "[HEARTBEAT] Agent {0} is running as the goal state agent {1}"
for call_args in patch_info.call_args), "The heartbeat was not written to the agent's log")


class MonitorThreadTest(AgentTestCase):
Expand Down

0 comments on commit 924c989

Please sign in to comment.