Skip to content
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

Fix regression on agent 5 only #2848

Merged
merged 4 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion disk/datadog_checks/disk/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
except ImportError:
psutil = None

try:
import datadog_agent
is_agent_6 = True
except ImportError:
is_agent_6 = False

from datadog_checks.base import AgentCheck, ConfigurationError, is_affirmative
from datadog_checks.base.utils.platform import Platform
from datadog_checks.base.utils.subprocess_output import get_subprocess_output
Expand All @@ -35,7 +41,6 @@ def __init__(self, name, init_config, agentConfig, instances=None):
AgentCheck.__init__(self, name, init_config, agentConfig, instances=instances)

instance = instances[0]
self._use_mount = is_affirmative(instance.get('use_mount', False))
self._all_partitions = is_affirmative(instance.get('all_partitions', False))
self._file_system_whitelist = instance.get('file_system_whitelist', [])
self._file_system_blacklist = instance.get('file_system_blacklist', [])
Expand All @@ -48,9 +53,32 @@ def __init__(self, name, init_config, agentConfig, instances=None):
self._custom_tags = instance.get('tags', [])
self._service_check_rw = is_affirmative(instance.get('service_check_rw', False))

if is_agent_6:
self._use_mount = is_affirmative(instance.get('use_mount', False))
else:
# FIXME: 6.x, drop use_mount option in datadog.conf
self._load_legacy_option(instance, 'use_mount', False, operation=is_affirmative)

# FIXME: 6.x, drop device_blacklist_re option in datadog.conf
self._load_legacy_option(
instance, 'excluded_disk_re', '^$', legacy_name='device_blacklist_re', operation=re.compile
)
self._compile_pattern_filters(instance)
self._compile_tag_re()

def _load_legacy_option(self, instance, option, default, legacy_name=None, operation=lambda l: l):
value = instance.get(option, default)
legacy_name = legacy_name or option

if value == default and legacy_name in self.agentConfig:
self.log.warning(
'Using `{}` in datadog.conf has been deprecated '
'in favor of `{}` in disk.yaml'.format(legacy_name, option)
)
value = self.agentConfig.get(legacy_name) or default

setattr(self, '_{}'.format(option), operation(value))

def check(self, instance):
"""Get disk space/inode stats"""
# Windows and Mac will always have psutil
Expand Down
11 changes: 11 additions & 0 deletions disk/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def test_bad_config():
Disk('disk', None, {}, [{}, {}])


def test_legacy_option(instance_basic_mount, instance_basic_volume):
"""
Ensure check option overrides datadog.conf
"""
c = Disk('disk', None, instance_basic_mount, [{}])
assert c._use_mount is True

c = Disk('disk', None, instance_basic_mount, [instance_basic_volume])
assert c._use_mount is False


@pytest.mark.usefixtures('psutil_mocks')
def test_psutil(aggregator, gauge_metrics, rate_metrics):
"""
Expand Down