Skip to content

Commit

Permalink
Clean up configuration parameters for cgroups (#2178)
Browse files Browse the repository at this point in the history
* Disable cgroups if agent is throttled

* Complete changes

* Python 2.6 compat

* Update conf settings for cgroups

* Fix pylint warning

Co-authored-by: narrieta <narrieta>
  • Loading branch information
narrieta authored Feb 17, 2021
1 parent 6f3a278 commit a4a8b42
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 90 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Microsoft Azure Linux Agent

## Develop branch status
Expand Down Expand Up @@ -219,8 +220,7 @@ OS.SshClientAliveInterval=180
OS.SshDir=/etc/ssh
HttpProxy.Host=None
HttpProxy.Port=None
CGroups.EnforceLimits=y
CGroups.Excluded=customscript,runcommand
CGroups.Enabled=y
```

The various configuration options are described in detail below. Configuration
Expand Down
4 changes: 4 additions & 0 deletions azurelinuxagent/common/cgroupconfigurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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
Expand Down Expand Up @@ -105,6 +106,9 @@ def initialize(self):
if self._initialized:
return

if not conf.get_cgroups_enabled():
return

# check whether cgroup monitoring is supported on the current distro
self._cgroups_supported = CGroupsApi.cgroups_supported()
if not self._cgroups_supported:
Expand Down
13 changes: 4 additions & 9 deletions azurelinuxagent/common/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def load_conf_from_file(conf_file_path, conf=__conf__):
"ResourceDisk.EnableSwapEncryption": False,
"AutoUpdate.Enabled": True,
"EnableOverProvisioning": True,
"CGroups.EnforceLimits": False,
"CGroups.Enabled": True,
}


Expand All @@ -134,7 +134,6 @@ def load_conf_from_file(conf_file_path, conf=__conf__):
"ResourceDisk.MountOptions": None,
"ResourceDisk.Filesystem": "ext3",
"AutoUpdate.GAFamily": "Prod",
"CGroups.Excluded": "customscript,runcommand",
}


Expand Down Expand Up @@ -453,13 +452,9 @@ def get_disable_agent_file_path(conf=__conf__):
return os.path.join(get_lib_dir(conf), DISABLE_AGENT_FILE)


def get_cgroups_enforce_limits(conf=__conf__):
return conf.get_switch("CGroups.EnforceLimits", False)
def get_cgroups_enabled(conf=__conf__):
return conf.get_switch("CGroups.Enabled", True)


def get_cgroups_excluded(conf=__conf__):
excluded_value = conf.get("CGroups.Excluded", "customscript, runcommand")
return [s for s in [i.strip().lower() for i in excluded_value.split(',')] if len(s) > 0] if excluded_value else []

def get_monitor_network_configuration_changes(conf=__conf__):
return conf.get_switch("Monitor.NetworkConfigurationChanges", False)
return conf.get_switch("Monitor.NetworkConfigurationChanges", False)
5 changes: 0 additions & 5 deletions config/alpine/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,3 @@ OS.SshDir=/etc/ssh
# Add firewall rules to protect access to Azure host node services
OS.EnableFirewall=y

# Enforce control groups limits on the agent and extensions
CGroups.EnforceLimits=n

# CGroups which are excluded from limits, comma separated
CGroups.Excluded=customscript,runcommand
5 changes: 0 additions & 5 deletions config/bigip/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,3 @@ AutoUpdate.Enabled=y
# Add firewall rules to protect access to Azure host node services
OS.EnableFirewall=y

# Enforce control groups limits on the agent and extensions
CGroups.EnforceLimits=n

# CGroups which are excluded from limits, comma separated
CGroups.Excluded=customscript,runcommand
5 changes: 0 additions & 5 deletions config/coreos/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,3 @@ OS.AllowHTTP=y
# Add firewall rules to protect access to Azure host node services
OS.EnableFirewall=y

# Enforce control groups limits on the agent and extensions
CGroups.EnforceLimits=n

# CGroups which are excluded from limits, comma separated
CGroups.Excluded=customscript,runcommand
5 changes: 0 additions & 5 deletions config/debian/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,3 @@ OS.SshDir=/etc/ssh
# - The default is false to protect the state of existing VMs
OS.EnableFirewall=n

# Enforce control groups limits on the agent and extensions
CGroups.EnforceLimits=n

# CGroups which are excluded from limits, comma separated
CGroups.Excluded=customscript,runcommand
5 changes: 0 additions & 5 deletions config/freebsd/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,3 @@ OS.SudoersDir=/usr/local/etc/sudoers.d
# Add firewall rules to protect access to Azure host node services
OS.EnableFirewall=y

# Enforce control groups limits on the agent and extensions
CGroups.EnforceLimits=n

# CGroups which are excluded from limits, comma separated
CGroups.Excluded=customscript,runcommand
5 changes: 0 additions & 5 deletions config/ubuntu/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,3 @@ OS.SshDir=/etc/ssh
# Add firewall rules to protect access to Azure host node services
OS.EnableFirewall=y

# Enforce control groups limits on the agent and extensions
CGroups.EnforceLimits=n

# CGroups which are excluded from limits, comma separated
CGroups.Excluded=customscript,runcommand
7 changes: 2 additions & 5 deletions config/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,5 @@ OS.RemovePersistentNetRulesPeriod=30
# How often (in seconds) to monitor for DHCP client restarts
OS.MonitorDhcpClientRestartPeriod=30

# Enforce control groups limits on the agent and extensions
CGroups.EnforceLimits=n

# CGroups which are excluded from limits, comma separated
CGroups.Excluded=customscript,runcommand
# Use cgroups to monitor the resource usage of the agent and extensions
CGroups.Enabled=y
6 changes: 5 additions & 1 deletion tests/common/test_cgroupconfigurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def test_initialize_should_enable_cgroups(self):
with self._get_cgroup_configurator() as configurator:
self.assertTrue(configurator.enabled(), "cgroups were not enabled")

def test_initialize_should_not_enable_cgroups_when_they_are_disabled_in_the_agent_configuration(self):
with patch('azurelinuxagent.common.conf.get_cgroups_enabled', return_value=False):
with self._get_cgroup_configurator() as configurator:
self.assertFalse(configurator.enabled(), "cgroups should not be enabled")

def test_initialize_should_start_tracking_the_agent_cgroups(self):
with self._get_cgroup_configurator() as configurator:
tracked = CGroupsTelemetry._tracked
Expand Down Expand Up @@ -666,7 +671,6 @@ def get_completed_process():
self.assertTrue(
any("[PID: {0}]".format(pid) in reported_process for reported_process in reported),
"Process {0} was not reported. Got: {1}".format(format_processes([pid]), reported))

finally:
# create the file that stops the test processes and wait for them to complete
open(stop_file, "w").close()
Expand Down
40 changes: 4 additions & 36 deletions tests/common/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import azurelinuxagent.common.conf as conf
from azurelinuxagent.common.utils import fileutil
from tests.tools import AgentTestCase, data_dir, patch
from tests.tools import AgentTestCase, data_dir


class TestConf(AgentTestCase):
Expand Down Expand Up @@ -66,8 +66,7 @@ class TestConf(AgentTestCase):
"EnableOverProvisioning": True,
"OS.AllowHTTP": False,
"OS.EnableFirewall": False,
"CGroups.EnforceLimits": False,
"CGroups.Excluded": "customscript,runcommand",
"CGroups.Enabled": True,
}

def setUp(self):
Expand Down Expand Up @@ -135,36 +134,5 @@ def test_write_agent_disabled(self):
def test_get_extensions_enabled(self):
self.assertTrue(conf.get_extensions_enabled(self.conf))

@patch('azurelinuxagent.common.conf.ConfigurationProvider.get')
def assert_get_cgroups_excluded(self, patch_get, config, expected_value):
patch_get.return_value = config
self.assertEqual(expected_value, conf.get_cgroups_excluded(self.conf))

def test_get_cgroups_excluded(self):
self.assert_get_cgroups_excluded(config=None, # pylint: disable=no-value-for-parameter
expected_value=[])

self.assert_get_cgroups_excluded(config='', # pylint: disable=no-value-for-parameter
expected_value=[])

self.assert_get_cgroups_excluded(config=' ', # pylint: disable=no-value-for-parameter
expected_value=[])

self.assert_get_cgroups_excluded(config=' , ,, ,', # pylint: disable=no-value-for-parameter
expected_value=[])

standard_values = ['customscript', 'runcommand']
self.assert_get_cgroups_excluded(config='CustomScript, RunCommand', # pylint: disable=no-value-for-parameter
expected_value=standard_values)

self.assert_get_cgroups_excluded(config='customScript, runCommand , , ,,', # pylint: disable=no-value-for-parameter
expected_value=standard_values)

self.assert_get_cgroups_excluded(config=' customscript,runcommand ', # pylint: disable=no-value-for-parameter
expected_value=standard_values)

self.assert_get_cgroups_excluded(config='customscript,, runcommand', # pylint: disable=no-value-for-parameter
expected_value=standard_values)

self.assert_get_cgroups_excluded(config=',,customscript ,runcommand', # pylint: disable=no-value-for-parameter
expected_value=standard_values)
def test_get_cgroups_enabled(self):
self.assertTrue(conf.get_cgroups_enabled(self.conf))
5 changes: 0 additions & 5 deletions tests/data/test_waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,3 @@ OS.SshDir=/notareal/path
# - The default is false to protect the state of existing VMs
OS.EnableFirewall=n

# Enforce control groups limits on the agent and extensions
CGroups.EnforceLimits=n

# CGroups which are excluded from limits, comma separated
CGroups.Excluded=customscript,runcommand
3 changes: 1 addition & 2 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"""AutoUpdate.Enabled = True
AutoUpdate.GAFamily = Prod
Autoupdate.Frequency = 3600
CGroups.EnforceLimits = False
CGroups.Excluded = customscript,runcommand
CGroups.Enabled = True
DVD.MountPoint = /mnt/cdrom/secure
DetectScvmmEnv = False
EnableOverProvisioning = True
Expand Down

0 comments on commit a4a8b42

Please sign in to comment.