Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Sending of ML Events by Default #923

Merged
merged 8 commits into from
Sep 20, 2023
4 changes: 2 additions & 2 deletions newrelic/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def default_otlp_host(host):
_settings.transaction_events.attributes.include = []

_settings.custom_insights_events.enabled = True
_settings.ml_insights_events.enabled = True
_settings.ml_insights_events.enabled = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to stay false too? Or just the global override setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was supposed to stay False since we check this as a standalone setting in calls to record_ml_event and not in conjunction with machine_learning.enabled.


_settings.distributed_tracing.enabled = _environ_as_bool("NEW_RELIC_DISTRIBUTED_TRACING_ENABLED", default=True)
_settings.distributed_tracing.exclude_newrelic_header = False
Expand Down Expand Up @@ -894,7 +894,7 @@ def default_otlp_host(host):
_settings.application_logging.local_decorating.enabled = _environ_as_bool(
"NEW_RELIC_APPLICATION_LOGGING_LOCAL_DECORATING_ENABLED", default=False
)
_settings.machine_learning.enabled = _environ_as_bool("NEW_RELIC_MACHINE_LEARNING_ENABLED", default=True)
_settings.machine_learning.enabled = _environ_as_bool("NEW_RELIC_MACHINE_LEARNING_ENABLED", default=False)
_settings.machine_learning.inference_events_value.enabled = _environ_as_bool(
"NEW_RELIC_MACHINE_LEARNING_INFERENCE_EVENT_VALUE_ENABLED", default=True
)
Expand Down
1 change: 1 addition & 0 deletions tests/agent_features/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"debug.record_transaction_failure": True,
"debug.log_autorum_middleware": True,
"agent_limits.errors_per_harvest": 100,
"ml_insights_events.enabled": True
}

collector_agent_registration = collector_agent_registration_fixture(
Expand Down
3 changes: 1 addition & 2 deletions tests/agent_features/test_ml_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,11 @@ def test_record_ml_event_outside_transaction_params_not_a_dict():

# Tests for ML Events configuration settings


@override_application_settings({"ml_insights_events.enabled": False})
@reset_core_stats_engine()
@validate_ml_event_count(count=0)
@background_task()
def test_ml_event_settings_check_ml_insights_enabled():
def test_ml_event_settings_check_ml_insights_disabled():
record_ml_event("FooEvent", {"foo": "bar"})


Expand Down
3 changes: 3 additions & 0 deletions tests/mlmodel_sklearn/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"transaction_tracer.stack_trace_threshold": 0.0,
"debug.log_data_collector_payloads": True,
"debug.record_transaction_failure": True,
"machine_learning.enabled": True,
"machine_learning.inference_events_value.enabled": True,
"ml_insights_events.enabled": True
}
collector_agent_registration = collector_agent_registration_fixture(
app_name="Python Agent Test (mlmodel_sklearn)",
Expand Down
1 change: 1 addition & 0 deletions tests/mlmodel_sklearn/test_ensemble_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def _test():
_test()



@pytest.mark.skipif(SKLEARN_VERSION < (1, 1, 0), reason="Requires sklearn >= 1.1")
@pytest.mark.parametrize(
"ensemble_model_name",
Expand Down
28 changes: 25 additions & 3 deletions tests/mlmodel_sklearn/test_inference_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
override_application_settings,
reset_core_stats_engine,
)
from testing_support.fixtures import override_application_settings
from testing_support.validators.validate_ml_event_count import validate_ml_event_count
from testing_support.validators.validate_ml_events import validate_ml_events

Expand Down Expand Up @@ -284,8 +285,15 @@ def _test():
]


disabled_inference_value_settings = {
"machine_learning.enabled": True,
"machine_learning.inference_events_value.enabled": False,
"ml_insights_events.enabled": True
}


@override_application_settings(disabled_inference_value_settings)
@reset_core_stats_engine()
@override_application_settings({"machine_learning.inference_events_value.enabled": False})
def test_does_not_include_value_when_inference_event_value_enabled_is_false():
@validate_ml_events(numpy_str_recorded_custom_events_no_value)
@validate_ml_event_count(count=1)
Expand All @@ -306,8 +314,15 @@ def _test():
_test()


disabled_ml_insights_settings = {
"machine_learning.enabled": True,
"machine_learning.inference_events_value.enabled": True,
"ml_insights_events.enabled": False
}


@override_application_settings(disabled_ml_insights_settings)
@reset_core_stats_engine()
@override_application_settings({"ml_insights_events.enabled": False})
def test_does_not_include_events_when_ml_insights_events_enabled_is_false():
"""
Verifies that all ml events can be disabled by setting
Expand All @@ -332,8 +347,15 @@ def _test():
_test()


disabled_ml_settings = {
"machine_learning.enabled": False,
"machine_learning.inference_events_value.enabled": True,
"ml_insights_events.enabled": True
}


@override_application_settings(disabled_ml_settings)
@reset_core_stats_engine()
@override_application_settings({"machine_learning.enabled": False})
def test_does_not_include_events_when_machine_learning_enabled_is_false():
@validate_ml_event_count(count=0)
@background_task()
Expand Down
Loading