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

feat: Add support for disabling LLM monitoring at the account level. #2592

Merged
merged 6 commits into from
Jul 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2076,8 +2076,8 @@ public bool AiMonitoringEnabled
{
get
{
// AI Monitoring is disabled in High Security Mode
return !HighSecurityModeEnabled && EnvironmentOverrides(_localConfiguration.aiMonitoring.enabled, "NEW_RELIC_AI_MONITORING_ENABLED");
// AI Monitoring is disabled in High Security Mode and can be disabled at the account level
return !HighSecurityModeEnabled && ServerCanDisable(_serverConfiguration.AICollectionEnabled, EnvironmentOverrides(_localConfiguration.aiMonitoring.enabled, "NEW_RELIC_AI_MONITORING_ENABLED"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ public ReportedConfiguration(IConfiguration configuration)
[JsonProperty("agent.disable_file_system_watcher")]
public bool DisableFileSystemWatcher => _configuration.DisableFileSystemWatcher;

[JsonProperty("agent.ai_monitoring.enabled")]
// To support account level disable feature, the name cannot include the "agent" prefix.
// The account level disable feature looks for this setting and will only reply with the ServerConfiguration setting if it is present.
[JsonProperty("ai_monitoring.enabled")]
jaffinito marked this conversation as resolved.
Show resolved Hide resolved
public bool AiMonitoringEnabled => _configuration.AiMonitoringEnabled;

[JsonProperty("ai_monitoring.streaming.enabled")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class ServerConfiguration
[JsonProperty("collect_traces")]
public bool? TraceCollectionEnabled { get; set; }

[JsonProperty("collect_ai")]
public bool? AICollectionEnabled { get; set; }

[JsonProperty("data_report_period")]
public long? DataReportPeriod { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ public ConsoleDynamicMethodFixtureFWLatest()
}
}

/// <summary>
/// Use this fixture for AIM Account level disabled tests
/// </summary>
public class ConsoleDynamicMethodFixtureFWLatestAIM : ConsoleDynamicMethodFixtureFW481
{
public override string TestSettingCategory { get { return "AIM"; } }
public ConsoleDynamicMethodFixtureFWLatestAIM()
{
}
}

/// <summary>
/// Use this fixture for High Security Mode tests
Expand Down Expand Up @@ -121,6 +131,18 @@ public ConsoleDynamicMethodFixtureCoreLatest()
}
}

/// <summary>
/// Use this fixture for AIM Account level disabled tests
/// </summary>
public class ConsoleDynamicMethodFixtureCoreLatestAIM : ConsoleDynamicMethodFixtureCore80
{
public override string TestSettingCategory { get { return "AIM"; } }
public ConsoleDynamicMethodFixtureCoreLatestAIM()
{
}

}

/// <summary>
/// Use this fixture for High Security Mode tests
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using System.Linq;
using NewRelic.Agent.IntegrationTestHelpers;
using NewRelic.Agent.IntegrationTestHelpers.RemoteServiceFixtures;
using Xunit;
using Xunit.Abstractions;

namespace NewRelic.Agent.IntegrationTests.LLM
{
public abstract class LlmAccountDisabledTestsBase<TFixture> : NewRelicIntegrationTest<TFixture>
where TFixture : ConsoleDynamicMethodFixture
{
private readonly TFixture _fixture;
private const string _model = "meta13";
private string _prompt = "In one sentence, what is a large-language model?";

public LlmAccountDisabledTestsBase(TFixture fixture, ITestOutputHelper output) : base(fixture)
{
_fixture = fixture;
_fixture.SetTimeout(TimeSpan.FromMinutes(2));
_fixture.TestLogger = output;
_fixture.AddActions(
setupConfiguration: () =>
{
new NewRelicConfigModifier(fixture.DestinationNewRelicConfigFilePath)
.ForceTransactionTraces()
.EnableAiMonitoring(true) // must be true to test override.
.SetLogLevel("finest");
},
exerciseApplication: () =>
{
_fixture.AgentLog.WaitForLogLines(AgentLogBase.MetricDataLogLineRegex, TimeSpan.FromMinutes(3), 2);
}
);

_fixture.AddCommand($"LLMExerciser InvokeModel {_model} {LLMHelpers.ConvertToBase64(_prompt)}");

_fixture.Initialize();
}

[Fact]
public void BedrockDisabledTest()
{
// Make sure it actually got called
var transactionEvent = _fixture.AgentLog.TryGetTransactionEvent($"OtherTransaction/Custom/MultiFunctionApplicationHelpers.NetStandardLibraries.LLM.LLMExerciser/InvokeModel");
Assert.NotNull(transactionEvent);

var unexpectedMetrics = new List<Assertions.ExpectedMetric>
{
new Assertions.ExpectedMetric { metricName = @"Supportability/DotNet/ML/Bedrock/.*", IsRegexName = true },
new Assertions.ExpectedMetric { metricName = @"Custom/Llm/.*", IsRegexName = true },
};

var metrics = _fixture.AgentLog.GetMetrics().ToList();
Assertions.MetricsDoNotExist(unexpectedMetrics, metrics);


}
}
[NetCoreTest]
public class LlmAccountDisabledTest_CoreLatest : LlmAccountDisabledTestsBase<ConsoleDynamicMethodFixtureCoreLatestAIM>
{
public LlmAccountDisabledTest_CoreLatest(ConsoleDynamicMethodFixtureCoreLatestAIM fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetFrameworkTest]
public class LlmAccountDisabledTest_FWLatest : LlmAccountDisabledTestsBase<ConsoleDynamicMethodFixtureFWLatestAIM>
{
public LlmAccountDisabledTest_FWLatest(ConsoleDynamicMethodFixtureFWLatestAIM fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public void serializes_correctly()
}
],
"agent.disable_file_system_watcher": false,
"agent.ai_monitoring.enabled": true,
"ai_monitoring.enabled": true,
"ai_monitoring.streaming.enabled": true,
"ai_monitoring.record_content.enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public void serializes_correctly()
}
],
"agent.disable_file_system_watcher": false,
"agent.ai_monitoring.enabled": true,
"ai_monitoring.enabled": true,
"ai_monitoring.streaming.enabled": true,
"ai_monitoring.record_content.enabled": true
},
Expand Down
Loading