From 6ef9bce98c116526eb4dd38f66c2328d30979b79 Mon Sep 17 00:00:00 2001 From: Timothy Pansino <11214426+TimPansino@users.noreply.github.com> Date: Thu, 1 Sep 2022 14:33:00 -0700 Subject: [PATCH] Custom Event Limit Increase (#591) * Update reservoir size for custom events. * [Mega-Linter] Apply linters fixes Co-authored-by: TimPansino --- newrelic/api/transaction.py | 38 ++++++++++++++-------- newrelic/core/config.py | 3 +- tests/agent_features/test_configuration.py | 8 ++--- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index f486989b4b..c963e73920 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -25,13 +25,12 @@ import weakref from collections import OrderedDict -from newrelic.api.application import application_instance import newrelic.core.database_node import newrelic.core.error_node -from newrelic.core.log_event_node import LogEventNode import newrelic.core.root_node import newrelic.core.transaction_node import newrelic.packages.six as six +from newrelic.api.application import application_instance from newrelic.api.time_trace import TimeTrace, get_linking_metadata from newrelic.common.encoding_utils import ( DistributedTracePayload, @@ -61,8 +60,9 @@ DST_NONE, DST_TRANSACTION_TRACER, ) -from newrelic.core.config import DEFAULT_RESERVOIR_SIZE, LOG_EVENT_RESERVOIR_SIZE +from newrelic.core.config import CUSTOM_EVENT_RESERVOIR_SIZE, LOG_EVENT_RESERVOIR_SIZE from newrelic.core.custom_event import create_custom_event +from newrelic.core.log_event_node import LogEventNode from newrelic.core.stack_trace import exception_stack from newrelic.core.stats_engine import CustomMetrics, SampledDataSet from newrelic.core.thread_utilization import utilization_tracker @@ -324,10 +324,14 @@ def __init__(self, application, enabled=None, source=None): self.enabled = True if self._settings: - self._custom_events = SampledDataSet(capacity=self._settings.event_harvest_config.harvest_limits.custom_event_data) - self._log_events = SampledDataSet(capacity=self._settings.event_harvest_config.harvest_limits.log_event_data) + self._custom_events = SampledDataSet( + capacity=self._settings.event_harvest_config.harvest_limits.custom_event_data + ) + self._log_events = SampledDataSet( + capacity=self._settings.event_harvest_config.harvest_limits.log_event_data + ) else: - self._custom_events = SampledDataSet(capacity=DEFAULT_RESERVOIR_SIZE) + self._custom_events = SampledDataSet(capacity=CUSTOM_EVENT_RESERVOIR_SIZE) self._log_events = SampledDataSet(capacity=LOG_EVENT_RESERVOIR_SIZE) def __del__(self): @@ -1473,31 +1477,35 @@ def set_transaction_name(self, name, group=None, priority=None): self._group = group self._name = name - def record_log_event(self, message, level=None, timestamp=None, priority=None): settings = self.settings - if not (settings and settings.application_logging and settings.application_logging.enabled and settings.application_logging.forwarding and settings.application_logging.forwarding.enabled): + if not ( + settings + and settings.application_logging + and settings.application_logging.enabled + and settings.application_logging.forwarding + and settings.application_logging.forwarding.enabled + ): return - + timestamp = timestamp if timestamp is not None else time.time() level = str(level) if level is not None else "UNKNOWN" - + if not message or message.isspace(): _logger.debug("record_log_event called where message was missing. No log event will be sent.") return - + message = truncate(message, MAX_LOG_MESSAGE_LENGTH) event = LogEventNode( timestamp=timestamp, level=level, message=message, - attributes=get_linking_metadata(), + attributes=get_linking_metadata(), ) self._log_events.add(event, priority=priority) - def record_exception(self, exc=None, value=None, tb=None, params=None, ignore_errors=None): # Deprecation Warning warnings.warn( @@ -1869,7 +1877,9 @@ def record_log_event(message, level=None, timestamp=None, application=None, prio "record_log_event has been called but no transaction or application was running. As a result, " "the following event has not been recorded. message: %r level: %r timestamp %r. To correct " "this problem, supply an application object as a parameter to this record_log_event call.", - message, level, timestamp, + message, + level, + timestamp, ) elif application.enabled: application.record_log_event(message, level, timestamp, priority=priority) diff --git a/newrelic/core/config.py b/newrelic/core/config.py index 60520c1134..2e4db97c70 100644 --- a/newrelic/core/config.py +++ b/newrelic/core/config.py @@ -52,6 +52,7 @@ # reservoir. Error Events have a different default size. DEFAULT_RESERVOIR_SIZE = 1200 +CUSTOM_EVENT_RESERVOIR_SIZE = 30000 ERROR_EVENT_RESERVOIR_SIZE = 100 SPAN_EVENT_RESERVOIR_SIZE = 2000 LOG_EVENT_RESERVOIR_SIZE = 10000 @@ -738,7 +739,7 @@ def default_host(license_key): ) _settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int( - "NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", DEFAULT_RESERVOIR_SIZE + "NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", CUSTOM_EVENT_RESERVOIR_SIZE ) _settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int( diff --git a/tests/agent_features/test_configuration.py b/tests/agent_features/test_configuration.py index 5846e38080..0b5203ad85 100644 --- a/tests/agent_features/test_configuration.py +++ b/tests/agent_features/test_configuration.py @@ -438,12 +438,12 @@ def test_delete_setting_parent(): TSetting("event_harvest_config.harvest_limits.error_event_data", 100, 100), ), ( - TSetting("custom_insights_events.max_samples_stored", 1200, 1200), - TSetting("event_harvest_config.harvest_limits.custom_event_data", 9999, 1200), + TSetting("custom_insights_events.max_samples_stored", 30000, 30000), + TSetting("event_harvest_config.harvest_limits.custom_event_data", 9999, 30000), ), ( - TSetting("custom_insights_events.max_samples_stored", 9999, 1200), - TSetting("event_harvest_config.harvest_limits.custom_event_data", 1200, 1200), + TSetting("custom_insights_events.max_samples_stored", 9999, 30000), + TSetting("event_harvest_config.harvest_limits.custom_event_data", 30000, 30000), ), ( TSetting("application_logging.forwarding.max_samples_stored", 10000, 10000),