Skip to content

Commit dc527a6

Browse files
authored
Merge branch 'main' into feat-agent-api-benchmarks
2 parents d02b927 + 27f357c commit dc527a6

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
@@ -818,15 +818,15 @@ def default_otlp_host(host):
818818
)
819819

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

828828
_settings.custom_insights_events.enabled = True
829-
_settings.custom_insights_events.max_samples_stored = _environ_as_int(
829+
_settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int(
830830
"NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", default=CUSTOM_EVENT_RESERVOIR_SIZE
831831
)
832832
_settings.custom_insights_events.max_attribute_value = _environ_as_int(
@@ -844,7 +844,7 @@ def default_otlp_host(host):
844844
)
845845
_settings.distributed_tracing.exclude_newrelic_header = False
846846
_settings.span_events.enabled = _environ_as_bool("NEW_RELIC_SPAN_EVENTS_ENABLED", default=True)
847-
_settings.span_events.max_samples_stored = _environ_as_int(
847+
_settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int(
848848
"NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED", default=SPAN_EVENT_RESERVOIR_SIZE
849849
)
850850
_settings.span_events.attributes.enabled = True
@@ -874,7 +874,7 @@ def default_otlp_host(host):
874874
_settings.error_collector.ignore_classes = []
875875
_settings.error_collector.ignore_status_codes = _parse_status_codes("100-102 200-208 226 300-308 404", set())
876876
_settings.error_collector.expected_classes = []
877-
_settings.error_collector.max_event_samples_stored = _environ_as_int(
877+
_settings.event_harvest_config.harvest_limits.error_event_data = _environ_as_int(
878878
"NEW_RELIC_ERROR_COLLECTOR_MAX_EVENT_SAMPLES_STORED", default=ERROR_EVENT_RESERVOIR_SIZE
879879
)
880880
_settings.error_collector.expected_status_codes = set()
@@ -943,30 +943,10 @@ def default_otlp_host(host):
943943
_settings.instrumentation.middleware.django.exclude = []
944944
_settings.instrumentation.middleware.django.include = []
945945

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

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

@@ -1033,7 +1013,7 @@ def default_otlp_host(host):
10331013
_settings.application_logging.forwarding.custom_attributes = _environ_as_mapping(
10341014
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CUSTOM_ATTRIBUTES", default=""
10351015
)
1036-
_settings.application_logging.forwarding.max_samples_stored = _environ_as_int(
1016+
_settings.event_harvest_config.harvest_limits.log_event_data = _environ_as_int(
10371017
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED", default=LOG_EVENT_RESERVOIR_SIZE
10381018
)
10391019

@@ -1321,7 +1301,9 @@ def apply_server_side_settings(server_side_config=None, settings=_settings):
13211301
span_event_harvest_config = server_side_config.get("span_event_harvest_config", {})
13221302
span_event_harvest_limit = span_event_harvest_config.get("harvest_limit", None)
13231303
if span_event_harvest_limit is not None:
1324-
apply_config_setting(settings_snapshot, "span_events.max_samples_stored", span_event_harvest_limit)
1304+
apply_config_setting(
1305+
settings_snapshot, "event_harvest_config.harvest_limits.span_event_data", span_event_harvest_limit
1306+
)
13251307

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