Repository: Azure/WALinuxAgent
Pull request #1236 (2018-06-28 19:51:43)

Clean up fallback logging and telemetry
```
2018/06/28 14:25:45.446696 WARNING ExtHandler direct
2018/06/28 14:25:45.457874 ERROR ExtHandler Event: name=WALinuxAgent, op=ReportStatus, message=direct, duration=0
```
Will now be a telemetry event with the message `Falling back to direct upload: {error}` which is not logged.


Patch:
diff --git a/azurelinuxagent/common/protocol/wire.py b/azurelinuxagent/common/protocol/wire.py
index 22874230..60e0ba2b 100644
--- a/azurelinuxagent/common/protocol/wire.py
+++ b/azurelinuxagent/common/protocol/wire.py
@@ -1021,14 +1021,15 @@ class WireClient(object):
                 return
             except Exception as e:
                 # for all other errors, fall back to direct
-                pass
+                msg = "Falling back to direct upload: {0}".format(ustr(e))
+                self.report_status_event(msg, is_success=True)
 
-            self.report_status_event("direct")
             if self.status_blob.upload(blob_uri):
                 return
 
         except Exception as e:
-            self.report_status_event("Exception uploading status blob: {0}", ustr(e))
+            msg = "Exception uploading status blob: {0}".format(ustr(e))
+            self.report_status_event(msg, is_success=False)
 
         raise ProtocolError("Failed to upload status blob via either channel")
 
@@ -1121,15 +1122,14 @@ class WireClient(object):
             if len(buf[provider_id]) > 0:
                 self.send_event(provider_id, buf[provider_id])
 
-    def report_status_event(self, message, *args):
+    def report_status_event(self, message, is_success):
         from azurelinuxagent.common.event import report_event, \
                 WALAEventOperation
 
-        message = message.format(*args)
-        logger.warn(message)
         report_event(op=WALAEventOperation.ReportStatus,
-                     is_success=False,
-                     message=message)
+                     is_success=is_success,
+                     message=message,
+                     log_event=not is_success)
 
     def get_header(self):
         return {


Test patch:
diff --git a/tests/protocol/test_hostplugin.py b/tests/protocol/test_hostplugin.py
index dae2523c..a1b91acd 100644
--- a/tests/protocol/test_hostplugin.py
+++ b/tests/protocol/test_hostplugin.py
@@ -325,8 +325,8 @@ class TestHostPlugin(AgentTestCase):
                     # The agent never logs telemetry event for direct fallback
                     self.assertEqual(1, patch_add_event.call_count)
                     self.assertEqual('ReportStatus', patch_add_event.call_args[1]['op'])
-                    self.assertEqual('direct', patch_add_event.call_args[1]['message'])
-                    self.assertEqual(False, patch_add_event.call_args[1]['is_success'])
+                    self.assertTrue('Falling back to direct' in patch_add_event.call_args[1]['message'])
+                    self.assertEqual(True, patch_add_event.call_args[1]['is_success'])
 
     def test_validate_http_request(self):
         """Validate correct set of data is sent to HostGAPlugin when reporting VM status"""