Skip to content

Commit c31451a

Browse files
authored
feat: Add support for disabling LLM monitoring at the account level. (#2592)
1 parent b17bfab commit c31451a

File tree

7 files changed

+114
-5
lines changed

7 files changed

+114
-5
lines changed

src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2076,8 +2076,8 @@ public bool AiMonitoringEnabled
20762076
{
20772077
get
20782078
{
2079-
// AI Monitoring is disabled in High Security Mode
2080-
return !HighSecurityModeEnabled && EnvironmentOverrides(_localConfiguration.aiMonitoring.enabled, "NEW_RELIC_AI_MONITORING_ENABLED");
2079+
// AI Monitoring is disabled in High Security Mode and can be disabled at the account level
2080+
return !HighSecurityModeEnabled && ServerCanDisable(_serverConfiguration.AICollectionEnabled, EnvironmentOverrides(_localConfiguration.aiMonitoring.enabled, "NEW_RELIC_AI_MONITORING_ENABLED"));
20812081
}
20822082
}
20832083

src/Agent/NewRelic/Agent/Core/Configuration/ReportedConfiguration.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,9 @@ public ReportedConfiguration(IConfiguration configuration)
665665
[JsonProperty("agent.disable_file_system_watcher")]
666666
public bool DisableFileSystemWatcher => _configuration.DisableFileSystemWatcher;
667667

668-
[JsonProperty("agent.ai_monitoring.enabled")]
668+
// To support account level disable feature, the name cannot include the "agent" prefix.
669+
// The account level disable feature looks for this setting and will only reply with the ServerConfiguration setting if it is present.
670+
[JsonProperty("ai_monitoring.enabled")]
669671
public bool AiMonitoringEnabled => _configuration.AiMonitoringEnabled;
670672

671673
[JsonProperty("ai_monitoring.streaming.enabled")]

src/Agent/NewRelic/Agent/Core/Configuration/ServerConfiguration.cs

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class ServerConfiguration
4242
[JsonProperty("collect_traces")]
4343
public bool? TraceCollectionEnabled { get; set; }
4444

45+
[JsonProperty("collect_ai")]
46+
public bool? AICollectionEnabled { get; set; }
47+
4548
[JsonProperty("data_report_period")]
4649
public long? DataReportPeriod { get; set; }
4750

tests/Agent/IntegrationTests/IntegrationTestHelpers/RemoteServiceFixtures/ConsoleDynamicMethodFixture.cs

+22
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ public ConsoleDynamicMethodFixtureFWLatest()
1616
}
1717
}
1818

19+
/// <summary>
20+
/// Use this fixture for AIM Account level disabled tests
21+
/// </summary>
22+
public class ConsoleDynamicMethodFixtureFWLatestAIM : ConsoleDynamicMethodFixtureFW481
23+
{
24+
public override string TestSettingCategory { get { return "AIM"; } }
25+
public ConsoleDynamicMethodFixtureFWLatestAIM()
26+
{
27+
}
28+
}
1929

2030
/// <summary>
2131
/// Use this fixture for High Security Mode tests
@@ -121,6 +131,18 @@ public ConsoleDynamicMethodFixtureCoreLatest()
121131
}
122132
}
123133

134+
/// <summary>
135+
/// Use this fixture for AIM Account level disabled tests
136+
/// </summary>
137+
public class ConsoleDynamicMethodFixtureCoreLatestAIM : ConsoleDynamicMethodFixtureCore80
138+
{
139+
public override string TestSettingCategory { get { return "AIM"; } }
140+
public ConsoleDynamicMethodFixtureCoreLatestAIM()
141+
{
142+
}
143+
144+
}
145+
124146
/// <summary>
125147
/// Use this fixture for High Security Mode tests
126148
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2020 New Relic, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using NewRelic.Agent.IntegrationTestHelpers;
8+
using NewRelic.Agent.IntegrationTestHelpers.RemoteServiceFixtures;
9+
using Xunit;
10+
using Xunit.Abstractions;
11+
12+
namespace NewRelic.Agent.IntegrationTests.LLM
13+
{
14+
public abstract class LlmAccountDisabledTestsBase<TFixture> : NewRelicIntegrationTest<TFixture>
15+
where TFixture : ConsoleDynamicMethodFixture
16+
{
17+
private readonly TFixture _fixture;
18+
private const string _model = "meta13";
19+
private string _prompt = "In one sentence, what is a large-language model?";
20+
21+
public LlmAccountDisabledTestsBase(TFixture fixture, ITestOutputHelper output) : base(fixture)
22+
{
23+
_fixture = fixture;
24+
_fixture.SetTimeout(TimeSpan.FromMinutes(2));
25+
_fixture.TestLogger = output;
26+
_fixture.AddActions(
27+
setupConfiguration: () =>
28+
{
29+
new NewRelicConfigModifier(fixture.DestinationNewRelicConfigFilePath)
30+
.ForceTransactionTraces()
31+
.EnableAiMonitoring(true) // must be true to test override.
32+
.SetLogLevel("finest");
33+
},
34+
exerciseApplication: () =>
35+
{
36+
_fixture.AgentLog.WaitForLogLines(AgentLogBase.MetricDataLogLineRegex, TimeSpan.FromMinutes(3), 2);
37+
}
38+
);
39+
40+
_fixture.AddCommand($"LLMExerciser InvokeModel {_model} {LLMHelpers.ConvertToBase64(_prompt)}");
41+
42+
_fixture.Initialize();
43+
}
44+
45+
[Fact]
46+
public void BedrockDisabledTest()
47+
{
48+
// Make sure it actually got called
49+
var transactionEvent = _fixture.AgentLog.TryGetTransactionEvent($"OtherTransaction/Custom/MultiFunctionApplicationHelpers.NetStandardLibraries.LLM.LLMExerciser/InvokeModel");
50+
Assert.NotNull(transactionEvent);
51+
52+
var unexpectedMetrics = new List<Assertions.ExpectedMetric>
53+
{
54+
new Assertions.ExpectedMetric { metricName = @"Supportability/DotNet/ML/Bedrock/.*", IsRegexName = true },
55+
new Assertions.ExpectedMetric { metricName = @"Custom/Llm/.*", IsRegexName = true },
56+
};
57+
58+
var metrics = _fixture.AgentLog.GetMetrics().ToList();
59+
Assertions.MetricsDoNotExist(unexpectedMetrics, metrics);
60+
61+
62+
}
63+
}
64+
[NetCoreTest]
65+
public class LlmAccountDisabledTest_CoreLatest : LlmAccountDisabledTestsBase<ConsoleDynamicMethodFixtureCoreLatestAIM>
66+
{
67+
public LlmAccountDisabledTest_CoreLatest(ConsoleDynamicMethodFixtureCoreLatestAIM fixture, ITestOutputHelper output)
68+
: base(fixture, output)
69+
{
70+
}
71+
}
72+
73+
[NetFrameworkTest]
74+
public class LlmAccountDisabledTest_FWLatest : LlmAccountDisabledTestsBase<ConsoleDynamicMethodFixtureFWLatestAIM>
75+
{
76+
public LlmAccountDisabledTest_FWLatest(ConsoleDynamicMethodFixtureFWLatestAIM fixture, ITestOutputHelper output)
77+
: base(fixture, output)
78+
{
79+
}
80+
}
81+
82+
}

tests/Agent/UnitTests/Core.UnitTest/DataTransport/AgentSettingsTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public void serializes_correctly()
338338
}
339339
],
340340
"agent.disable_file_system_watcher": false,
341-
"agent.ai_monitoring.enabled": true,
341+
"ai_monitoring.enabled": true,
342342
"ai_monitoring.streaming.enabled": true,
343343
"ai_monitoring.record_content.enabled": true
344344
}

tests/Agent/UnitTests/Core.UnitTest/DataTransport/ConnectModelTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public void serializes_correctly()
408408
}
409409
],
410410
"agent.disable_file_system_watcher": false,
411-
"agent.ai_monitoring.enabled": true,
411+
"ai_monitoring.enabled": true,
412412
"ai_monitoring.streaming.enabled": true,
413413
"ai_monitoring.record_content.enabled": true
414414
},

0 commit comments

Comments
 (0)