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

Make is_metadata_collection_enabled static #5863

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ def send_config_metadata(self):
'config', self.init_config, section='init_config', whitelist=self.METADATA_DEFAULT_CONFIG_INIT_CONFIG
)

def is_metadata_collection_enabled(self):
@staticmethod
def is_metadata_collection_enabled():
return is_affirmative(datadog_agent.get_config('enable_metadata_collection'))

def set_external_tags(self, external_tags):
Expand Down
15 changes: 15 additions & 0 deletions datadog_checks_base/tests/test_agent_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ def test_load_config():
assert AgentCheck.load_config("raw_foo: bar") == {'raw_foo': 'bar'}


@pytest.mark.parametrize(
'enable_metadata_collection, expected_is_metadata_collection_enabled',
[(None, False), ('true', True), ('false', False)],
)
def test_is_metadata_collection_enabled(enable_metadata_collection, expected_is_metadata_collection_enabled):
check = AgentCheck()
with mock.patch('datadog_checks.base.checks.base.datadog_agent.get_config') as get_config:
get_config.return_value = enable_metadata_collection

assert check.is_metadata_collection_enabled() is expected_is_metadata_collection_enabled
assert AgentCheck.is_metadata_collection_enabled() is expected_is_metadata_collection_enabled

get_config.assert_called_with('enable_metadata_collection')


def test_log_critical_error():
check = AgentCheck()

Expand Down