From 01bd62a0613d87dc431492f4aed4566d666ad6e8 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 17 Apr 2024 16:27:08 -0700 Subject: [PATCH] Add NEW_RELIC_K8S_OPERATOR_ENABLED --- newrelic/bootstrap/sitecustomize.py | 3 ++- newrelic/config.py | 1 + newrelic/core/config.py | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/newrelic/bootstrap/sitecustomize.py b/newrelic/bootstrap/sitecustomize.py index 6640af0e99..19abbc31f4 100644 --- a/newrelic/bootstrap/sitecustomize.py +++ b/newrelic/bootstrap/sitecustomize.py @@ -121,8 +121,9 @@ def log_message(text, *args, **kwargs): log_message("python_prefix_matches = %r", python_prefix_matches) log_message("python_version_matches = %r", python_version_matches) +k8s_operator_enabled = os.environ.get("NEW_RELIC_K8S_OPERATOR_ENABLED", False) -if python_prefix_matches and python_version_matches: +if k8s_operator_enabled or (python_prefix_matches and python_version_matches): # We also need to skip agent initialisation if neither the license # key or config file environment variables are set. We do this as # some people like to use a common startup script which always uses diff --git a/newrelic/config.py b/newrelic/config.py index 730b8ed4cb..4dbcff2b56 100644 --- a/newrelic/config.py +++ b/newrelic/config.py @@ -564,6 +564,7 @@ def _process_configuration(section): _process_setting(section, "ai_monitoring.enabled", "getboolean", None) _process_setting(section, "ai_monitoring.record_content.enabled", "getboolean", None) _process_setting(section, "ai_monitoring.streaming.enabled", "getboolean", None) + _process_setting(section, "k8s_operator.enabled", "getboolean", None) _process_setting(section, "package_reporting.enabled", "getboolean", None) diff --git a/newrelic/core/config.py b/newrelic/core/config.py index 677f278aa4..3939d40e67 100644 --- a/newrelic/core/config.py +++ b/newrelic/core/config.py @@ -162,6 +162,10 @@ class AIMonitoringRecordContentSettings(Settings): pass +class K8sOperatorSettings(Settings): + pass + + class PackageReportingSettings(Settings): pass @@ -430,6 +434,7 @@ class EventHarvestConfigHarvestLimitSettings(Settings): _settings.ai_monitoring = AIMonitoringSettings() _settings.ai_monitoring.streaming = AIMonitoringStreamingSettings() _settings.ai_monitoring.record_content = AIMonitoringRecordContentSettings() +_settings.k8s_operator = K8sOperatorSettings() _settings.package_reporting = PackageReportingSettings() _settings.attributes = AttributesSettings() _settings.browser_monitoring = BrowserMonitorSettings() @@ -745,7 +750,9 @@ def default_otlp_host(host): _settings.gc_runtime_metrics.enabled = False _settings.gc_runtime_metrics.top_object_count_limit = 5 -_settings.memory_runtime_pid_metrics.enabled = _environ_as_bool("NEW_RELIC_MEMORY_RUNTIME_METRICS_ENABLED", default=True) +_settings.memory_runtime_pid_metrics.enabled = _environ_as_bool( + "NEW_RELIC_MEMORY_RUNTIME_METRICS_ENABLED", default=True +) _settings.transaction_events.enabled = True _settings.transaction_events.attributes.enabled = True @@ -953,6 +960,7 @@ def default_otlp_host(host): "NEW_RELIC_AI_MONITORING_RECORD_CONTENT_ENABLED", default=True ) _settings.ai_monitoring._llm_token_count_callback = None +_settings.k8s_operator.enabled = _environ_as_bool("NEW_RELIC_K8S_OPERATOR_ENABLED", default=False) _settings.package_reporting.enabled = _environ_as_bool("NEW_RELIC_PACKAGE_REPORTING_ENABLED", default=True) _settings.ml_insights_events.enabled = _environ_as_bool("NEW_RELIC_ML_INSIGHTS_EVENTS_ENABLED", default=False)