Skip to content

Commit 27f357c

Browse files
lrafeeimergify[bot]TimPansino
authored
Fix max_samples_stored settings to still allow server side config to override settings. (#1537)
* Remove removed settings from deprecations * Remove deprecated settings from core/config.py * Map mismatched server/client setting names for serverside override * Map out max_samples to event_harvest settings: * Modify downstream max_samples settings to point to event_harvest * Fix megalinter errors * Update newrelic/config.py Co-authored-by: Timothy Pansino <[email protected]> * Add more tests * [MegaLinter] Apply linters fixes --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Timothy Pansino <[email protected]>
1 parent 68511db commit 27f357c

File tree

12 files changed

+194
-135
lines changed

12 files changed

+194
-135
lines changed

newrelic/api/transaction.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,13 @@ def __init__(self, application, enabled=None, source=None):
333333
self.enabled = True
334334

335335
if self._settings:
336-
self._custom_events = SampledDataSet(capacity=self._settings.custom_insights_events.max_samples_stored)
336+
self._custom_events = SampledDataSet(
337+
capacity=self._settings.event_harvest_config.harvest_limits.custom_event_data
338+
)
337339
self._ml_events = SampledDataSet(capacity=self._settings.event_harvest_config.harvest_limits.ml_event_data)
338-
self._log_events = SampledDataSet(capacity=self._settings.application_logging.forwarding.max_samples_stored)
340+
self._log_events = SampledDataSet(
341+
capacity=self._settings.event_harvest_config.harvest_limits.log_event_data
342+
)
339343
else:
340344
self._custom_events = SampledDataSet(capacity=CUSTOM_EVENT_RESERVOIR_SIZE)
341345
self._log_events = SampledDataSet(capacity=LOG_EVENT_RESERVOIR_SIZE)

newrelic/config.py

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,63 @@ def delete_setting(settings_object, name):
638638
_logger.debug("Failed to delete setting: %r", name)
639639

640640

641+
def translate_event_harvest_config_settings(settings, cached_settings):
642+
"""Translate event_harvest_config settings to max_samples settings.
643+
644+
Background:
645+
The collector/server side agent configuration uses the
646+
`event_harvest_config` naming convention for their harvest
647+
limit settings. The original intent was for the language
648+
agents to switch to this convention. However, this only
649+
happened for the Python agent. Eventually, to remain
650+
consistent with the other language agents, the decision
651+
was made to change this back. However, because the server
652+
side configuration settings override the client-side settings,
653+
the agent will insist on employing the `max_samples` naming
654+
convention from the user's end but translate the settings
655+
to their deprecated `event_harvest_config` counterparts during
656+
the configuration process.
657+
658+
Here, the user will still get warnings about deprecated settings
659+
being used. However, the agent will also translate the settings
660+
to their deprecated `event_harvest_config` counterparts during
661+
the configuration process.
662+
"""
663+
664+
cached = dict(cached_settings)
665+
666+
event_harvest_to_max_samples_settings_map = [
667+
("event_harvest_config.harvest_limits.analytic_event_data", "transaction_events.max_samples_stored"),
668+
("event_harvest_config.harvest_limits.span_event_data", "span_events.max_samples_stored"),
669+
("event_harvest_config.harvest_limits.error_event_data", "error_collector.max_event_samples_stored"),
670+
("event_harvest_config.harvest_limits.custom_event_data", "custom_insights_events.max_samples_stored"),
671+
("event_harvest_config.harvest_limits.log_event_data", "application_logging.forwarding.max_samples_stored"),
672+
]
673+
674+
for event_harvest_key, max_samples_key in event_harvest_to_max_samples_settings_map:
675+
if event_harvest_key in cached:
676+
_logger.info(
677+
"Deprecated setting found: %r. Please use new setting: %r.", event_harvest_key, max_samples_key
678+
)
679+
680+
if max_samples_key in cached:
681+
# Since there is the max_samples key as well as the event_harvest key,
682+
# we need to apply the max_samples value to the event_harvest key.
683+
apply_config_setting(settings, event_harvest_key, cached[max_samples_key])
684+
_logger.info(
685+
"Ignoring deprecated setting: %r. Using new setting: %r.", event_harvest_key, max_samples_key
686+
)
687+
else:
688+
# Translation to event_harvest_config has already happened
689+
_logger.info("Applying value of deprecated setting %r to %r.", event_harvest_key, max_samples_key)
690+
elif max_samples_key in cached:
691+
apply_config_setting(settings, event_harvest_key, cached[max_samples_key])
692+
693+
delete_setting(settings, max_samples_key)
694+
695+
return settings
696+
697+
641698
def translate_deprecated_settings(settings, cached_settings):
642699
# If deprecated setting has been set by user, but the new
643700
# setting has not, then translate the deprecated setting to the
@@ -669,19 +726,7 @@ def translate_deprecated_settings(settings, cached_settings):
669726
cached = dict(cached_settings)
670727

671728
deprecated_settings_map = [
672-
("transaction_tracer.capture_attributes", "transaction_tracer.attributes.enabled"),
673-
("error_collector.capture_attributes", "error_collector.attributes.enabled"),
674-
("browser_monitoring.capture_attributes", "browser_monitoring.attributes.enabled"),
675-
("analytics_events.capture_attributes", "transaction_events.attributes.enabled"),
676-
("analytics_events.enabled", "transaction_events.enabled"),
677-
("analytics_events.max_samples_stored", "transaction_events.max_samples_stored"),
678-
("event_harvest_config.harvest_limits.analytic_event_data", "transaction_events.max_samples_stored"),
679-
("event_harvest_config.harvest_limits.span_event_data", "span_events.max_samples_stored"),
680-
("event_harvest_config.harvest_limits.error_event_data", "error_collector.max_event_samples_stored"),
681-
("event_harvest_config.harvest_limits.custom_event_data", "custom_insights_events.max_samples_stored"),
682-
("event_harvest_config.harvest_limits.log_event_data", "application_logging.forwarding.max_samples_stored"),
683-
("error_collector.ignore_errors", "error_collector.ignore_classes"),
684-
("strip_exception_messages.whitelist", "strip_exception_messages.allowlist"),
729+
# Nothing in here right now!
685730
]
686731

687732
for old_key, new_key in deprecated_settings_map:
@@ -979,6 +1024,10 @@ def _load_configuration(config_file=None, environment=None, ignore_errors=True,
9791024

9801025
translate_deprecated_settings(_settings, _cache_object)
9811026

1027+
# Translate event_harvest_config settings to max_samples settings (from user's side)
1028+
1029+
translate_event_harvest_config_settings(_settings, _cache_object)
1030+
9821031
# Apply High Security Mode policy if enabled in local agent
9831032
# configuration file.
9841033

newrelic/core/config.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -819,15 +819,15 @@ def default_otlp_host(host):
819819
)
820820

821821
_settings.transaction_events.enabled = True
822-
_settings.transaction_events.max_samples_stored = _environ_as_int(
822+
_settings.event_harvest_config.harvest_limits.analytic_event_data = _environ_as_int(
823823
"NEW_RELIC_ANALYTICS_EVENTS_MAX_SAMPLES_STORED", default=DEFAULT_RESERVOIR_SIZE
824824
)
825825
_settings.transaction_events.attributes.enabled = True
826826
_settings.transaction_events.attributes.exclude = []
827827
_settings.transaction_events.attributes.include = []
828828

829829
_settings.custom_insights_events.enabled = True
830-
_settings.custom_insights_events.max_samples_stored = _environ_as_int(
830+
_settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int(
831831
"NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", default=CUSTOM_EVENT_RESERVOIR_SIZE
832832
)
833833
_settings.custom_insights_events.max_attribute_value = _environ_as_int(
@@ -845,7 +845,7 @@ def default_otlp_host(host):
845845
)
846846
_settings.distributed_tracing.exclude_newrelic_header = False
847847
_settings.span_events.enabled = _environ_as_bool("NEW_RELIC_SPAN_EVENTS_ENABLED", default=True)
848-
_settings.span_events.max_samples_stored = _environ_as_int(
848+
_settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int(
849849
"NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED", default=SPAN_EVENT_RESERVOIR_SIZE
850850
)
851851
_settings.span_events.attributes.enabled = True
@@ -875,7 +875,7 @@ def default_otlp_host(host):
875875
_settings.error_collector.ignore_classes = []
876876
_settings.error_collector.ignore_status_codes = _parse_status_codes("100-102 200-208 226 300-308 404", set())
877877
_settings.error_collector.expected_classes = []
878-
_settings.error_collector.max_event_samples_stored = _environ_as_int(
878+
_settings.event_harvest_config.harvest_limits.error_event_data = _environ_as_int(
879879
"NEW_RELIC_ERROR_COLLECTOR_MAX_EVENT_SAMPLES_STORED", default=ERROR_EVENT_RESERVOIR_SIZE
880880
)
881881
_settings.error_collector.expected_status_codes = set()
@@ -944,30 +944,10 @@ def default_otlp_host(host):
944944
_settings.instrumentation.middleware.django.exclude = []
945945
_settings.instrumentation.middleware.django.include = []
946946

947-
_settings.event_harvest_config.harvest_limits.analytic_event_data = _environ_as_int(
948-
"NEW_RELIC_ANALYTICS_EVENTS_MAX_SAMPLES_STORED", DEFAULT_RESERVOIR_SIZE
949-
)
950-
951-
_settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int(
952-
"NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", CUSTOM_EVENT_RESERVOIR_SIZE
953-
)
954-
955947
_settings.event_harvest_config.harvest_limits.ml_event_data = _environ_as_int(
956948
"NEW_RELIC_ML_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", ML_EVENT_RESERVOIR_SIZE
957949
)
958950

959-
_settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int(
960-
"NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED", SPAN_EVENT_RESERVOIR_SIZE
961-
)
962-
963-
_settings.event_harvest_config.harvest_limits.error_event_data = _environ_as_int(
964-
"NEW_RELIC_ERROR_COLLECTOR_MAX_EVENT_SAMPLES_STORED", ERROR_EVENT_RESERVOIR_SIZE
965-
)
966-
967-
_settings.event_harvest_config.harvest_limits.log_event_data = _environ_as_int(
968-
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED", LOG_EVENT_RESERVOIR_SIZE
969-
)
970-
971951
_settings.console.listener_socket = None
972952
_settings.console.allow_interpreter_cmd = False
973953

@@ -1034,7 +1014,7 @@ def default_otlp_host(host):
10341014
_settings.application_logging.forwarding.custom_attributes = _environ_as_mapping(
10351015
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CUSTOM_ATTRIBUTES", default=""
10361016
)
1037-
_settings.application_logging.forwarding.max_samples_stored = _environ_as_int(
1017+
_settings.event_harvest_config.harvest_limits.log_event_data = _environ_as_int(
10381018
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED", default=LOG_EVENT_RESERVOIR_SIZE
10391019
)
10401020

@@ -1322,7 +1302,9 @@ def apply_server_side_settings(server_side_config=None, settings=_settings):
13221302
span_event_harvest_config = server_side_config.get("span_event_harvest_config", {})
13231303
span_event_harvest_limit = span_event_harvest_config.get("harvest_limit", None)
13241304
if span_event_harvest_limit is not None:
1325-
apply_config_setting(settings_snapshot, "span_events.max_samples_stored", span_event_harvest_limit)
1305+
apply_config_setting(
1306+
settings_snapshot, "event_harvest_config.harvest_limits.span_event_data", span_event_harvest_limit
1307+
)
13261308

13271309
# Check to see if collect_ai appears in the connect response to handle account-level AIM toggling
13281310
collect_ai = server_side_config.get("collect_ai", None)

newrelic/core/stats_engine.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,19 +1704,21 @@ def reset_transaction_events(self):
17041704
"""
17051705

17061706
if self.__settings is not None:
1707-
self._transaction_events = SampledDataSet(self.__settings.transaction_events.max_samples_stored)
1707+
self._transaction_events = SampledDataSet(
1708+
self.__settings.event_harvest_config.harvest_limits.analytic_event_data
1709+
)
17081710
else:
17091711
self._transaction_events = SampledDataSet()
17101712

17111713
def reset_error_events(self):
17121714
if self.__settings is not None:
1713-
self._error_events = SampledDataSet(self.__settings.error_collector.max_event_samples_stored)
1715+
self._error_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.error_event_data)
17141716
else:
17151717
self._error_events = SampledDataSet()
17161718

17171719
def reset_custom_events(self):
17181720
if self.__settings is not None:
1719-
self._custom_events = SampledDataSet(self.__settings.custom_insights_events.max_samples_stored)
1721+
self._custom_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.custom_event_data)
17201722
else:
17211723
self._custom_events = SampledDataSet()
17221724

@@ -1728,13 +1730,13 @@ def reset_ml_events(self):
17281730

17291731
def reset_span_events(self):
17301732
if self.__settings is not None:
1731-
self._span_events = SampledDataSet(self.__settings.span_events.max_samples_stored)
1733+
self._span_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.span_event_data)
17321734
else:
17331735
self._span_events = SampledDataSet()
17341736

17351737
def reset_log_events(self):
17361738
if self.__settings is not None:
1737-
self._log_events = SampledDataSet(self.__settings.application_logging.forwarding.max_samples_stored)
1739+
self._log_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.log_event_data)
17381740
else:
17391741
self._log_events = SampledDataSet()
17401742

tests/agent_features/test_collector_payloads.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import pytest
1615
import webtest
1716
from testing_support.fixtures import override_application_settings
1817
from testing_support.sample_applications import simple_app, simple_custom_event_app, simple_exceptional_app

0 commit comments

Comments
 (0)