Skip to content

Commit

Permalink
Merge latest from main, resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Nov 21, 2023
2 parents b6a150d + bb41cdc commit 0426904
Show file tree
Hide file tree
Showing 68 changed files with 1,054 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/repolinter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: Test Default Branch
id: default-branch
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
uses: actions/github-script@e69ef5462fd455e02edcaf4dd7708eda96b9eda0 # v7.0.0
with:
script: |
const data = await github.rest.repos.get(context.repo)
Expand Down
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,3 @@ Keep in mind that when you submit your Pull Request, you'll need to sign the CLA

For more information about CLAs, please check out Alex Russell’s excellent post,
[“Why Do I Need to Sign This?”](https://infrequently.org/2008/06/why-do-i-need-to-sign-this/).

## Slack

We host a public Slack with a dedicated channel for contributors and maintainers of open source projects hosted by New Relic. If you are contributing to this project, you're welcome to request access to the #oss-contributors channel in the newrelicusers.slack.com workspace. To request access, please use this [link](https://join.slack.com/t/newrelicusers/shared_invite/zt-1ayj69rzm-~go~Eo1whIQGYnu3qi15ng).
13 changes: 13 additions & 0 deletions src/Agent/NewRelic/Agent/Core/AgentHealth/AgentHealthReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ private void CollectOneTimeMetrics()
ReportLogForwardingConfiguredValues();
ReportIfAppDomainCachingDisabled();
ReportInfiniteTracingOneTimeMetrics();
ReportIfLoggingDisabled();
}

public void CollectMetrics()
Expand Down Expand Up @@ -829,5 +830,17 @@ protected override void OnConfigurationUpdated(ConfigurationUpdateSource configu
// Some one time metrics are reporting configured values, so we want to re-report them if the configuration changed
_oneTimeMetricsCollected = false;
}

private void ReportIfLoggingDisabled()
{
if (!_configuration.LoggingEnabled)
{
ReportSupportabilityCountMetric(MetricNames.SupportabilityLoggingDisabled);
}
if (Log.FileLoggingHasFailed)
{
ReportSupportabilityCountMetric(MetricNames.SupportabilityLoggingFatalError);
}
}
}
}
2 changes: 2 additions & 0 deletions src/Agent/NewRelic/Agent/Core/AgentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ private void LogInitialized()
"NEW_RELIC_LOG",
"NEWRELIC_PROFILER_LOG_DIRECTORY",
"NEWRELIC_LOG_LEVEL",
"NEW_RELIC_LOG_ENABLED",
"NEW_RELIC_LOG_CONSOLE",
"NEW_RELIC_LABELS",
"NEW_RELIC_PROXY_HOST",
"NEW_RELIC_PROXY_URI_PATH",
Expand Down
16 changes: 16 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ public virtual configurationApplication Clone()
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:newrelic-config")]
public partial class configurationLog
{
private bool enabledField;

private string levelField;

Expand All @@ -1300,6 +1301,7 @@ public partial class configurationLog
/// </summary>
public configurationLog()
{
this.enabledField = true;
this.levelField = "info";
this.consoleField = false;
this.auditLogField = false;
Expand Down Expand Up @@ -1358,6 +1360,20 @@ public bool console
this.consoleField = value;
}
}

[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(true)]
public bool enabled
{
get
{
return this.enabledField;
}
set
{
this.enabledField = value;
}
}

[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(false)]
Expand Down
8 changes: 8 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@
</xs:annotation>
</xs:attribute>

<xs:attribute name="enabled" type="xs:boolean" default="true">
<xs:annotation>
<xs:documentation>
If this is false, no attempts will be made to write to a log file. This is primarily used for installations on read-only file systems.
</xs:documentation>
</xs:annotation>
</xs:attribute>

<xs:attribute name="directory" type="xs:string" use="optional">
<xs:annotation>
<xs:documentation>
Expand Down
44 changes: 42 additions & 2 deletions src/Agent/NewRelic/Agent/Core/Config/ConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private static string InternalGetAppDomainAppPath()

public static Func<string, bool> FileExists = File.Exists;
public static Func<string, string> PathGetDirectoryName = Path.GetDirectoryName;
public static Func<string, string> GetEnvironmentVar = System.Environment.GetEnvironmentVariable;

private static string InternalGetNewRelicHome()
{
Expand Down Expand Up @@ -522,6 +523,10 @@ public string LogLevel
{
get
{
if (!Enabled)
{
return "off";
}
// Environment variable or log.level from config...
return (AgentInstallConfiguration.NewRelicLogLevel
?? this.level).ToUpper();
Expand Down Expand Up @@ -559,7 +564,7 @@ public string GetFullLogFileName()

private string GetLogFileName()
{
string name = System.Environment.GetEnvironmentVariable("NEW_RELIC_LOG");
string name = ConfigurationLoader.GetEnvironmentVar("NEW_RELIC_LOG");
if (name != null)
{
return Strings.SafeFileName(name);
Expand Down Expand Up @@ -594,11 +599,46 @@ private string GetLogFileName()
return "newrelic_agent_" + Strings.SafeFileName(name) + ".log";
}

private bool GetOverride(string name, bool fallback)
{
var val = ConfigurationLoader.GetEnvironmentVar(name);

if (val != null)
{
val = val.ToLower();
}

if (bool.TryParse(val, out var parsedValue))
{
return parsedValue;
}

if ("0" == val)
{
return false;
}

if ("1" == val)
{
return true;
}

return fallback;
}

public bool Console
{
get
{
return console;
return GetOverride("NEW_RELIC_LOG_CONSOLE", console);
}
}

public bool Enabled
{
get
{
return GetOverride("NEW_RELIC_LOG_ENABLED", enabled);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Config/ILogConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace NewRelic.Agent.Core.Config
{
public interface ILogConfig
{
bool Enabled { get; }

string LogLevel { get; }

string GetFullLogFileName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void OnConfigurationDeserialized(ConfigurationDeserializedEvent configur
private static void UpdateLogLevel(configuration localConfiguration)
{
Log.Info("The log level was updated to {0}", localConfiguration.LogConfig.LogLevel);
LoggerBootstrapper.UpdateLoggingLevel(localConfiguration.LogConfig.LogLevel);
LoggerBootstrapper.SetLoggingLevel(localConfiguration.LogConfig.LogLevel);
}

private void OnServerConfigurationUpdated(ServerConfigurationUpdatedEvent serverConfigurationUpdatedEvent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2775,6 +2775,8 @@ public bool CodeLevelMetricsEnabled

#endregion

public bool LoggingEnabled => _localConfiguration.log.Enabled;

private const bool CaptureTransactionTraceAttributesDefault = true;
private const bool CaptureErrorCollectorAttributesDefault = true;
private const bool CaptureBrowserMonitoringAttributesDefault = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ public ReportedConfiguration(IConfiguration configuration)
[JsonProperty("stackexchangeredis_cleanup.cycle")]
public TimeSpan StackExchangeRedisCleanupCycle => _configuration.StackExchangeRedisCleanupCycle;

[JsonProperty("agent.logging_enabled")]
public bool LoggingEnabled => _configuration.LoggingEnabled;

public IReadOnlyDictionary<string, string> GetAppSettings()
{
return _configuration.GetAppSettings();
Expand Down
6 changes: 2 additions & 4 deletions src/Agent/NewRelic/Agent/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.Expressions" Version="3.4.1" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
Expand Down Expand Up @@ -101,7 +100,6 @@
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'NewRelic.Parsing'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Newtonsoft.Json'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Serilog'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Serilog.Expressions'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Serilog.Sinks.Async'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Serilog.Sinks.Console'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Serilog.Sinks.Debug'" />
Expand All @@ -126,8 +124,8 @@
</ItemGroup>

<PropertyGroup>
<ILRepackIncludeCount Condition="'$(TargetFramework)' == 'net462'">20</ILRepackIncludeCount>
<ILRepackIncludeCount Condition="'$(TargetFramework)' == 'netstandard2.0'">17</ILRepackIncludeCount>
<ILRepackIncludeCount Condition="'$(TargetFramework)' == 'net462'">19</ILRepackIncludeCount>
<ILRepackIncludeCount Condition="'$(TargetFramework)' == 'netstandard2.0'">16</ILRepackIncludeCount>
</PropertyGroup>

<Error Text="ILRepack of $(AssemblyName) ($(TargetFramework)) failed. A dependency is missing. Expected $(ILRepackIncludeCount) dependencies but found @(ILRepackInclude-&gt;Count())." Condition="@(ILRepackInclude-&gt;Count()) != $(ILRepackIncludeCount)" />
Expand Down
4 changes: 2 additions & 2 deletions src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public static void Log(string message)

public static LoggerConfiguration IncludeOnlyAuditLog(this LoggerConfiguration loggerConfiguration)
{
return loggerConfiguration.Filter.ByIncludingOnly($"{LogLevelExtensions.AuditLevel} is not null");
return loggerConfiguration.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey(LogLevelExtensions.AuditLevel));
}

public static LoggerConfiguration ExcludeAuditLog(this LoggerConfiguration loggerConfiguration)
{
return loggerConfiguration.Filter.ByIncludingOnly($"{LogLevelExtensions.AuditLevel} is null");
return loggerConfiguration.Filter.ByIncludingOnly(logEvent => !logEvent.Properties.ContainsKey(LogLevelExtensions.AuditLevel));
}
}
}
Loading

0 comments on commit 0426904

Please sign in to comment.