Skip to content

Commit 30a18a0

Browse files
authored
Feature Work: Refactor and Optimize LogLevelDenyList (#1764)
* ci: Update AwsLamba unit tests to .NET 7.0 (#1759) * Converted LogLevelDenyList to HashSet<string>, updated tests as required. * Cache the logleveldenylist evaluation * Renamed the logLevelDenyList attribute, added integration tests * unit test fix * Integration test fix
1 parent ae97c0f commit 30a18a0

File tree

13 files changed

+324
-22
lines changed

13 files changed

+324
-22
lines changed

src/Agent/NewRelic/Agent/Core/Agent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public void RecordSupportabilityMetric(string metricName, int count)
408408
_agentHealthReporter.ReportSupportabilityCountMetric(metricName, count);
409409
}
410410

411-
public void RecordLogMessage(string frameworkName, object logEvent, Func<object, DateTime> getTimestamp, Func<object, object> getLevel, Func<object, string> getLogMessage, Func<object, Exception> getLogException,Func<object, Dictionary<string, object>> getContextData, string spanId, string traceId)
411+
public void RecordLogMessage(string frameworkName, object logEvent, Func<object, DateTime> getTimestamp, Func<object, object> getLevel, Func<object, string> getLogMessage, Func<object, Exception> getLogException, Func<object, Dictionary<string, object>> getContextData, string spanId, string traceId)
412412
{
413413
_agentHealthReporter.ReportLogForwardingFramework(frameworkName);
414414

@@ -420,8 +420,8 @@ public void RecordLogMessage(string frameworkName, object logEvent, Func<object,
420420
normalizedLevel = string.IsNullOrWhiteSpace(level) ? "UNKNOWN" : level.ToUpper();
421421
}
422422

423-
// we want to ignore case so that we don't have to normalize the deny-list values
424-
if (_configurationService.Configuration.LogLevelDenylist.Contains(normalizedLevel, StringComparer.OrdinalIgnoreCase))
423+
// LogLevelDenyList is already uppercase
424+
if (normalizedLevel != string.Empty && _configurationService.Configuration.LogLevelDenyList.Contains(normalizedLevel))
425425
{
426426
return;
427427
}
@@ -438,7 +438,7 @@ public void RecordLogMessage(string frameworkName, object logEvent, Func<object,
438438

439439
var logMessage = getLogMessage(logEvent);
440440
var logException = getLogException(logEvent);
441-
441+
442442
// exit quickly if the message and exception are missing
443443
if (string.IsNullOrWhiteSpace(logMessage) && logException is null)
444444
{

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5035,7 +5035,7 @@ public partial class configurationApplicationLoggingForwarding
50355035

50365036
private int maxSamplesStoredField;
50375037

5038-
private string logLevelDenylistField;
5038+
private string logLevelDenyListField;
50395039

50405040
/// <summary>
50415041
/// configurationApplicationLoggingForwarding class constructor
@@ -5088,15 +5088,15 @@ public int maxSamplesStored
50885088
}
50895089

50905090
[System.Xml.Serialization.XmlAttributeAttribute()]
5091-
public string logLevelDenylist
5091+
public string logLevelDenyList
50925092
{
50935093
get
50945094
{
5095-
return this.logLevelDenylistField;
5095+
return this.logLevelDenyListField;
50965096
}
50975097
set
50985098
{
5099-
this.logLevelDenylistField = value;
5099+
this.logLevelDenyListField = value;
51005100
}
51015101
}
51025102

src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@
16561656
</xs:annotation>
16571657
</xs:attribute>
16581658

1659-
<xs:attribute name="logLevelDenylist" type="xs:string" use="optional">
1659+
<xs:attribute name="logLevelDenyList" type="xs:string" use="optional">
16601660
<xs:annotation>
16611661
<xs:documentation>
16621662
A comma-separated, case-insensitive, list of log levels that should be ignored and not sent up to New Relic.

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,13 +1990,17 @@ public virtual bool LogDecoratorEnabled
19901990
}
19911991
}
19921992

1993-
public virtual IEnumerable<string> LogLevelDenylist
1993+
private HashSet<string> _logLevelDenyList;
1994+
public virtual HashSet<string> LogLevelDenyList
19941995
{
19951996
get
19961997
{
1997-
return EnvironmentOverrides(_localConfiguration.applicationLogging.forwarding.logLevelDenylist,
1998-
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_LOG_LEVEL_DENYLIST")
1999-
.Split(new[] { StringSeparators.CommaChar, ' ' }, StringSplitOptions.RemoveEmptyEntries);
1998+
return _logLevelDenyList ??= new HashSet<string>(
1999+
EnvironmentOverrides(_localConfiguration.applicationLogging.forwarding.logLevelDenyList,
2000+
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_LOG_LEVEL_DENYLIST")
2001+
?.Split(new[] { StringSeparators.CommaChar, ' ' }, StringSplitOptions.RemoveEmptyEntries)
2002+
.Select(s => s.ToUpper())
2003+
?? Enumerable.Empty<string>());
20002004
}
20012005
}
20022006

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,15 @@ public ReportedConfiguration(IConfiguration configuration)
593593
[JsonProperty("application_logging.forwarding.max_samples_stored")]
594594
public int LogEventsMaxSamplesStored => _configuration.LogEventsMaxSamplesStored;
595595

596+
[JsonProperty("application_logging.forwarding.log_level_denylist")]
597+
public HashSet<string> LogLevelDenyList => _configuration.LogLevelDenyList;
598+
596599
[JsonProperty("application_logging.harvest_cycle")]
597600
public TimeSpan LogEventsHarvestCycle => _configuration.LogEventsHarvestCycle;
598601

599602
[JsonProperty("application_logging.local_decorating.enabled")]
600603
public bool LogDecoratorEnabled => _configuration.LogDecoratorEnabled;
601604

602-
[JsonProperty("application_logging.log_level_denylist")]
603-
public IEnumerable<string> LogLevelDenylist => _configuration.LogLevelDenylist;
604-
605605
[JsonProperty("agent.app_domain_caching_disabled")]
606606
public bool AppDomainCachingDisabled => _configuration.AppDomainCachingDisabled;
607607

src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Configuration/IConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public interface IConfiguration
190190
int LogEventsMaxSamplesStored { get; }
191191
TimeSpan LogEventsHarvestCycle { get; }
192192
bool LogDecoratorEnabled { get; }
193-
IEnumerable<string> LogLevelDenylist { get; }
193+
HashSet<string> LogLevelDenyList { get; }
194194
bool ContextDataEnabled { get; }
195195
IEnumerable<string> ContextDataInclude { get; }
196196
IEnumerable<string> ContextDataExclude { get; }

tests/Agent/IntegrationTests/IntegrationTestHelpers/NewRelicConfigModifier.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,13 @@ public NewRelicConfigModifier SetLogForwardingMaxSamplesStored(int samples)
317317
return this;
318318
}
319319

320+
public NewRelicConfigModifier SetLogForwardingLogLevelDenyList(string logLevelDenyList)
321+
{
322+
CommonUtils.ModifyOrCreateXmlNodeInNewRelicConfig(_configFilePath, new[] { "configuration", "applicationLogging" }, "forwarding", string.Empty);
323+
CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(_configFilePath, new[] { "configuration", "applicationLogging", "forwarding" }, "logLevelDenyList", logLevelDenyList);
324+
return this;
325+
}
326+
320327
public NewRelicConfigModifier SetCodeLevelMetricsEnabled(bool enabled = true)
321328
{
322329
CommonUtils.ModifyOrCreateXmlNodeInNewRelicConfig(_configFilePath, new[] { "configuration" }, "codeLevelMetrics", string.Empty);

0 commit comments

Comments
 (0)