Repository: Azure/WALinuxAgent
Pull request #1583 (2019-07-16 01:01:20)

Resetting the poll times when the metric is cleared.
<!-- DO NOT DELETE THIS TEMPLATE -->

## Description
Currently, the poll times are not reset, causing the stale first-poll time to show up in the reporting period. This change is to reset the poll periods.

<!--
Please add an informative description that covers that changes made by the pull request. 
This checklist is used to make sure that common issues in a pull request are addressed.
This will expedite the process of getting your pull request merged and avoid extra work on your part to fix issues discovered during the review process.
-->

---

### 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/1583)
<!-- Reviewable:end -->


codecov[bot]: # [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1583?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`develop@2ffb7dc`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##             develop    #1583   +/-   ##
==========================================
  Coverage           ?   64.55%           
==========================================
  Files              ?       78           
  Lines              ?    11103           
  Branches           ?     1569           
==========================================
  Hits               ?     7168           
  Misses             ?     3595           
  Partials           ?      340
```


| [Impacted Files](https://codecov.io/gh/Azure/WALinuxAgent/pull/1583?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [azurelinuxagent/common/cgroupstelemetry.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/1583/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9jZ3JvdXBzdGVsZW1ldHJ5LnB5) | `94.02% <100%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1583?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/1583?src=pr&el=footer). Last update [2ffb7dc...ec6b731](https://codecov.io/gh/Azure/WALinuxAgent/pull/1583?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 6384e88f..18a1382a 100644
--- a/azurelinuxagent/common/cgroupstelemetry.py
+++ b/azurelinuxagent/common/cgroupstelemetry.py
@@ -194,6 +194,8 @@ class Metric(object):
         self._last_poll_time = dt.utcnow()
 
     def clear(self):
+        self._first_poll_time = None
+        self._last_poll_time = None
         self._data *= 0
 
     def average(self):


Test patch:
diff --git a/tests/common/test_cgroupstelemetry.py b/tests/common/test_cgroupstelemetry.py
index 2841649f..b37369f9 100644
--- a/tests/common/test_cgroupstelemetry.py
+++ b/tests/common/test_cgroupstelemetry.py
@@ -700,7 +700,6 @@ class TestMetric(AgentTestCase):
         self.assertEqual(None, test_metric.max())
         self.assertEqual(None, test_metric.min())
         self.assertEqual(None, test_metric.average())
-        # self.assertEqual("None", test_metric.append())
 
     def test_metrics(self):
         num_polls = 10
@@ -714,3 +713,12 @@ class TestMetric(AgentTestCase):
         self.assertListEqual(generate_metric_list(test_values), [test_metric.average(), test_metric.min(),
                                                                  test_metric.max(), test_metric.median(),
                                                                  test_metric.count()])
+
+        test_metric.clear()
+        self.assertEqual("None", test_metric.first_poll_time())
+        self.assertEqual("None", test_metric.last_poll_time())
+        self.assertEqual(0, test_metric.count())
+        self.assertEqual(None, test_metric.median())
+        self.assertEqual(None, test_metric.max())
+        self.assertEqual(None, test_metric.min())
+        self.assertEqual(None, test_metric.average())