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

NH-80452 Ignore export logs config when AO collector #400

Merged
merged 2 commits into from
Jul 30, 2024
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
17 changes: 17 additions & 0 deletions solarwinds_apm/apm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ def __init__(
self.context.setTracingMode(self.__config["tracing_mode"])
self.context.setTriggerMode(self.__config["trigger_trace"])

# (Re-)Calculate config if AppOptics
self.metric_format = self._calculate_metric_format()
self.certificates = self._calculate_certificates()
self.__config["export_logs_enabled"] = self._calculate_logs_enabled()

logger.debug("Set ApmConfig as: %s", self)

Expand Down Expand Up @@ -612,6 +614,21 @@ def _calculate_certificates(self) -> str:
)
return certs

def _calculate_logs_enabled(self) -> bool:
"""Return if export of logs telemetry enabled, based on collector.
Always False if AO collector, else use current config."""
host = self.get("collector")
if host:
if (
INTL_SWO_AO_COLLECTOR in host
or INTL_SWO_AO_STG_COLLECTOR in host
):
logger.warning(
"AO collector detected. Defaulting to disabled logs export."
)
return False
return self.get("export_logs_enabled")

def mask_service_key(self) -> str:
"""Return masked service key except first 4 and last 4 chars"""
service_key = self.__config.get("service_key")
Expand Down
65 changes: 65 additions & 0 deletions tests/unit/test_apm_config/test_apm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,22 @@ def test__init_oboe_api_and_options_configured_valid(self, mocker):
mock_type.assert_called_once_with(1)
mock_oboe_api_swig.assert_called_once()

def test__init_ao_settings_helpers_called(self, mocker):
mock_metric_format = mocker.patch(
"solarwinds_apm.apm_config.SolarWindsApmConfig._calculate_metric_format"
)
mock_certs = mocker.patch(
"solarwinds_apm.apm_config.SolarWindsApmConfig._calculate_certificates"
)
mock_logs_enabled = mocker.patch(
"solarwinds_apm.apm_config.SolarWindsApmConfig._calculate_logs_enabled"
)

apm_config.SolarWindsApmConfig()
mock_metric_format.assert_called_once()
mock_certs.assert_called_once()
mock_logs_enabled.assert_called_once()

def test_calculate_metric_format_no_collector(self, mocker):
assert apm_config.SolarWindsApmConfig()._calculate_metric_format() == 2

Expand Down Expand Up @@ -481,6 +497,55 @@ def test_calculate_certificates_ao_prod_trustedpath_file_present(self, mocker):
mock_get_public_cert.configure_mock(return_value="foo")
assert apm_config.SolarWindsApmConfig()._calculate_certificates() == "bar"

def test_calculate_logs_enabled_no_collector_enabled(self, mocker):
mocker.patch.dict(os.environ, {
"SW_APM_COLLECTOR": "",
"SW_APM_EXPORT_LOGS_ENABLED": "true",
})
assert apm_config.SolarWindsApmConfig()._calculate_logs_enabled() == True

def test_calculate_logs_enabled_no_collector_disabled(self, mocker):
mocker.patch.dict(os.environ, {
"SW_APM_COLLECTOR": "",
"SW_APM_EXPORT_LOGS_ENABLED": "false",
})
assert apm_config.SolarWindsApmConfig()._calculate_logs_enabled() == False

def test_calculate_logs_enabled_not_ao_enabled(self, mocker):
mocker.patch.dict(os.environ, {
"SW_APM_COLLECTOR": "some-other-collector",
"SW_APM_EXPORT_LOGS_ENABLED": "true",
})
assert apm_config.SolarWindsApmConfig()._calculate_logs_enabled() == True

def test_calculate_logs_enabled_not_ao_disabled(self, mocker):
mocker.patch.dict(os.environ, {
"SW_APM_COLLECTOR": "some-other-collector",
"SW_APM_EXPORT_LOGS_ENABLED": "false",
})
assert apm_config.SolarWindsApmConfig()._calculate_logs_enabled() == False

def test_calculate_logs_enabled_ao_prod(self, mocker):
mocker.patch.dict(os.environ, {
"SW_APM_COLLECTOR": INTL_SWO_AO_COLLECTOR,
"SW_APM_EXPORT_LOGS_ENABLED": "true",
})
assert apm_config.SolarWindsApmConfig()._calculate_logs_enabled() == False

def test_calculate_logs_enabled_ao_staging(self, mocker):
mocker.patch.dict(os.environ, {
"SW_APM_COLLECTOR": INTL_SWO_AO_STG_COLLECTOR,
"SW_APM_EXPORT_LOGS_ENABLED": "true",
})
assert apm_config.SolarWindsApmConfig()._calculate_logs_enabled() == False

def test_calculate_logs_enabled_ao_prod_with_port(self, mocker):
mocker.patch.dict(os.environ, {
"SW_APM_COLLECTOR": "{}:123".format(INTL_SWO_AO_COLLECTOR),
"SW_APM_EXPORT_LOGS_ENABLED": "true",
})
assert apm_config.SolarWindsApmConfig()._calculate_logs_enabled() == False

def test_mask_service_key_no_key_empty_default(self, mocker):
mock_iter_entry_points = mocker.patch(
"solarwinds_apm.apm_config.iter_entry_points"
Expand Down
Loading