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

Disable server info and version collection when collect_server_info is false #14610

Merged
merged 11 commits into from
Jun 20, 2023
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')