Skip to content

Commit

Permalink
Disable server info and version collection when collect_server_info i…
Browse files Browse the repository at this point in the history
…s false (#14610)

* if collect_server_info is set to false disable server info and version collection

* the collect metadata in check.py has to check for the collect_server_info before attempting to collect server info, even when the base url is well formated

* add testing to see if metadata is collected when collect_server_info is false

* add testing to see if metadata is collected when collect_server_info is false

* fix typo

* fix typo

* commit

* commit

* commit

* commit typo

* fix check.py
  • Loading branch information
HadhemiDD authored Jun 20, 2023
1 parent d90a7bb commit b8c3ee4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions envoy/datadog_checks/envoy/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def __init__(self, name, init_config, instances):
super().__init__(name, init_config, instances)
self.check_initializations.append(self.configure_additional_transformers)
openmetrics_endpoint = self.instance.get('openmetrics_endpoint')
self.collect_server_info = self.instance.get('collect_server_info', True)

self.base_url = None
try:
parts = urlparse(openmetrics_endpoint)
Expand Down Expand Up @@ -148,7 +150,12 @@ def _collect_metadata(self):
if not self.base_url:
self.log.debug("Skipping server info collection due to malformed url: %s", self.base_url)
return

# From http://domain/thing/stats to http://domain/thing/server_info
if not self.collect_server_info:
self.log.debug("Skipping server info collection as it is disabled, collect_server_info")
return

server_info_url = urljoin(self.base_url, 'server_info')
raw_version = _get_server_info(server_info_url, self.log, self.http)

Expand Down
14 changes: 14 additions & 0 deletions envoy/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,17 @@ def test_collect_metadata_with_invalid_base_url(
c._collect_metadata()
datadog_agent.assert_metadata_count(0)
c.log.debug.assert_called_with('Skipping server info collection due to malformed url: %s', b'')


@requires_py3
def test_collect_metadata_with_disabled_collect_server_info(
datadog_agent, fixture_path, mock_http_response, check, default_instance
):
default_instance["collect_server_info"] = False
c = check(default_instance)
c.check_id = 'test:123'
c.log = mock.MagicMock()

c._collect_metadata()
datadog_agent.assert_metadata_count(0)
c.log.debug.assert_called_with('Skipping server info collection as it is disabled, collect_server_info')

0 comments on commit b8c3ee4

Please sign in to comment.