diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index d856982a1b..b163ff54fd 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -333,9 +333,13 @@ def __init__(self, application, enabled=None, source=None): self.enabled = True if self._settings: - self._custom_events = SampledDataSet(capacity=self._settings.custom_insights_events.max_samples_stored) + self._custom_events = SampledDataSet( + capacity=self._settings.event_harvest_config.harvest_limits.custom_event_data + ) self._ml_events = SampledDataSet(capacity=self._settings.event_harvest_config.harvest_limits.ml_event_data) - self._log_events = SampledDataSet(capacity=self._settings.application_logging.forwarding.max_samples_stored) + self._log_events = SampledDataSet( + capacity=self._settings.event_harvest_config.harvest_limits.log_event_data + ) else: self._custom_events = SampledDataSet(capacity=CUSTOM_EVENT_RESERVOIR_SIZE) self._log_events = SampledDataSet(capacity=LOG_EVENT_RESERVOIR_SIZE) diff --git a/newrelic/config.py b/newrelic/config.py index 3221b26438..cb879d9c4b 100644 --- a/newrelic/config.py +++ b/newrelic/config.py @@ -638,6 +638,63 @@ def delete_setting(settings_object, name): _logger.debug("Failed to delete setting: %r", name) +def translate_event_harvest_config_settings(settings, cached_settings): + """Translate event_harvest_config settings to max_samples settings. + + Background: + The collector/server side agent configuration uses the + `event_harvest_config` naming convention for their harvest + limit settings. The original intent was for the language + agents to switch to this convention. However, this only + happened for the Python agent. Eventually, to remain + consistent with the other language agents, the decision + was made to change this back. However, because the server + side configuration settings override the client-side settings, + the agent will insist on employing the `max_samples` naming + convention from the user's end but translate the settings + to their deprecated `event_harvest_config` counterparts during + the configuration process. + + Here, the user will still get warnings about deprecated settings + being used. However, the agent will also translate the settings + to their deprecated `event_harvest_config` counterparts during + the configuration process. + """ + + cached = dict(cached_settings) + + event_harvest_to_max_samples_settings_map = [ + ("event_harvest_config.harvest_limits.analytic_event_data", "transaction_events.max_samples_stored"), + ("event_harvest_config.harvest_limits.span_event_data", "span_events.max_samples_stored"), + ("event_harvest_config.harvest_limits.error_event_data", "error_collector.max_event_samples_stored"), + ("event_harvest_config.harvest_limits.custom_event_data", "custom_insights_events.max_samples_stored"), + ("event_harvest_config.harvest_limits.log_event_data", "application_logging.forwarding.max_samples_stored"), + ] + + for event_harvest_key, max_samples_key in event_harvest_to_max_samples_settings_map: + if event_harvest_key in cached: + _logger.info( + "Deprecated setting found: %r. Please use new setting: %r.", event_harvest_key, max_samples_key + ) + + if max_samples_key in cached: + # Since there is the max_samples key as well as the event_harvest key, + # we need to apply the max_samples value to the event_harvest key. + apply_config_setting(settings, event_harvest_key, cached[max_samples_key]) + _logger.info( + "Ignoring deprecated setting: %r. Using new setting: %r.", event_harvest_key, max_samples_key + ) + else: + # Translation to event_harvest_config has already happened + _logger.info("Applying value of deprecated setting %r to %r.", event_harvest_key, max_samples_key) + elif max_samples_key in cached: + apply_config_setting(settings, event_harvest_key, cached[max_samples_key]) + + delete_setting(settings, max_samples_key) + + return settings + + def translate_deprecated_settings(settings, cached_settings): # If deprecated setting has been set by user, but the new # setting has not, then translate the deprecated setting to the @@ -669,19 +726,7 @@ def translate_deprecated_settings(settings, cached_settings): cached = dict(cached_settings) deprecated_settings_map = [ - ("transaction_tracer.capture_attributes", "transaction_tracer.attributes.enabled"), - ("error_collector.capture_attributes", "error_collector.attributes.enabled"), - ("browser_monitoring.capture_attributes", "browser_monitoring.attributes.enabled"), - ("analytics_events.capture_attributes", "transaction_events.attributes.enabled"), - ("analytics_events.enabled", "transaction_events.enabled"), - ("analytics_events.max_samples_stored", "transaction_events.max_samples_stored"), - ("event_harvest_config.harvest_limits.analytic_event_data", "transaction_events.max_samples_stored"), - ("event_harvest_config.harvest_limits.span_event_data", "span_events.max_samples_stored"), - ("event_harvest_config.harvest_limits.error_event_data", "error_collector.max_event_samples_stored"), - ("event_harvest_config.harvest_limits.custom_event_data", "custom_insights_events.max_samples_stored"), - ("event_harvest_config.harvest_limits.log_event_data", "application_logging.forwarding.max_samples_stored"), - ("error_collector.ignore_errors", "error_collector.ignore_classes"), - ("strip_exception_messages.whitelist", "strip_exception_messages.allowlist"), + # Nothing in here right now! ] for old_key, new_key in deprecated_settings_map: @@ -979,6 +1024,10 @@ def _load_configuration(config_file=None, environment=None, ignore_errors=True, translate_deprecated_settings(_settings, _cache_object) + # Translate event_harvest_config settings to max_samples settings (from user's side) + + translate_event_harvest_config_settings(_settings, _cache_object) + # Apply High Security Mode policy if enabled in local agent # configuration file. diff --git a/newrelic/core/config.py b/newrelic/core/config.py index 8375a618c8..e7573a1fec 100644 --- a/newrelic/core/config.py +++ b/newrelic/core/config.py @@ -819,7 +819,7 @@ def default_otlp_host(host): ) _settings.transaction_events.enabled = True -_settings.transaction_events.max_samples_stored = _environ_as_int( +_settings.event_harvest_config.harvest_limits.analytic_event_data = _environ_as_int( "NEW_RELIC_ANALYTICS_EVENTS_MAX_SAMPLES_STORED", default=DEFAULT_RESERVOIR_SIZE ) _settings.transaction_events.attributes.enabled = True @@ -827,7 +827,7 @@ def default_otlp_host(host): _settings.transaction_events.attributes.include = [] _settings.custom_insights_events.enabled = True -_settings.custom_insights_events.max_samples_stored = _environ_as_int( +_settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int( "NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", default=CUSTOM_EVENT_RESERVOIR_SIZE ) _settings.custom_insights_events.max_attribute_value = _environ_as_int( @@ -845,7 +845,7 @@ def default_otlp_host(host): ) _settings.distributed_tracing.exclude_newrelic_header = False _settings.span_events.enabled = _environ_as_bool("NEW_RELIC_SPAN_EVENTS_ENABLED", default=True) -_settings.span_events.max_samples_stored = _environ_as_int( +_settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int( "NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED", default=SPAN_EVENT_RESERVOIR_SIZE ) _settings.span_events.attributes.enabled = True @@ -875,7 +875,7 @@ def default_otlp_host(host): _settings.error_collector.ignore_classes = [] _settings.error_collector.ignore_status_codes = _parse_status_codes("100-102 200-208 226 300-308 404", set()) _settings.error_collector.expected_classes = [] -_settings.error_collector.max_event_samples_stored = _environ_as_int( +_settings.event_harvest_config.harvest_limits.error_event_data = _environ_as_int( "NEW_RELIC_ERROR_COLLECTOR_MAX_EVENT_SAMPLES_STORED", default=ERROR_EVENT_RESERVOIR_SIZE ) _settings.error_collector.expected_status_codes = set() @@ -944,30 +944,10 @@ def default_otlp_host(host): _settings.instrumentation.middleware.django.exclude = [] _settings.instrumentation.middleware.django.include = [] -_settings.event_harvest_config.harvest_limits.analytic_event_data = _environ_as_int( - "NEW_RELIC_ANALYTICS_EVENTS_MAX_SAMPLES_STORED", DEFAULT_RESERVOIR_SIZE -) - -_settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int( - "NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", CUSTOM_EVENT_RESERVOIR_SIZE -) - _settings.event_harvest_config.harvest_limits.ml_event_data = _environ_as_int( "NEW_RELIC_ML_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", ML_EVENT_RESERVOIR_SIZE ) -_settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int( - "NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED", SPAN_EVENT_RESERVOIR_SIZE -) - -_settings.event_harvest_config.harvest_limits.error_event_data = _environ_as_int( - "NEW_RELIC_ERROR_COLLECTOR_MAX_EVENT_SAMPLES_STORED", ERROR_EVENT_RESERVOIR_SIZE -) - -_settings.event_harvest_config.harvest_limits.log_event_data = _environ_as_int( - "NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED", LOG_EVENT_RESERVOIR_SIZE -) - _settings.console.listener_socket = None _settings.console.allow_interpreter_cmd = False @@ -1034,7 +1014,7 @@ def default_otlp_host(host): _settings.application_logging.forwarding.custom_attributes = _environ_as_mapping( "NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CUSTOM_ATTRIBUTES", default="" ) -_settings.application_logging.forwarding.max_samples_stored = _environ_as_int( +_settings.event_harvest_config.harvest_limits.log_event_data = _environ_as_int( "NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED", default=LOG_EVENT_RESERVOIR_SIZE ) @@ -1322,7 +1302,9 @@ def apply_server_side_settings(server_side_config=None, settings=_settings): span_event_harvest_config = server_side_config.get("span_event_harvest_config", {}) span_event_harvest_limit = span_event_harvest_config.get("harvest_limit", None) if span_event_harvest_limit is not None: - apply_config_setting(settings_snapshot, "span_events.max_samples_stored", span_event_harvest_limit) + apply_config_setting( + settings_snapshot, "event_harvest_config.harvest_limits.span_event_data", span_event_harvest_limit + ) # Check to see if collect_ai appears in the connect response to handle account-level AIM toggling collect_ai = server_side_config.get("collect_ai", None) diff --git a/newrelic/core/stats_engine.py b/newrelic/core/stats_engine.py index 5b566ac4cc..f44f82fe13 100644 --- a/newrelic/core/stats_engine.py +++ b/newrelic/core/stats_engine.py @@ -1704,19 +1704,21 @@ def reset_transaction_events(self): """ if self.__settings is not None: - self._transaction_events = SampledDataSet(self.__settings.transaction_events.max_samples_stored) + self._transaction_events = SampledDataSet( + self.__settings.event_harvest_config.harvest_limits.analytic_event_data + ) else: self._transaction_events = SampledDataSet() def reset_error_events(self): if self.__settings is not None: - self._error_events = SampledDataSet(self.__settings.error_collector.max_event_samples_stored) + self._error_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.error_event_data) else: self._error_events = SampledDataSet() def reset_custom_events(self): if self.__settings is not None: - self._custom_events = SampledDataSet(self.__settings.custom_insights_events.max_samples_stored) + self._custom_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.custom_event_data) else: self._custom_events = SampledDataSet() @@ -1728,13 +1730,13 @@ def reset_ml_events(self): def reset_span_events(self): if self.__settings is not None: - self._span_events = SampledDataSet(self.__settings.span_events.max_samples_stored) + self._span_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.span_event_data) else: self._span_events = SampledDataSet() def reset_log_events(self): if self.__settings is not None: - self._log_events = SampledDataSet(self.__settings.application_logging.forwarding.max_samples_stored) + self._log_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.log_event_data) else: self._log_events = SampledDataSet() diff --git a/tests/agent_features/test_collector_payloads.py b/tests/agent_features/test_collector_payloads.py index b48112af8d..08b4a53e34 100644 --- a/tests/agent_features/test_collector_payloads.py +++ b/tests/agent_features/test_collector_payloads.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest import webtest from testing_support.fixtures import override_application_settings from testing_support.sample_applications import simple_app, simple_custom_event_app, simple_exceptional_app diff --git a/tests/agent_features/test_configuration.py b/tests/agent_features/test_configuration.py index 4dd0726a82..78517e45ca 100644 --- a/tests/agent_features/test_configuration.py +++ b/tests/agent_features/test_configuration.py @@ -32,6 +32,7 @@ delete_setting, initialize, translate_deprecated_settings, + translate_event_harvest_config_settings, ) from newrelic.core.config import ( Settings, @@ -404,101 +405,117 @@ def test_delete_setting_parent(): # 'value' != 'default' TSetting = collections.namedtuple("TSetting", ["name", "value", "default"]) -translate_settings_tests = [ +translate_event_harvest_settings_tests = [ ( - TSetting("strip_exception_messages.whitelist", [], []), - TSetting("strip_exception_messages.allowlist", ["non-default-value"], []), - ), - ( - TSetting("strip_exception_messages.whitelist", ["non-default-value"], []), - TSetting("strip_exception_messages.allowlist", [], []), - ), - ( - TSetting("transaction_tracer.capture_attributes", True, True), - TSetting("transaction_tracer.attributes.enabled", False, True), - ), - ( - TSetting("transaction_tracer.capture_attributes", False, True), - TSetting("transaction_tracer.attributes.enabled", True, True), - ), - ( - TSetting("error_collector.capture_attributes", True, True), - TSetting("error_collector.attributes.enabled", False, True), - ), - ( - TSetting("error_collector.capture_attributes", False, True), - TSetting("error_collector.attributes.enabled", True, True), - ), - ( - TSetting("browser_monitoring.capture_attributes", False, False), - TSetting("browser_monitoring.attributes.enabled", True, False), - ), - ( - TSetting("browser_monitoring.capture_attributes", True, False), - TSetting("browser_monitoring.attributes.enabled", False, False), - ), - ( - TSetting("analytics_events.capture_attributes", True, True), - TSetting("transaction_events.attributes.enabled", False, True), - ), - ( - TSetting("analytics_events.capture_attributes", False, True), - TSetting("transaction_events.attributes.enabled", True, True), - ), - (TSetting("analytics_events.enabled", True, True), TSetting("transaction_events.enabled", False, True)), - (TSetting("analytics_events.enabled", False, True), TSetting("transaction_events.enabled", True, True)), - ( - TSetting("analytics_events.max_samples_stored", 1200, 1200), - TSetting("transaction_events.max_samples_stored", 9999, 1200), - ), - ( - TSetting("analytics_events.max_samples_stored", 9999, 1200), TSetting("transaction_events.max_samples_stored", 1200, 1200), + TSetting("event_harvest_config.harvest_limits.analytic_event_data", 9999, 1200), ), ( - TSetting("event_harvest_config.harvest_limits.analytic_event_data", 1200, 1200), TSetting("transaction_events.max_samples_stored", 9999, 1200), + TSetting("event_harvest_config.harvest_limits.analytic_event_data", 1200, 1200), ), ( - TSetting("event_harvest_config.harvest_limits.analytic_event_data", 9999, 1200), - TSetting("transaction_events.max_samples_stored", 1200, 1200), + TSetting("span_events.max_samples_stored", 1000, 2000), + TSetting("event_harvest_config.harvest_limits.span_event_data", 9999, 2000), ), ( - TSetting("event_harvest_config.harvest_limits.span_event_data", 1000, 2000), TSetting("span_events.max_samples_stored", 9999, 2000), + TSetting("event_harvest_config.harvest_limits.span_event_data", 1000, 2000), ), ( - TSetting("event_harvest_config.harvest_limits.span_event_data", 9999, 2000), - TSetting("span_events.max_samples_stored", 1000, 2000), + TSetting("error_collector.max_event_samples_stored", 100, 100), + TSetting("event_harvest_config.harvest_limits.error_event_data", 9999, 100), ), ( - TSetting("event_harvest_config.harvest_limits.error_event_data", 100, 100), TSetting("error_collector.max_event_samples_stored", 9999, 100), + TSetting("event_harvest_config.harvest_limits.error_event_data", 100, 100), ), ( - TSetting("event_harvest_config.harvest_limits.error_event_data", 9999, 100), - TSetting("error_collector.max_event_samples_stored", 100, 100), + TSetting("custom_insights_events.max_samples_stored", 3600, 3600), + TSetting("event_harvest_config.harvest_limits.custom_event_data", 9999, 3600), ), ( - TSetting("event_harvest_config.harvest_limits.custom_event_data", 3600, 3600), TSetting("custom_insights_events.max_samples_stored", 9999, 3600), + TSetting("event_harvest_config.harvest_limits.custom_event_data", 3600, 3600), ), ( - TSetting("event_harvest_config.harvest_limits.custom_event_data", 9999, 3600), - TSetting("custom_insights_events.max_samples_stored", 3600, 3600), + TSetting("application_logging.forwarding.max_samples_stored", 10000, 10000), + TSetting("event_harvest_config.harvest_limits.log_event_data", 99999, 10000), ), ( - TSetting("event_harvest_config.harvest_limits.log_event_data", 10000, 10000), TSetting("application_logging.forwarding.max_samples_stored", 99999, 10000), + TSetting("event_harvest_config.harvest_limits.log_event_data", 10000, 10000), ), - ( - TSetting("event_harvest_config.harvest_limits.log_event_data", 99999, 10000), - TSetting("application_logging.forwarding.max_samples_stored", 10000, 10000), - ), ] -@pytest.mark.parametrize("old,new", translate_settings_tests) +@pytest.mark.parametrize("external,internal", translate_event_harvest_settings_tests) +def test_translate_event_harvest_setting_without_new_setting(external, internal): + # From the user's end, the *.max_samples_stored naming convention + # is the desired setting name, but since the collector still uses the + # event_harvest_config.harvest_limits.* naming convention, those will be + # what is actually stored in the settings object. + # + # Before: max_samples_stored setting will be in settings object. + # event_harvest_config.harvest_limits.* settings will + # *NOT* be in settings object. + # + # After: max_samples_stored setting will *NOT* be in settings object. + # event_harvest_config.harvest_limits.* settings will be in + # settings object with value given by max_samples_stored + + settings = apply_server_side_settings() + apply_config_setting(settings, external.name, external.value) + + assert fetch_config_setting(settings, external.name) == external.value + assert fetch_config_setting(settings, internal.name) == internal.default + + cached = [(external.name, external.value)] + result = translate_event_harvest_config_settings(settings, cached) + + assert result is settings + assert external.name not in flatten_settings(result) + assert fetch_config_setting(result, internal.name) == external.value + + +@pytest.mark.parametrize("external,internal", translate_event_harvest_settings_tests) +def test_translate_event_harvest_setting_with_new_setting(external, internal): + # NOTE: This is the same behavior for whether the old setting is present or not + # From the user's end, the *.max_samples_stored naming convention + # is the desired setting name, but since the collector still uses the + # event_harvest_config.harvest_limits.* naming convention, those will be + # what is actually stored in the settings object. + # + # Before: max_samples_stored setting will be in settings object. + # event_harvest_config.harvest_limits.* settings will + # also be in settings object. + # + # After: max_samples_stored setting will *NOT* be in settings object. + # event_harvest_config.harvest_limits.* settings will be in + # settings object with value given by max_samples_stored + + settings = apply_server_side_settings() + apply_config_setting(settings, external.name, external.value) + apply_config_setting(settings, internal.name, internal.value) + + assert fetch_config_setting(settings, external.name) == external.value + assert fetch_config_setting(settings, internal.name) == internal.value + + cached = [(external.name, external.value), (internal.name, internal.value)] + result = translate_event_harvest_config_settings(settings, cached) + + assert result is settings + assert external.name not in flatten_settings(result) + assert fetch_config_setting(result, internal.name) == external.value + + +translate_deprecated_settings_tests = [ + # Nothing in here right now. +] + + +@pytest.mark.skip("Renable this test once there are other deprecated settings.") +@pytest.mark.parametrize("old,new", translate_deprecated_settings_tests) def test_translate_deprecated_setting_without_new_setting(old, new): # Before: deprecated setting will be in settings object. # new setting will be in settings object and have default value @@ -520,7 +537,8 @@ def test_translate_deprecated_setting_without_new_setting(old, new): assert fetch_config_setting(result, new.name) == old.value -@pytest.mark.parametrize("old,new", translate_settings_tests) +@pytest.mark.skip("Renable this test once there are other deprecated settings.") +@pytest.mark.parametrize("old,new", translate_deprecated_settings_tests) def test_translate_deprecated_setting_with_new_setting(old, new): # Before: deprecated setting will be in settings object. # new setting will be in settings object and have its value @@ -543,7 +561,8 @@ def test_translate_deprecated_setting_with_new_setting(old, new): assert fetch_config_setting(result, new.name) == new.value -@pytest.mark.parametrize("old,new", translate_settings_tests) +@pytest.mark.skip("Renable this test once there are other deprecated settings.") +@pytest.mark.parametrize("old,new", translate_deprecated_settings_tests) def test_translate_deprecated_setting_without_old_setting(old, new): # Before: deprecated setting will *NOT* be in settings object. # new setting will be in settings object and have its value diff --git a/tests/agent_features/test_notice_error.py b/tests/agent_features/test_notice_error.py index 5744dcc61a..e698dee7be 100644 --- a/tests/agent_features/test_notice_error.py +++ b/tests/agent_features/test_notice_error.py @@ -396,7 +396,7 @@ def test_application_error_trace_limit(): @override_application_settings( { "agent_limits.errors_per_transaction": _errors_per_transaction_limit, - "error_collector.max_event_samples_stored": _error_event_limit, + "event_harvest_config.harvest_limits.error_event_data": _error_event_limit, } ) @validate_transaction_error_event_count(_errors_per_transaction_limit) @@ -411,7 +411,7 @@ def test_transaction_error_event_limit(): @override_application_settings( { "agent_limits.errors_per_harvest": _errors_per_harvest_limit, - "error_collector.max_event_samples_stored": _error_event_limit, + "event_harvest_config.harvest_limits.error_event_data": _error_event_limit, } ) @reset_core_stats_engine() diff --git a/tests/agent_features/test_priority_sampling.py b/tests/agent_features/test_priority_sampling.py index ceb81564b4..6ef697c12c 100644 --- a/tests/agent_features/test_priority_sampling.py +++ b/tests/agent_features/test_priority_sampling.py @@ -24,7 +24,7 @@ from newrelic.api.background_task import BackgroundTask -@override_application_settings({"transaction_events.max_samples_stored": 1}) +@override_application_settings({"event_harvest_config.harvest_limits.analytic_event_data": 1}) @pytest.mark.parametrize("first_transaction_saved", [True, False]) def test_priority_used_in_transaction_events(first_transaction_saved): first_priority = 1 if first_transaction_saved else 0 @@ -57,7 +57,7 @@ def _test(): _test() -@override_application_settings({"error_collector.max_event_samples_stored": 1}) +@override_application_settings({"event_harvest_config.harvest_limits.error_event_data": 1}) @pytest.mark.parametrize("first_transaction_saved", [True, False]) def test_priority_used_in_transaction_error_events(first_transaction_saved): first_priority = 1 if first_transaction_saved else 0 @@ -97,7 +97,7 @@ def _test(): _test() -@override_application_settings({"custom_insights_events.max_samples_stored": 1}) +@override_application_settings({"event_harvest_config.harvest_limits.custom_event_data": 1}) @pytest.mark.parametrize("first_transaction_saved", [True, False]) def test_priority_used_in_transaction_custom_events(first_transaction_saved): first_priority = 1 if first_transaction_saved else 0 diff --git a/tests/agent_unittests/test_connect_response_fields.py b/tests/agent_unittests/test_connect_response_fields.py index 9d6a423773..eefd785e22 100644 --- a/tests/agent_unittests/test_connect_response_fields.py +++ b/tests/agent_unittests/test_connect_response_fields.py @@ -106,6 +106,8 @@ def test_blob(): assert headers == {"Content-Type": "application/json", "X-Foo": "Bar"} +# This test tests the precedence order of agent server side +# config settings and global server side config settings @override_generic_settings(global_settings(), {"developer_mode": True}) def test_server_side_config_precedence(): connect_response_fields = {"agent_config": {"span_events.enabled": True}, "span_events.enabled": False} @@ -140,7 +142,8 @@ def test_span_event_harvest_config(connect_response_fields): from newrelic.core.config import SPAN_EVENT_RESERVOIR_SIZE expected = SPAN_EVENT_RESERVOIR_SIZE - assert protocol.configuration.span_events.max_samples_stored == expected + + assert protocol.configuration.event_harvest_config.harvest_limits.span_event_data == expected @override_generic_settings(global_settings(), {"developer_mode": True}) diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index b9c1ea25b8..9717e956ba 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -349,7 +349,8 @@ def test_application_harvest_with_spans(distributed_tracing_enabled, span_events "license_key": "**NOT A LICENSE KEY**", "distributed_tracing.enabled": distributed_tracing_enabled, "span_events.enabled": span_events_enabled, - "span_events.max_samples_stored": max_samples_stored, + # Uses the name from post-translation as this is modifying the settings object, not a config file + "event_harvest_config.harvest_limits.span_event_data": max_samples_stored, }, ) def _test(): @@ -514,10 +515,10 @@ def test_adaptive_sampling(transaction_node, monkeypatch): "feature_flag": set(), "distributed_tracing.enabled": True, "application_logging.forwarding.enabled": True, - "error_collector.max_event_samples_stored": 1000, - "span_events.max_samples_stored": 1000, - "custom_insights_events.max_samples_stored": 1000, - "application_logging.forwarding.max_samples_stored": 1000, + "event_harvest_config.harvest_limits.error_event_data": 1000, + "event_harvest_config.harvest_limits.span_event_data": 1000, + "event_harvest_config.harvest_limits.custom_event_data": 1000, + "event_harvest_config.harvest_limits.log_event_data": 1000, }, ) def test_reservoir_sizes(transaction_node): @@ -539,11 +540,11 @@ def test_reservoir_sizes(transaction_node): @pytest.mark.parametrize( "harvest_setting,event_name", [ - ("transaction_events.max_samples_stored", "transaction_events"), - ("error_collector.max_event_samples_stored", "error_events"), - ("custom_insights_events.max_samples_stored", "custom_events"), - ("application_logging.forwarding.max_samples_stored", "log_events"), - ("span_events.max_samples_stored", "span_events"), + ("event_harvest_config.harvest_limits.analytic_event_data", "transaction_events"), + ("event_harvest_config.harvest_limits.error_event_data", "error_events"), + ("event_harvest_config.harvest_limits.custom_event_data", "custom_events"), + ("event_harvest_config.harvest_limits.log_event_data", "log_events"), + ("event_harvest_config.harvest_limits.span_event_data", "span_events"), ], ) @override_generic_settings( @@ -614,7 +615,7 @@ def test_error_event_sampling_info(events_seen): { "developer_mode": True, "license_key": "**NOT A LICENSE KEY**", - "error_collector.max_event_samples_stored": reservoir_size, + "event_harvest_config.harvest_limits.error_event_data": reservoir_size, }, ) def _test(): @@ -683,7 +684,7 @@ def transactions_validator(payload): settings, { "developer_mode": True, - "transaction_events.max_samples_stored": transactions_limit, + "event_harvest_config.harvest_limits.analytic_event_data": transactions_limit, "agent_limits.synthetics_events": synthetics_limit, }, ) diff --git a/tests/testing_support/validators/validate_custom_event_collector_json.py b/tests/testing_support/validators/validate_custom_event_collector_json.py index 5efe5cef3c..0a7afb84db 100644 --- a/tests/testing_support/validators/validate_custom_event_collector_json.py +++ b/tests/testing_support/validators/validate_custom_event_collector_json.py @@ -49,7 +49,7 @@ def _validate_custom_event_collector_json(wrapped, instance, args, kwargs): assert decoded_agent_run_id == agent_run_id assert decoded_sampling_info == sampling_info - max_setting = settings.custom_insights_events.max_samples_stored + max_setting = settings.event_harvest_config.harvest_limits.custom_event_data assert decoded_sampling_info["reservoir_size"] == max_setting assert decoded_sampling_info["events_seen"] == num_events diff --git a/tests/testing_support/validators/validate_error_event_collector_json.py b/tests/testing_support/validators/validate_error_event_collector_json.py index 9d6f8ef44e..d1cec3a558 100644 --- a/tests/testing_support/validators/validate_error_event_collector_json.py +++ b/tests/testing_support/validators/validate_error_event_collector_json.py @@ -45,7 +45,7 @@ def _validate_error_event_collector_json(wrapped, instance, args, kwargs): sampling_info = decoded_json[1] - reservoir_size = instance.settings.error_collector.max_event_samples_stored + reservoir_size = instance.settings.event_harvest_config.harvest_limits.error_event_data assert sampling_info["reservoir_size"] == reservoir_size assert sampling_info["events_seen"] == num_errors