Repository: Azure/WALinuxAgent
Pull request #1548 (2019-06-09 17:25:27)

Bug fixes for duplicate copies and scope name
<!-- DO NOT DELETE THIS TEMPLATE -->

## Description
- Prevent adding duplicates in `_tracked` data structure.
- Change the scope name to have the .scope suffix  …
- nit fixes; correcting the systemd filename and other unit test fixes.

---

### PR information
- [x] The title of the PR is clear and informative.
- [x] There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).
- [x] Except for special cases involving multiple contributors, the PR is started from a fork of the main repository, not a branch.
- [x] If applicable, the PR references the bug/issue that it fixes in the description.
- [x] New Unit tests were added for the changes made and Travis.CI is passing.

### Quality of Code and Contribution Guidelines
- [x] I have read the [contribution guidelines](https://github.com/Azure/WALinuxAgent/blob/master/.github/CONTRIBUTING.md).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/azure/walinuxagent/1548)
<!-- Reviewable:end -->


codecov[bot]: # [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=h1) Report
> Merging [#1548](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=desc) into [cgroups](https://codecov.io/gh/Azure/WALinuxAgent/commit/468714c44e2408a293b6fab800acf3a647c77b80?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `70%`.

[![Impacted file tree graph](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548/graphs/tree.svg?width=650&token=ae90E2KYCw&height=150&src=pr)](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           cgroups    #1548      +/-   ##
===========================================
+ Coverage    63.17%   63.18%   +<.01%     
===========================================
  Files           78       78              
  Lines        10980    10978       -2     
  Branches      1541     1542       +1     
===========================================
- Hits          6937     6936       -1     
  Misses        3707     3707              
+ Partials       336      335       -1
```


| [Impacted Files](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [azurelinuxagent/common/cgroupapi.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9jZ3JvdXBhcGkucHk=) | `62.56% <0%> (ø)` | :arrow_up: |
| [azurelinuxagent/common/cgroupstelemetry.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9jZ3JvdXBzdGVsZW1ldHJ5LnB5) | `98.13% <100%> (+0.01%)` | :arrow_up: |
| [azurelinuxagent/ga/monitor.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2dhL21vbml0b3IucHk=) | `66.78% <75%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=footer). Last update [468714c...7385ccb](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

codecov[bot]: # [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=h1) Report
> Merging [#1548](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=desc) into [cgroups](https://codecov.io/gh/Azure/WALinuxAgent/commit/468714c44e2408a293b6fab800acf3a647c77b80?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `70%`.

[![Impacted file tree graph](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548/graphs/tree.svg?width=650&token=ae90E2KYCw&height=150&src=pr)](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           cgroups    #1548      +/-   ##
===========================================
+ Coverage    63.17%   63.18%   +<.01%     
===========================================
  Files           78       78              
  Lines        10980    10978       -2     
  Branches      1541     1542       +1     
===========================================
- Hits          6937     6936       -1     
  Misses        3707     3707              
+ Partials       336      335       -1
```


| [Impacted Files](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [azurelinuxagent/common/cgroupapi.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9jZ3JvdXBhcGkucHk=) | `62.56% <0%> (ø)` | :arrow_up: |
| [azurelinuxagent/common/cgroupstelemetry.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9jZ3JvdXBzdGVsZW1ldHJ5LnB5) | `98.13% <100%> (+0.01%)` | :arrow_up: |
| [azurelinuxagent/ga/monitor.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2dhL21vbml0b3IucHk=) | `66.78% <75%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=footer). Last update [468714c...7385ccb](https://codecov.io/gh/Azure/WALinuxAgent/pull/1548?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/azurelinuxagent/common/cgroupstelemetry.py b/azurelinuxagent/common/cgroupstelemetry.py
index a00ad0fc..b5e915d0 100644
--- a/azurelinuxagent/common/cgroupstelemetry.py
+++ b/azurelinuxagent/common/cgroupstelemetry.py
@@ -51,18 +51,19 @@ class CGroupsTelemetry(object):
         Adds the given item to the dictionary of tracked cgroups
         """
         with CGroupsTelemetry._rlock:
-            CGroupsTelemetry._tracked.append(cgroup)
-            logger.info("Started tracking new cgroup: {0}, path: {1}".format(cgroup.name, cgroup.path))
+            if not CGroupsTelemetry.is_tracked(cgroup.path):
+                CGroupsTelemetry._tracked.append(cgroup)
+                logger.info("Started tracking new cgroup: {0}, path: {1}".format(cgroup.name, cgroup.path))
 
     @staticmethod
-    def is_tracked(name, controller):
+    def is_tracked(path):
         """
         Returns true if the given item is in the list of tracked items
         O(n) operation. But limited to few cgroup objects we have.
         """
         with CGroupsTelemetry._rlock:
             for cgroup in CGroupsTelemetry._tracked:
-                if name == cgroup.name and controller == cgroup.controller:
+                if path == cgroup.path:
                     return True
 
         return False
diff --git a/azurelinuxagent/ga/monitor.py b/azurelinuxagent/ga/monitor.py
index 135cd5e9..99ff3ae9 100644
--- a/azurelinuxagent/ga/monitor.py
+++ b/azurelinuxagent/ga/monitor.py
@@ -419,29 +419,24 @@ class MonitorHandler(object):
             self.last_cgroup_polling_telemetry = time_now
 
     def send_telemetry_metrics(self):
-        to_send = False
         time_now = datetime.datetime.utcnow()
-        performance_metrics = {}
 
         if not self.last_cgroup_report_telemetry:
             self.last_cgroup_report_telemetry = time_now
 
-        if time_now >= (self.last_cgroup_report_telemetry +
-                        MonitorHandler.CGROUP_TELEMETRY_REPORTING_PERIOD):
+        if time_now >= (self.last_cgroup_report_telemetry + MonitorHandler.CGROUP_TELEMETRY_REPORTING_PERIOD):
             performance_metrics = CGroupsTelemetry.report_all_tracked()
             self.last_cgroup_report_telemetry = time_now
-            to_send = True
-
-        if to_send:
-            message = generate_extension_metrics_telemetry_dictionary(schema_version=1.0,
-                                                                      performance_metrics=performance_metrics)
-
-            add_event(name=AGENT_NAME,
-                      version=CURRENT_VERSION,
-                      op=WALAEventOperation.ExtensionMetricsData,
-                      is_success=True,
-                      message=ustr(message),
-                      log_event=False)
+
+            if performance_metrics:
+                message = generate_extension_metrics_telemetry_dictionary(schema_version=1.0,
+                                                                          performance_metrics=performance_metrics)
+                add_event(name=AGENT_NAME,
+                          version=CURRENT_VERSION,
+                          op=WALAEventOperation.ExtensionMetricsData,
+                          is_success=True,
+                          message=ustr(message),
+                          log_event=False)
 
     def log_altered_network_configuration(self):
         """


Test patch:
diff --git a/tests/common/test_cgroupconfigurator.py b/tests/common/test_cgroupconfigurator.py
index d506395d..f4b55c67 100644
--- a/tests/common/test_cgroupconfigurator.py
+++ b/tests/common/test_cgroupconfigurator.py
@@ -183,8 +183,10 @@ class CGroupConfiguratorTestCase(AgentTestCase):
             stdout=subprocess.PIPE,
             stderr=subprocess.PIPE)
 
-        self.assertTrue(CGroupsTelemetry.is_tracked("Microsoft.Compute.TestExtension-1.2.3", "cpu"))
-        self.assertTrue(CGroupsTelemetry.is_tracked("Microsoft.Compute.TestExtension-1.2.3", "memory"))
+        self.assertTrue(CGroupsTelemetry.is_tracked(os.path.join(
+            self.cgroups_file_system_root, "cpu", "walinuxagent.extensions/Microsoft.Compute.TestExtension_1.2.3")))
+        self.assertTrue(CGroupsTelemetry.is_tracked(os.path.join(
+            self.cgroups_file_system_root, "memory", "walinuxagent.extensions/Microsoft.Compute.TestExtension_1.2.3")))
 
     def test_start_extension_command_should_raise_an_exception_when_the_command_cannot_be_started(self):
         configurator = CGroupConfigurator.get_instance()
diff --git a/tests/common/test_cgroupstelemetry.py b/tests/common/test_cgroupstelemetry.py
index f3e8a0c8..02c1d281 100644
--- a/tests/common/test_cgroupstelemetry.py
+++ b/tests/common/test_cgroupstelemetry.py
@@ -25,6 +25,7 @@ from mock import patch
 from azurelinuxagent.common.cgroup import CGroup
 from azurelinuxagent.common.cgroupconfigurator import CGroupConfigurator
 from azurelinuxagent.common.cgroupstelemetry import CGroupsTelemetry, Metric
+from azurelinuxagent.common.osutil.default import BASE_CGROUPS
 from azurelinuxagent.common.protocol.restapi import ExtHandlerProperties, ExtHandler
 from azurelinuxagent.ga.exthandlers import ExtHandlerInstance
 from tests.common.test_cgroupapi import i_am_root
@@ -80,10 +81,11 @@ class TestCGroupsTelemetry(AgentTestCase):
     def test_telemetry_polling_with_active_cgroups(self, *args):
         num_extensions = 5
         for i in range(num_extensions):
-            dummy_cpu_cgroup = CGroup.create("dummy_path", "cpu", "dummy_extension_{0}".format(i))
+            dummy_cpu_cgroup = CGroup.create("dummy_cpu_path_{0}".format(i), "cpu", "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_cpu_cgroup)
 
-            dummy_memory_cgroup = CGroup.create("dummy_path", "memory", "dummy_extension_{0}".format(i))
+            dummy_memory_cgroup = CGroup.create("dummy_memory_path_{0}".format(i), "memory",
+                                                "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_memory_cgroup)
 
         with patch("azurelinuxagent.common.cgroup.MemoryCgroup._get_memory_max_usage") as patch_get_memory_max_usage:
@@ -165,10 +167,11 @@ class TestCGroupsTelemetry(AgentTestCase):
     def test_telemetry_polling_with_inactive_cgroups(self, *args):
         num_extensions = 5
         for i in range(num_extensions):
-            dummy_cpu_cgroup = CGroup.create("dummy_path", "cpu", "dummy_extension_{0}".format(i))
+            dummy_cpu_cgroup = CGroup.create("dummy_cpu_path_{0}".format(i), "cpu", "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_cpu_cgroup)
 
-            dummy_memory_cgroup = CGroup.create("dummy_path", "memory", "dummy_extension_{0}".format(i))
+            dummy_memory_cgroup = CGroup.create("dummy_memory_path_{0}".format(i), "memory",
+                                                "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_memory_cgroup)
 
         with patch("azurelinuxagent.common.cgroup.MemoryCgroup._get_memory_max_usage") as patch_get_memory_max_usage:
@@ -188,14 +191,14 @@ class TestCGroupsTelemetry(AgentTestCase):
                         patch_get_memory_max_usage.return_value = current_max_memory  # example 450 MB
 
                         for i in range(num_extensions):
-                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "cpu"))
-                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "memory"))
+                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_cpu_path_{0}".format(i)))
+                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_memory_path_{0}".format(i)))
 
                         CGroupsTelemetry.poll_all_tracked()
 
                         for i in range(num_extensions):
-                            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "cpu"))
-                            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "memory"))
+                            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_cpu_path_{0}".format(i)))
+                            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_memory_path_{0}".format(i)))
 
                         self.assertEqual(CGroupsTelemetry._cgroup_metrics.__len__(), num_extensions)
 
@@ -222,10 +225,11 @@ class TestCGroupsTelemetry(AgentTestCase):
     def test_telemetry_polling_with_changing_cgroups_state(self, *args):
         num_extensions = 5
         for i in range(num_extensions):
-            dummy_cpu_cgroup = CGroup.create("dummy_path", "cpu", "dummy_extension_{0}".format(i))
+            dummy_cpu_cgroup = CGroup.create("dummy_cpu_path_{0}".format(i), "cpu", "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_cpu_cgroup)
 
-            dummy_memory_cgroup = CGroup.create("dummy_path", "memory", "dummy_extension_{0}".format(i))
+            dummy_memory_cgroup = CGroup.create("dummy_memory_path_{0}".format(i), "memory",
+                                                "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_memory_cgroup)
 
         with patch("azurelinuxagent.common.cgroup.MemoryCgroup._get_memory_max_usage") as patch_get_memory_max_usage:
@@ -246,14 +250,14 @@ class TestCGroupsTelemetry(AgentTestCase):
                         patch_get_memory_max_usage.return_value = current_max_memory  # example 450 MB
 
                         for i in range(num_extensions):
-                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "cpu"))
-                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "memory"))
+                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_cpu_path_{0}".format(i)))
+                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_memory_path_{0}".format(i)))
 
                         CGroupsTelemetry.poll_all_tracked()
 
                         for i in range(num_extensions):
-                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "cpu"))
-                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "memory"))
+                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_cpu_path_{0}".format(i)))
+                            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_memory_path_{0}".format(i)))
 
                         self.assertEqual(CGroupsTelemetry._cgroup_metrics.__len__(), num_extensions)
 
@@ -261,8 +265,8 @@ class TestCGroupsTelemetry(AgentTestCase):
                         CGroupsTelemetry.poll_all_tracked()
 
                         for i in range(num_extensions):
-                            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "cpu"))
-                            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "memory"))
+                            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_cpu_path_{0}".format(i)))
+                            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_memory_path_{0}".format(i)))
 
                         self.assertEqual(CGroupsTelemetry._cgroup_metrics.__len__(), num_extensions)
 
@@ -299,10 +303,11 @@ class TestCGroupsTelemetry(AgentTestCase):
         max_memory_usage_values = [random.randint(0, 8 * 1024 ** 3) for _ in range(num_polls)]
 
         for i in range(num_extensions):
-            dummy_cpu_cgroup = CGroup.create("dummy_path", "cpu", "dummy_extension_{0}".format(i))
+            dummy_cpu_cgroup = CGroup.create("dummy_cpu_path_{0}".format(i), "cpu", "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_cpu_cgroup)
 
-            dummy_memory_cgroup = CGroup.create("dummy_path", "memory", "dummy_extension_{0}".format(i))
+            dummy_memory_cgroup = CGroup.create("dummy_memory_path_{0}".format(i), "memory",
+                                                "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_memory_cgroup)
 
         self.assertEqual(2 * num_extensions, len(CGroupsTelemetry._tracked))
@@ -344,15 +349,16 @@ class TestCGroupsTelemetry(AgentTestCase):
         num_extensions = 5
         num_controllers = 2
         for i in range(num_extensions):
-            dummy_cpu_cgroup = CGroup.create("dummy_path", "cpu", "dummy_extension_{0}".format(i))
+            dummy_cpu_cgroup = CGroup.create("dummy_cpu_path_{0}".format(i), "cpu", "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_cpu_cgroup)
 
-            dummy_memory_cgroup = CGroup.create("dummy_path", "memory", "dummy_extension_{0}".format(i))
+            dummy_memory_cgroup = CGroup.create("dummy_memory_path_{0}".format(i), "memory",
+                                                "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_memory_cgroup)
 
         for i in range(num_extensions):
-            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "cpu"))
-            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "memory"))
+            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_cpu_path_{0}".format(i)))
+            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_memory_path_{0}".format(i)))
 
         self.assertEqual(num_extensions * num_controllers, len(CGroupsTelemetry._tracked))
 
@@ -360,45 +366,48 @@ class TestCGroupsTelemetry(AgentTestCase):
         num_extensions = 5
         num_controllers = 2
         for i in range(num_extensions):
-            dummy_cpu_cgroup = CGroup.create("dummy_path", "cpu", "dummy_extension_{0}".format(i))
+            dummy_cpu_cgroup = CGroup.create("dummy_cpu_path_{0}".format(i), "cpu", "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_cpu_cgroup)
 
-            dummy_memory_cgroup = CGroup.create("dummy_path", "memory", "dummy_extension_{0}".format(i))
+            dummy_memory_cgroup = CGroup.create("dummy_memory_path_{0}".format(i), "memory",
+                                                "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_memory_cgroup)
 
         for i in range(num_extensions):
-            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "cpu"))
-            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "memory"))
+            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_cpu_path_{0}".format(i)))
+            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_memory_path_{0}".format(i)))
 
         self.assertEqual(num_extensions * num_controllers, len(CGroupsTelemetry._tracked))
 
         CGroupsTelemetry.prune_all_tracked()
 
         for i in range(num_extensions):
-            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "cpu"))
-            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), "memory"))
+            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_cpu_path_{0}".format(i)))
+            self.assertFalse(CGroupsTelemetry.is_tracked("dummy_memory_path_{0}".format(i)))
 
         self.assertEqual(0, len(CGroupsTelemetry._tracked))
 
     def test_cgroup_is_tracked(self):
         num_extensions = 5
         for i in range(num_extensions):
-            dummy_cpu_cgroup = CGroup.create("dummy_path", "cpu", "dummy_extension_{0}".format(i))
+            dummy_cpu_cgroup = CGroup.create("dummy_cpu_path_{0}".format(i), "cpu", "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_cpu_cgroup)
 
-            dummy_memory_cgroup = CGroup.create("dummy_path", "memory", "dummy_extension_{0}".format(i))
+            dummy_memory_cgroup = CGroup.create("dummy_memory_path_{0}".format(i), "memory", "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_memory_cgroup)
 
         for i in range(num_extensions):
-            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), 'cpu'))
-            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_extension_{0}".format(i), 'memory'))
+            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_cpu_path_{0}".format(i)))
+            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_memory_path_{0}".format(i)))
 
-        self.assertFalse(CGroupsTelemetry.is_tracked("not_present_dummy_extension_{0}".format(i), 'cpu'))
-        self.assertFalse(CGroupsTelemetry.is_tracked("not_present_dummy_extension_{0}".format(i), 'memory'))
+        self.assertFalse(CGroupsTelemetry.is_tracked("not_present_cpu_dummy_path"))
+        self.assertFalse(CGroupsTelemetry.is_tracked("not_present_memory_dummy_path"))
 
     @skip_if_predicate_false(i_am_root, "This test will only run as root")
     @skip_if_predicate_false(CGroupConfigurator.get_instance().enabled, "Does not run when Cgroups are not enabled")
     def test_telemetry_with_tracked_cgroup(self):
+        # TODO: Write another test like this which would work for systemd as well, explicitely.
+
         max_num_polls = 30
         time_to_wait = 3
         extn_name = "foobar-1.0.0"
@@ -425,10 +434,17 @@ for i in range(5):
 
         self.log_dir = os.path.join(self.tmp_dir, "log")
 
-        with patch("azurelinuxagent.ga.exthandlers.ExtHandlerInstance.get_base_dir", lambda *_: self.tmp_dir) as patch_get_base_dir:
-            with patch("azurelinuxagent.ga.exthandlers.ExtHandlerInstance.get_log_dir", lambda *_: self.log_dir) as patch_get_log_dir:
+        with patch("azurelinuxagent.ga.exthandlers.ExtHandlerInstance.get_base_dir", lambda *_: self.tmp_dir) as \
+                patch_get_base_dir:
+            with patch("azurelinuxagent.ga.exthandlers.ExtHandlerInstance.get_log_dir", lambda *_: self.log_dir) as \
+                    patch_get_log_dir:
                 self.ext_handler_instance.launch_command(command)
 
+        self.assertTrue(CGroupsTelemetry.is_tracked(os.path.join(
+            BASE_CGROUPS, "cpu", "walinuxagent.extensions", "foobar_1.0.0")))
+        self.assertTrue(CGroupsTelemetry.is_tracked(os.path.join(
+            BASE_CGROUPS, "memory", "walinuxagent.extensions", "foobar_1.0.0")))
+
         for i in range(max_num_polls):
             CGroupsTelemetry.poll_all_tracked()
             time.sleep(0.5)
diff --git a/tests/ga/test_monitor.py b/tests/ga/test_monitor.py
index ca7fd512..91398f18 100644
--- a/tests/ga/test_monitor.py
+++ b/tests/ga/test_monitor.py
@@ -235,6 +235,11 @@ class TestMonitor(AgentTestCase):
 @patch("azurelinuxagent.common.protocol.healthservice.HealthService._report")
 @patch("azurelinuxagent.common.utils.restutil.http_get")
 class TestExtensionMetricsDataTelemetry(AgentTestCase):
+
+    def setUp(self):
+        AgentTestCase.setUp(self)
+        CGroupsTelemetry.cleanup()
+
     @patch('azurelinuxagent.common.event.EventLogger.add_event')
     @patch("azurelinuxagent.common.cgroupstelemetry.CGroupsTelemetry.poll_all_tracked")
     @patch("azurelinuxagent.common.cgroupstelemetry.CGroupsTelemetry.report_all_tracked")
@@ -261,6 +266,24 @@ class TestExtensionMetricsDataTelemetry(AgentTestCase):
         self.assertEqual(1, patch_add_event.call_count)
         monitor_handler.stop()
 
+    @patch('azurelinuxagent.common.event.EventLogger.add_event')
+    @patch("azurelinuxagent.common.cgroupstelemetry.CGroupsTelemetry.poll_all_tracked")
+    @patch("azurelinuxagent.common.cgroupstelemetry.CGroupsTelemetry.report_all_tracked", return_value={})
+    def test_send_extension_metrics_telemetry_for_empty_cgroup(self, patch_report_all_tracked, patch_poll_all_tracked,
+                                                               patch_add_event, *args):
+        patch_report_all_tracked.return_value = {}
+
+        monitor_handler = get_monitor_handler()
+        monitor_handler.init_protocols()
+        monitor_handler.last_cgroup_polling_telemetry = datetime.datetime.utcnow() - timedelta(hours=1)
+        monitor_handler.last_cgroup_report_telemetry = datetime.datetime.utcnow() - timedelta(hours=1)
+        monitor_handler.poll_telemetry_metrics()
+        monitor_handler.send_telemetry_metrics()
+        self.assertEqual(1, patch_poll_all_tracked.call_count)
+        self.assertEqual(1, patch_report_all_tracked.call_count)
+        self.assertEqual(0, patch_add_event.call_count)
+        monitor_handler.stop()
+
     @skip_if_predicate_false(i_am_root, "Test does not run when non-root")
     @skip_if_predicate_false(CGroupConfigurator.get_instance().enabled, "Does not run when Cgroups are not enabled")
     @patch('azurelinuxagent.common.event.EventLogger.add_event')
@@ -312,10 +335,11 @@ class TestExtensionMetricsDataTelemetry(AgentTestCase):
         max_memory_usage_values = [random.randint(0, 8 * 1024 ** 3) for _ in range(num_polls)]
 
         for i in range(num_extensions):
-            dummy_cpu_cgroup = CGroup.create("dummy_path", "cpu", "dummy_extension_{0}".format(i))
+            dummy_cpu_cgroup = CGroup.create("dummy_cpu_path_{0}".format(i), "cpu", "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_cpu_cgroup)
 
-            dummy_memory_cgroup = CGroup.create("dummy_path", "memory", "dummy_extension_{0}".format(i))
+            dummy_memory_cgroup = CGroup.create("dummy_memory_path_{0}".format(i), "memory",
+                                                "dummy_extension_{0}".format(i))
             CGroupsTelemetry.track_cgroup(dummy_memory_cgroup)
 
         self.assertEqual(2 * num_extensions, len(CGroupsTelemetry._tracked))
@@ -336,6 +360,10 @@ class TestExtensionMetricsDataTelemetry(AgentTestCase):
         message_json = generate_extension_metrics_telemetry_dictionary(schema_version=1.0,
                                                                        performance_metrics=performance_metrics)
 
+        for i in range(num_extensions):
+            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_cpu_path_{0}".format(i)))
+            self.assertTrue(CGroupsTelemetry.is_tracked("dummy_memory_path_{0}".format(i)))
+
         self.assertIn("SchemaVersion", message_json)
         self.assertIn("PerfMetrics", message_json)
 
diff --git a/tests/protocol/test_wire.py b/tests/protocol/test_wire.py
index 41fb2f6d..afc6f3b1 100644
--- a/tests/protocol/test_wire.py
+++ b/tests/protocol/test_wire.py
@@ -217,7 +217,7 @@ class TestWireProtocol(AgentTestCase):
         packer_version = '{0} --version'.format(packer)
         rc, stdout = run_get_output(packer_version)
         self.assertEqual(0, rc)
-        self.assertEqual('1.2.5\n', stdout)
+        self.assertEqual('1.3.5\n', stdout)
 
 
     @patch("azurelinuxagent.common.protocol.wire.WireClient.update_goal_state")