Repository: Azure/WALinuxAgent
Pull request #2203 (2021-03-10 23:45:59)

Add Debug options to disable checks on cgroups

codecov[bot]: # [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/2203?src=pr&el=h1) Report
> Merging [#2203](https://codecov.io/gh/Azure/WALinuxAgent/pull/2203?src=pr&el=desc) (9665c98) into [develop](https://codecov.io/gh/Azure/WALinuxAgent/commit/84cef723a84d0181a4e1facf148d9dfa30f87119?el=desc) (84cef72) will **increase** coverage by `0.03%`.
> The diff coverage is `91.66%`.

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

```diff
@@             Coverage Diff             @@
##           develop    #2203      +/-   ##
===========================================
+ Coverage    70.43%   70.46%   +0.03%     
===========================================
  Files           96       96              
  Lines        13538    13548      +10     
  Branches      1910     1910              
===========================================
+ Hits          9535     9547      +12     
- Misses        3590     3591       +1     
+ Partials       413      410       -3     
```


| [Impacted Files](https://codecov.io/gh/Azure/WALinuxAgent/pull/2203?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [azurelinuxagent/common/cgroupconfigurator.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2203/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9jZ3JvdXBjb25maWd1cmF0b3IucHk=) | `71.50% <87.50%> (+0.49%)` | :arrow_up: |
| [azurelinuxagent/common/conf.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2203/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9jb25mLnB5) | `77.03% <100.00%> (+0.44%)` | :arrow_up: |
| [azurelinuxagent/common/event.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2203/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9ldmVudC5weQ==) | `85.29% <0.00%> (-0.68%)` | :arrow_down: |
| [azurelinuxagent/ga/collect\_telemetry\_events.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2203/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2dhL2NvbGxlY3RfdGVsZW1ldHJ5X2V2ZW50cy5weQ==) | `91.43% <0.00%> (+1.71%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/2203?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/2203?src=pr&el=footer). Last update [84cef72...9665c98](https://codecov.io/gh/Azure/WALinuxAgent/pull/2203?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/azurelinuxagent/common/cgroupconfigurator.py b/azurelinuxagent/common/cgroupconfigurator.py
index fa850483..cebb5450 100644
--- a/azurelinuxagent/common/cgroupconfigurator.py
+++ b/azurelinuxagent/common/cgroupconfigurator.py
@@ -19,6 +19,7 @@ import os
 import re
 import subprocess
 
+from azurelinuxagent.common import conf
 from azurelinuxagent.common import logger
 from azurelinuxagent.common.cgroup import CpuCgroup, AGENT_NAME_TELEMETRY, MetricsCounter
 from azurelinuxagent.common.cgroupapi import CGroupsApi, SystemdCgroupsApi, SystemdRunError
@@ -449,17 +450,25 @@ class CGroupConfigurator(object):
 
             errors = []
 
+            processCheckSuccess = False
             try:
                 self._check_processes_in_agent_cgroup()
+                processCheckSuccess = True
             except CGroupsException as exception:
                 errors.append(exception)
 
+            quotaCheckSuccess = False
             try:
                 self._check_agent_throttled_time(cgroup_metrics)
+                quotaCheckSuccess = True
             except CGroupsException as exception:
                 errors.append(exception)
 
-            if len(errors) > 0:
+            disable = not processCheckSuccess and conf.get_cgroup_disable_on_process_check_failure() \
+                      or \
+                      not quotaCheckSuccess and conf.get_cgroup_disable_on_quota_check_failure()
+
+            if disable:
                 self.disable("Check on cgroups failed:\n{0}".format("\n".join([ustr(e) for e in errors])))
 
         def _check_processes_in_agent_cgroup(self):
@@ -514,7 +523,7 @@ class CGroupConfigurator(object):
                     cmdline = '/proc/{0}/cmdline'.format(pid)
                     if os.path.exists(cmdline):
                         with open(cmdline, "r") as cmdline_file:
-                            return "[PID: {0}] {1:40.40}".format(pid, cmdline_file.read())
+                            return "[PID: {0}] {1:64.64}".format(pid, cmdline_file.read())
                 except Exception:
                     pass
                 return "[PID: {0}] UNKNOWN".format(pid)
diff --git a/azurelinuxagent/common/conf.py b/azurelinuxagent/common/conf.py
index 9d1ac9e2..2b446ad8 100644
--- a/azurelinuxagent/common/conf.py
+++ b/azurelinuxagent/common/conf.py
@@ -116,6 +116,8 @@ __SWITCH_OPTIONS__ = {
     # versions of the Agent.
     #
     "Debug.CgroupLogMetrics": False,
+    "Debug.CgroupDisableOnProcessCheckFailure": True,
+    "Debug.CgroupDisableOnQuotaCheckFailure": True,
 }
 
 
@@ -473,6 +475,8 @@ def get_cgroup_check_period(conf=__conf__):
     """
     How often to perform checks on cgroups (are the processes in the cgroups as expected,
     has the agent exceeded its quota, etc)
+
+    NOTE: This option is experimental and may be removed in later versions of the Agent.
     """
     return conf.get_int("Debug.CgroupCheckPeriod", 300)
 
@@ -480,6 +484,25 @@ def get_cgroup_check_period(conf=__conf__):
 def get_cgroup_log_metrics(conf=__conf__):
     """
     If True, resource usage metrics are written to the local log
+
+    NOTE: This option is experimental and may be removed in later versions of the Agent.
     """
     return conf.get_switch("Debug.CgroupLogMetrics", False)
 
+
+def get_cgroup_disable_on_process_check_failure(conf=__conf__):
+    """
+    If True, cgroups will be disabled if the process check fails
+
+    NOTE: This option is experimental and may be removed in later versions of the Agent.
+    """
+    return conf.get_switch("Debug.CgroupDisableOnProcessCheckFailure", True)
+
+
+def get_cgroup_disable_on_quota_check_failure(conf=__conf__):
+    """
+    If True, cgroups will be disabled if the CPU quota check fails
+
+    NOTE: This option is experimental and may be removed in later versions of the Agent.
+    """
+    return conf.get_switch("Debug.CgroupDisableOnQuotaCheckFailure", True)


Test patch:
diff --git a/tests/test_agent.py b/tests/test_agent.py
index 7a4db941..285710bd 100644
--- a/tests/test_agent.py
+++ b/tests/test_agent.py
@@ -28,6 +28,8 @@ AutoUpdate.GAFamily = Prod
 Autoupdate.Frequency = 3600
 DVD.MountPoint = /mnt/cdrom/secure
 Debug.CgroupCheckPeriod = 300
+Debug.CgroupDisableOnProcessCheckFailure = True
+Debug.CgroupDisableOnQuotaCheckFailure = True
 Debug.CgroupLogMetrics = False
 DetectScvmmEnv = False
 EnableOverProvisioning = True