Skip to content

Commit 831fa32

Browse files
authored
Merge branch 'main' into partial-granularity-type-support
2 parents 1d913fb + 27f357c commit 831fa32

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
@@ -645,6 +645,63 @@ def delete_setting(settings_object, name):
645645
_logger.debug("Failed to delete setting: %r", name)
646646

647647

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

678735
deprecated_settings_map = [
679-
("transaction_tracer.capture_attributes", "transaction_tracer.attributes.enabled"),
680-
("error_collector.capture_attributes", "error_collector.attributes.enabled"),
681-
("browser_monitoring.capture_attributes", "browser_monitoring.attributes.enabled"),
682-
("analytics_events.capture_attributes", "transaction_events.attributes.enabled"),
683-
("analytics_events.enabled", "transaction_events.enabled"),
684-
("analytics_events.max_samples_stored", "transaction_events.max_samples_stored"),
685-
("event_harvest_config.harvest_limits.analytic_event_data", "transaction_events.max_samples_stored"),
686-
("event_harvest_config.harvest_limits.span_event_data", "span_events.max_samples_stored"),
687-
("event_harvest_config.harvest_limits.error_event_data", "error_collector.max_event_samples_stored"),
688-
("event_harvest_config.harvest_limits.custom_event_data", "custom_insights_events.max_samples_stored"),
689-
("event_harvest_config.harvest_limits.log_event_data", "application_logging.forwarding.max_samples_stored"),
690-
("error_collector.ignore_errors", "error_collector.ignore_classes"),
691-
("strip_exception_messages.whitelist", "strip_exception_messages.allowlist"),
736+
# Nothing in here right now!
692737
]
693738

694739
for old_key, new_key in deprecated_settings_map:
@@ -986,6 +1031,10 @@ def _load_configuration(config_file=None, environment=None, ignore_errors=True,
9861031

9871032
translate_deprecated_settings(_settings, _cache_object)
9881033

1034+
# Translate event_harvest_config settings to max_samples settings (from user's side)
1035+
1036+
translate_event_harvest_config_settings(_settings, _cache_object)
1037+
9891038
# Apply High Security Mode policy if enabled in local agent
9901039
# configuration file.
9911040

newrelic/core/config.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -827,15 +827,15 @@ def default_otlp_host(host):
827827
)
828828

829829
_settings.transaction_events.enabled = True
830-
_settings.transaction_events.max_samples_stored = _environ_as_int(
830+
_settings.event_harvest_config.harvest_limits.analytic_event_data = _environ_as_int(
831831
"NEW_RELIC_ANALYTICS_EVENTS_MAX_SAMPLES_STORED", default=DEFAULT_RESERVOIR_SIZE
832832
)
833833
_settings.transaction_events.attributes.enabled = True
834834
_settings.transaction_events.attributes.exclude = []
835835
_settings.transaction_events.attributes.include = []
836836

837837
_settings.custom_insights_events.enabled = True
838-
_settings.custom_insights_events.max_samples_stored = _environ_as_int(
838+
_settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int(
839839
"NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", default=CUSTOM_EVENT_RESERVOIR_SIZE
840840
)
841841
_settings.custom_insights_events.max_attribute_value = _environ_as_int(
@@ -863,7 +863,7 @@ def default_otlp_host(host):
863863
)
864864
_settings.distributed_tracing.exclude_newrelic_header = False
865865
_settings.span_events.enabled = _environ_as_bool("NEW_RELIC_SPAN_EVENTS_ENABLED", default=True)
866-
_settings.span_events.max_samples_stored = _environ_as_int(
866+
_settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int(
867867
"NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED", default=SPAN_EVENT_RESERVOIR_SIZE
868868
)
869869
_settings.span_events.attributes.enabled = True
@@ -893,7 +893,7 @@ def default_otlp_host(host):
893893
_settings.error_collector.ignore_classes = []
894894
_settings.error_collector.ignore_status_codes = _parse_status_codes("100-102 200-208 226 300-308 404", set())
895895
_settings.error_collector.expected_classes = []
896-
_settings.error_collector.max_event_samples_stored = _environ_as_int(
896+
_settings.event_harvest_config.harvest_limits.error_event_data = _environ_as_int(
897897
"NEW_RELIC_ERROR_COLLECTOR_MAX_EVENT_SAMPLES_STORED", default=ERROR_EVENT_RESERVOIR_SIZE
898898
)
899899
_settings.error_collector.expected_status_codes = set()
@@ -962,30 +962,10 @@ def default_otlp_host(host):
962962
_settings.instrumentation.middleware.django.exclude = []
963963
_settings.instrumentation.middleware.django.include = []
964964

965-
_settings.event_harvest_config.harvest_limits.analytic_event_data = _environ_as_int(
966-
"NEW_RELIC_ANALYTICS_EVENTS_MAX_SAMPLES_STORED", DEFAULT_RESERVOIR_SIZE
967-
)
968-
969-
_settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int(
970-
"NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", CUSTOM_EVENT_RESERVOIR_SIZE
971-
)
972-
973965
_settings.event_harvest_config.harvest_limits.ml_event_data = _environ_as_int(
974966
"NEW_RELIC_ML_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", ML_EVENT_RESERVOIR_SIZE
975967
)
976968

977-
_settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int(
978-
"NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED", SPAN_EVENT_RESERVOIR_SIZE
979-
)
980-
981-
_settings.event_harvest_config.harvest_limits.error_event_data = _environ_as_int(
982-
"NEW_RELIC_ERROR_COLLECTOR_MAX_EVENT_SAMPLES_STORED", ERROR_EVENT_RESERVOIR_SIZE
983-
)
984-
985-
_settings.event_harvest_config.harvest_limits.log_event_data = _environ_as_int(
986-
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED", LOG_EVENT_RESERVOIR_SIZE
987-
)
988-
989969
_settings.console.listener_socket = None
990970
_settings.console.allow_interpreter_cmd = False
991971

@@ -1052,7 +1032,7 @@ def default_otlp_host(host):
10521032
_settings.application_logging.forwarding.custom_attributes = _environ_as_mapping(
10531033
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CUSTOM_ATTRIBUTES", default=""
10541034
)
1055-
_settings.application_logging.forwarding.max_samples_stored = _environ_as_int(
1035+
_settings.event_harvest_config.harvest_limits.log_event_data = _environ_as_int(
10561036
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED", default=LOG_EVENT_RESERVOIR_SIZE
10571037
)
10581038

@@ -1340,7 +1320,9 @@ def apply_server_side_settings(server_side_config=None, settings=_settings):
13401320
span_event_harvest_config = server_side_config.get("span_event_harvest_config", {})
13411321
span_event_harvest_limit = span_event_harvest_config.get("harvest_limit", None)
13421322
if span_event_harvest_limit is not None:
1343-
apply_config_setting(settings_snapshot, "span_events.max_samples_stored", span_event_harvest_limit)
1323+
apply_config_setting(
1324+
settings_snapshot, "event_harvest_config.harvest_limits.span_event_data", span_event_harvest_limit
1325+
)
13441326

13451327
# Check to see if collect_ai appears in the connect response to handle account-level AIM toggling
13461328
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)