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

Add config setting for sklearn inference event capture. #706

Merged
merged 17 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions newrelic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ def _process_configuration(section):
_process_setting(section, "application_logging.metrics.enabled", "getboolean", None)
_process_setting(section, "application_logging.local_decorating.enabled", "getboolean", None)

_process_setting(section, "machine_learning.inference_event_value.enabled", "getboolean", None)


# Loading of configuration from specified file and for specified
# deployment environment. Can also indicate whether configuration
Expand Down Expand Up @@ -875,6 +877,10 @@ def apply_local_high_security_mode_setting(settings):
settings.application_logging.forwarding.enabled = False
_logger.info(log_template, "application_logging.forwarding.enabled", True, False)

if settings.machine_learning.inference_event_value.enabled:
settings.machine_learning.inference_event_value.enabled = False
_logger.info(log_template, "machine_learning.inference_event_value.enabled", True, False)

return settings


Expand Down
1 change: 1 addition & 0 deletions newrelic/core/agent_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class AgentProtocol(object):
"strip_exception_messages.enabled",
"custom_insights_events.enabled",
"application_logging.forwarding.enabled",
"machine_learning.inference_event_value.enabled",
)

LOGGER_FUNC_MAPPING = {
Expand Down
13 changes: 13 additions & 0 deletions newrelic/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ class GCRuntimeMetricsSettings(Settings):
enabled = False


class MachineLearningSettings(Settings):
pass


class MachineLearningInferenceEventValueSettings(Settings):
pass


class CodeLevelMetricsSettings(Settings):
pass

Expand Down Expand Up @@ -359,6 +367,8 @@ class EventHarvestConfigHarvestLimitSettings(Settings):
_settings.application_logging.forwarding = ApplicationLoggingForwardingSettings()
_settings.application_logging.metrics = ApplicationLoggingMetricsSettings()
_settings.application_logging.local_decorating = ApplicationLoggingLocalDecoratingSettings()
_settings.machine_learning = MachineLearningSettings()
_settings.machine_learning.inference_event_value = MachineLearningInferenceEventValueSettings()
_settings.attributes = AttributesSettings()
_settings.gc_runtime_metrics = GCRuntimeMetricsSettings()
_settings.code_level_metrics = CodeLevelMetricsSettings()
Expand Down Expand Up @@ -821,6 +831,9 @@ def default_host(license_key):
_settings.application_logging.local_decorating.enabled = _environ_as_bool(
"NEW_RELIC_APPLICATION_LOGGING_LOCAL_DECORATING_ENABLED", default=False
)
_settings.machine_learning.inference_event_value.enabled = _environ_as_bool(
"NEW_RELIC_MACHINE_LEARNING_INFERENCE_EVENT_VALUE_ENABLED", default=True
)


def global_settings():
Expand Down
31 changes: 31 additions & 0 deletions tests/agent_features/test_high_security_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": True,
"message_tracer.segment_parameters_enabled": True,
"application_logging.forwarding.enabled": True,
"machine_learning.inference_event_value.enabled": True,
},
{
"high_security": False,
Expand All @@ -88,6 +89,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": False,
"message_tracer.segment_parameters_enabled": True,
"application_logging.forwarding.enabled": True,
"machine_learning.inference_event_value.enabled": True,
},
{
"high_security": False,
Expand All @@ -97,6 +99,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": True,
"message_tracer.segment_parameters_enabled": False,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
},
{
"high_security": False,
Expand All @@ -106,6 +109,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": False,
"message_tracer.segment_parameters_enabled": False,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
},
]

Expand All @@ -118,6 +122,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": True,
"message_tracer.segment_parameters_enabled": True,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
},
{
"high_security": True,
Expand All @@ -127,6 +132,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": True,
"message_tracer.segment_parameters_enabled": True,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
},
{
"high_security": True,
Expand All @@ -136,6 +142,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": True,
"message_tracer.segment_parameters_enabled": True,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
},
{
"high_security": True,
Expand All @@ -145,6 +152,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": True,
"message_tracer.segment_parameters_enabled": True,
"application_logging.forwarding.enabled": True,
"machine_learning.inference_event_value.enabled": True,
},
{
"high_security": True,
Expand All @@ -154,6 +162,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": True,
"message_tracer.segment_parameters_enabled": True,
"application_logging.forwarding.enabled": True,
"machine_learning.inference_event_value.enabled": True,
},
{
"high_security": True,
Expand All @@ -163,6 +172,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": True,
"message_tracer.segment_parameters_enabled": False,
"application_logging.forwarding.enabled": True,
"machine_learning.inference_event_value.enabled": True,
},
{
"high_security": True,
Expand All @@ -172,6 +182,7 @@ def test_hsm_configuration_default():
"custom_insights_events.enabled": False,
"message_tracer.segment_parameters_enabled": False,
"application_logging.forwarding.enabled": True,
"machine_learning.inference_event_value.enabled": True,
},
]

Expand All @@ -196,6 +207,7 @@ def test_local_config_file_override_hsm_disabled(settings):
original_custom_events = settings.custom_insights_events.enabled
original_message_segment_params_enabled = settings.message_tracer.segment_parameters_enabled
original_application_logging_forwarding_enabled = settings.application_logging.forwarding.enabled
original_machine_learning_inference_event_value_enabled = settings.machine_learning.inference_event_value.enabled

apply_local_high_security_mode_setting(settings)

Expand All @@ -205,6 +217,10 @@ def test_local_config_file_override_hsm_disabled(settings):
assert settings.custom_insights_events.enabled == original_custom_events
assert settings.message_tracer.segment_parameters_enabled == original_message_segment_params_enabled
assert settings.application_logging.forwarding.enabled == original_application_logging_forwarding_enabled
assert (
settings.machine_learning.inference_event_value.enabled
== original_machine_learning_inference_event_value_enabled
)


@parameterize_hsm_local_config(_hsm_local_config_file_settings_enabled)
Expand All @@ -217,6 +233,7 @@ def test_local_config_file_override_hsm_enabled(settings):
assert settings.custom_insights_events.enabled is False
assert settings.message_tracer.segment_parameters_enabled is False
assert settings.application_logging.forwarding.enabled is False
assert settings.machine_learning.inference_event_value.enabled is False


_server_side_config_settings_hsm_disabled = [
Expand All @@ -228,6 +245,7 @@ def test_local_config_file_override_hsm_enabled(settings):
"strip_exception_messages.enabled": True,
"custom_insights_events.enabled": False,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
},
{
"agent_config": {
Expand All @@ -236,6 +254,7 @@ def test_local_config_file_override_hsm_enabled(settings):
"strip_exception_messages.enabled": False,
"custom_insights_events.enabled": True,
"application_logging.forwarding.enabled": True,
"machine_learning.inference_event_value.enabled": True,
},
},
),
Expand All @@ -247,6 +266,7 @@ def test_local_config_file_override_hsm_enabled(settings):
"strip_exception_messages.enabled": False,
"custom_insights_events.enabled": True,
"application_logging.forwarding.enabled": True,
"machine_learning.inference_event_value.enabled": True,
},
{
"agent_config": {
Expand All @@ -255,6 +275,7 @@ def test_local_config_file_override_hsm_enabled(settings):
"strip_exception_messages.enabled": True,
"custom_insights_events.enabled": False,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
},
},
),
Expand All @@ -269,6 +290,7 @@ def test_local_config_file_override_hsm_enabled(settings):
"strip_exception_messages.enabled": True,
"custom_insights_events.enabled": False,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
},
{
"high_security": True,
Expand All @@ -277,12 +299,14 @@ def test_local_config_file_override_hsm_enabled(settings):
"strip_exception_messages.enabled": True,
"custom_insights_events.enabled": False,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
"agent_config": {
"capture_params": False,
"transaction_tracer.record_sql": "obfuscated",
"strip_exception_messages.enabled": True,
"custom_insights_events.enabled": False,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
},
},
),
Expand All @@ -294,6 +318,7 @@ def test_local_config_file_override_hsm_enabled(settings):
"strip_exception_messages.enabled": True,
"custom_insights_events.enabled": False,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
},
{
"high_security": True,
Expand All @@ -302,12 +327,14 @@ def test_local_config_file_override_hsm_enabled(settings):
"strip_exception_messages.enabled": True,
"custom_insights_events.enabled": False,
"application_logging.forwarding.enabled": False,
"machine_learning.inference_event_value.enabled": False,
"agent_config": {
"capture_params": True,
"transaction_tracer.record_sql": "raw",
"strip_exception_messages.enabled": False,
"custom_insights_events.enabled": True,
"application_logging.forwarding.enabled": True,
"machine_learning.inference_event_value.enabled": True,
},
},
),
Expand All @@ -328,6 +355,7 @@ def test_remote_config_fixups_hsm_disabled(local_settings, server_settings):
original_strip_messages = agent_config["strip_exception_messages.enabled"]
original_custom_events = agent_config["custom_insights_events.enabled"]
original_log_forwarding = agent_config["application_logging.forwarding.enabled"]
original_machine_learning_events = agent_config["machine_learning.inference_event_value.enabled"]

_settings = global_settings()
settings = override_generic_settings(_settings, local_settings)(AgentProtocol._apply_high_security_mode_fixups)(
Expand All @@ -343,6 +371,7 @@ def test_remote_config_fixups_hsm_disabled(local_settings, server_settings):
assert agent_config["strip_exception_messages.enabled"] == original_strip_messages
assert agent_config["custom_insights_events.enabled"] == original_custom_events
assert agent_config["application_logging.forwarding.enabled"] == original_log_forwarding
assert agent_config["machine_learning.inference_event_value.enabled"] == original_machine_learning_events


@pytest.mark.parametrize("local_settings,server_settings", _server_side_config_settings_hsm_enabled)
Expand All @@ -365,12 +394,14 @@ def test_remote_config_fixups_hsm_enabled(local_settings, server_settings):
assert "strip_exception_messages.enabled" not in settings
assert "custom_insights_events.enabled" not in settings
assert "application_logging.forwarding.enabled" not in settings
assert "machine_learning.inference_event_value.enabled" not in settings

assert "capture_params" not in agent_config
assert "transaction_tracer.record_sql" not in agent_config
assert "strip_exception_messages.enabled" not in agent_config
assert "custom_insights_events.enabled" not in agent_config
assert "application_logging.forwarding.enabled" not in agent_config
assert "machine_learning.inference_event_value.enabled" not in agent_config


def test_remote_config_hsm_fixups_server_side_disabled():
Expand Down