-
Notifications
You must be signed in to change notification settings - Fork 372
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
Minor refactoring of cgroup telemetry #1607
Conversation
@@ -184,15 +181,14 @@ def _get_cpu_percent(self): | |||
|
|||
return round(float(cpu_delta * self._osutil.get_processor_cores() * 100) / float(system_delta), 3) | |||
|
|||
def collect(self): | |||
def get_cpu_usage(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of collect returned an array of different length with different items for each of the controllers. This makes it difficult to use and error prone. I removed it and instead added explicit methods to get each metric.
@@ -231,7 +227,7 @@ def _get_memory_usage(self): | |||
usage = "0" | |||
return int(usage) | |||
|
|||
def _get_memory_max_usage(self): | |||
def get_max_memory_usage(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made it public + rename
@@ -209,7 +205,7 @@ def __str__(self): | |||
self.name, self.path, self.controller | |||
) | |||
|
|||
def _get_memory_usage(self): | |||
def get_memory_usage(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made it public
CollectedMetrics("memory", "Max Memory Usage", max_usage)] | ||
|
||
|
||
class CollectedMetrics(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was not needed
@@ -118,19 +120,7 @@ def poll_all_tracked(): | |||
if cgroup.name not in CGroupsTelemetry._cgroup_metrics: | |||
CGroupsTelemetry._cgroup_metrics[cgroup.name] = CgroupMetrics() | |||
|
|||
metric = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved the exception handling to collect_data
self._current_memory_usage = Metric() | ||
self._max_memory_levels = Metric() | ||
self._current_cpu_usage = Metric() | ||
self._memory_usage = Metric() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed those members to have consistent names with the rest of the code
self._current_memory_usage.clear() | ||
self._max_memory_levels.clear() | ||
self._current_cpu_usage.clear() | ||
self._memory_usage.clear() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed for consistency
@@ -188,12 +182,12 @@ def __init__(self): | |||
self._first_poll_time = None | |||
self._last_poll_time = None | |||
|
|||
def append(self, metric): | |||
def append(self, data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'metric' was confusing since we are not adding a Metric, but a number
self.assertListEqual(max_memory_levels._data, [current_max_memory] * data_count) | ||
self.assertEqual(len(current_cpu_usage._data), data_count) | ||
self.assertListEqual(current_cpu_usage._data, [current_cpu] * data_count) | ||
self.assertEqual(len(CGroupsTelemetry._cgroup_metrics), num_extensions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those checks were repeated over and over so capture them on a helper function _assert_cgroup_metrics_equal
Codecov Report
@@ Coverage Diff @@
## develop #1607 +/- ##
===========================================
- Coverage 66.01% 65.98% -0.03%
===========================================
Files 77 77
Lines 11051 11036 -15
Branches 1558 1556 -2
===========================================
- Hits 7295 7282 -13
+ Misses 3422 3421 -1
+ Partials 334 333 -1
Continue to review full report at Codecov.
|
|
||
def get_metrics(self): | ||
return self._current_memory_usage, self._max_memory_levels, self._current_cpu_usage | ||
def get_cpu_usage(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_metrics was returning a list of values, replaced it with explicit methods for each value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the inline comments, made it easier to understand the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
While reviewing the code for cpu computation I did some refactoring to make it clearer. I'm adding comments in the PR to point our what changed.
PR information
Quality of Code and Contribution Guidelines
This change is