diff --git a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs index e5c9983ddf..c2869c5c54 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs @@ -20,14 +20,21 @@ namespace NewRelic.Agent.Core { public static partial class AgentInstallConfiguration { + // This field exists only for testing purposes. It allows bootstrap logic and regular + // configuration logic to use the same environment variable logic. + public static IEnvironment EnvironmentVariableProxy = new SharedInterfaces.Environment(); + #if NETSTANDARD2_0 - private const string NewRelicHomeEnvironmentVariable = "CORECLR_NEWRELIC_HOME"; + // TODO: remove legacy env var name in v11 + private static readonly string[] NewRelicHomeEnvironmentVariables = ["CORECLR_NEW_RELIC_HOME", "CORECLR_NEWRELIC_HOME"]; private const string RuntimeDirectoryName = "netcore"; #else - private const string NewRelicHomeEnvironmentVariable = "NEWRELIC_HOME"; + // TODO: remove legacy env var name in v11 + private static readonly string[] NewRelicHomeEnvironmentVariables = ["NEW_RELIC_HOME", "NEWRELIC_HOME"]; private const string RuntimeDirectoryName = "netframework"; #endif - private const string NewRelicInstallPathEnvironmentVariable = "NEWRELIC_INSTALL_PATH"; + // TODO: remove legacy env var name in v11 + private static readonly string[] NewRelicInstallPathEnvironmentVariables = ["NEW_RELIC_INSTALL_PATH", "NEWRELIC_INSTALL_PATH"]; public static bool IsWindows { get; } #if NETFRAMEWORK @@ -158,7 +165,7 @@ private static bool GetIsNetCore30OrAbove() private static string GetNewRelicHome() { - var newRelicHome = System.Environment.GetEnvironmentVariable(NewRelicHomeEnvironmentVariable); + var newRelicHome = EnvironmentVariableProxy.GetEnvironmentVariableFromList(NewRelicHomeEnvironmentVariables); if (newRelicHome != null && Directory.Exists(newRelicHome)) return Path.GetFullPath(newRelicHome); #if NETFRAMEWORK var key = Registry.LocalMachine.OpenSubKey(@"Software\New Relic\.NET Agent"); @@ -169,14 +176,14 @@ private static string GetNewRelicHome() private static string GetNewRelicInstallPath() { - var newRelicInstallPath = System.Environment.GetEnvironmentVariable(NewRelicInstallPathEnvironmentVariable); + var newRelicInstallPath = EnvironmentVariableProxy.GetEnvironmentVariableFromList(NewRelicInstallPathEnvironmentVariables); if (newRelicInstallPath != null) { newRelicInstallPath = Path.Combine(newRelicInstallPath, RuntimeDirectoryName); if (Directory.Exists(newRelicInstallPath)) return newRelicInstallPath; } - newRelicInstallPath = System.Environment.GetEnvironmentVariable(NewRelicHomeEnvironmentVariable); + newRelicInstallPath = EnvironmentVariableProxy.GetEnvironmentVariableFromList(NewRelicHomeEnvironmentVariables); return newRelicInstallPath; } diff --git a/src/Agent/NewRelic/Agent/Core/AgentManager.cs b/src/Agent/NewRelic/Agent/Core/AgentManager.cs index 94e513fde0..0a29e4106a 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentManager.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentManager.cs @@ -217,7 +217,7 @@ private void LogInitialized() List environmentVariables = new List { "CORECLR_ENABLE_PROFILING", "CORECLR_PROFILER", - "CORECLR_NEWRELIC_HOME", + "CORECLR_NEW_RELIC_HOME", "CORECLR_PROFILER_PATH", "CORECLR_PROFILER_PATH_32", "CORECLR_PROFILER_PATH_64", @@ -226,8 +226,8 @@ private void LogInitialized() "COR_PROFILER_PATH", "COR_PROFILER_PATH_32", "COR_PROFILER_PATH_64", - "NEWRELIC_HOME", - "NEWRELIC_INSTALL_PATH", + "NEW_RELIC_HOME", + "NEW_RELIC_INSTALL_PATH", "NEW_RELIC_APP_NAME", "RoleName", "IISEXPRESS_SITENAME", @@ -246,8 +246,8 @@ private void LogInitialized() "NEW_RELIC_PROCESS_HOST_DISPLAY_NAME", "NEW_RELIC_IGNORE_SERVER_SIDE_CONFIG", "NEW_RELIC_LOG", - "NEWRELIC_PROFILER_LOG_DIRECTORY", - "NEWRELIC_LOG_LEVEL", + "NEW_RELIC_PROFILER_LOG_DIRECTORY", + "NEW_RELIC_LOG_LEVEL", "NEW_RELIC_LOG_ENABLED", "NEW_RELIC_LOG_CONSOLE", "NEW_RELIC_LABELS", @@ -285,7 +285,13 @@ private void LogInitialized() "NEW_RELIC_CODE_LEVEL_METRICS_ENABLED", "NEW_RELIC_SEND_DATA_ON_EXIT", "NEW_RELIC_SEND_DATA_ON_EXIT_THRESHOLD_MS", - "NEW_RELIC_AZURE_FUNCTION_MODE_ENABLED" + "NEW_RELIC_AZURE_FUNCTION_MODE_ENABLED", + // TODO: remove in v11 + "CORECLR_NEWRELIC_HOME", + "NEWRELIC_HOME", + "NEWRELIC_INSTALL_PATH", + "NEWRELIC_PROFILER_LOG_DIRECTORY", + "NEWRELIC_LOG_LEVEL", }; List environmentVariablesSensitive = new List { diff --git a/src/Agent/NewRelic/Agent/Core/Config/BootstrapConfiguration.cs b/src/Agent/NewRelic/Agent/Core/Config/BootstrapConfiguration.cs index 61414f9a5c..00c5cb3e99 100644 --- a/src/Agent/NewRelic/Agent/Core/Config/BootstrapConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/Config/BootstrapConfiguration.cs @@ -284,7 +284,8 @@ public string GetFullLogFileName() private string GetNewRelicLogDirectory() { - var newRelicLogDirectory = ConfigLoaderHelpers.GetEnvironmentVar("NEWRELIC_LOG_DIRECTORY"); + // TODO: remove legacy env var name in v11 + var newRelicLogDirectory = ConfigLoaderHelpers.GetEnvironmentVar("NEW_RELIC_LOG_DIRECTORY", "NEWRELIC_LOG_DIRECTORY"); if (newRelicLogDirectory != null && _checkDirectoryExists(newRelicLogDirectory)) return _getFullPath(newRelicLogDirectory); return newRelicLogDirectory; diff --git a/src/Agent/NewRelic/Agent/Core/Config/ConfigurationLoader.cs b/src/Agent/NewRelic/Agent/Core/Config/ConfigurationLoader.cs index 624b832042..36519ac9da 100644 --- a/src/Agent/NewRelic/Agent/Core/Config/ConfigurationLoader.cs +++ b/src/Agent/NewRelic/Agent/Core/Config/ConfigurationLoader.cs @@ -8,6 +8,7 @@ using NewRelic.Agent.Core.SharedInterfaces; using System; using System.IO; +using System.Linq; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; @@ -569,9 +570,14 @@ public static class ConfigLoaderHelpers // configuration logic to use the same environment variable logic. public static IEnvironment EnvironmentVariableProxy = new SharedInterfaces.Environment(); - public static string GetEnvironmentVar(string name) + public static string GetEnvironmentVar(params string[] environmentVariableNames) { - return EnvironmentVariableProxy.GetEnvironmentVariable(name); + var result = (environmentVariableNames ?? Enumerable.Empty()) + .Select(EnvironmentVariableProxy.GetEnvironmentVariable) + .FirstOrDefault(value => value != null); + + // needs to return null instead of empty string + return result == string.Empty ? null : result; } public static string GetOverride(string name, string fallback) diff --git a/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs b/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs index 9670e798d8..5fe500218e 100644 --- a/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs @@ -211,8 +211,9 @@ public virtual string AgentLicenseKey if (_agentLicenseKey != null) return _agentLicenseKey; + // TODO: remove legacy env var name in v11 _agentLicenseKey = _configurationManagerStatic.GetAppSetting(Constants.AppSettingsLicenseKey) - ?? EnvironmentOverrides(_localConfiguration.service.licenseKey, "NEW_RELIC_LICENSE_KEY", "NEWRELIC_LICENSEKEY"); + ?? EnvironmentOverrides(_localConfiguration.service.licenseKey, "NEW_RELIC_LICENSE_KEY", "NEWRELIC_LICENSEKEY"); if (_agentLicenseKey != null) _agentLicenseKey = _agentLicenseKey.Trim(); @@ -2509,10 +2510,7 @@ private static T ServerOverrides(T server, T local) where T : class private IEnumerable EnvironmentOverrides(IEnumerable local, params string[] environmentVariableNames) { - var envValue = (environmentVariableNames ?? Enumerable.Empty()) - .Select(_environment.GetEnvironmentVariable) - .Where(value => value != null) - .FirstOrDefault(); + var envValue = _environment.GetEnvironmentVariableFromList(environmentVariableNames ?? []); // took this approach to eliminate a null object issue when combining the different calls together. Also a bit easier to read. if (string.IsNullOrWhiteSpace(envValue)) @@ -2533,10 +2531,7 @@ private string EnvironmentOverrides(string local, params string[] environmentVar public static string EnvironmentOverrides(IEnvironment environment, string local, params string[] environmentVariableNames) { - var envValue = (environmentVariableNames ?? Enumerable.Empty()) - .Select(environment.GetEnvironmentVariable) - .Where(value => !string.IsNullOrWhiteSpace(value)) - .FirstOrDefault(); // returns null if no env var found or if enumerable is empty + var envValue = environment.GetEnvironmentVariableFromList(environmentVariableNames ?? []); // if we get a null, we use local - should not get whitespace if (string.IsNullOrWhiteSpace(envValue)) @@ -2549,9 +2544,7 @@ public static string EnvironmentOverrides(IEnvironment environment, string local private uint? EnvironmentOverrides(uint? local, params string[] environmentVariableNames) { - var env = environmentVariableNames - .Select(_environment.GetEnvironmentVariable) - .FirstOrDefault(value => value != null); + var env = _environment.GetEnvironmentVariableFromList(environmentVariableNames ?? []); return uint.TryParse(env, out uint parsedValue) ? parsedValue : local; } @@ -2563,18 +2556,14 @@ public static string EnvironmentOverrides(IEnvironment environment, string local public static int? EnvironmentOverrides(IEnvironment environment, int? local, params string[] environmentVariableNames) { - var env = environmentVariableNames - .Select(environment.GetEnvironmentVariable) - .FirstOrDefault(value => value != null); + var env = environment.GetEnvironmentVariableFromList(environmentVariableNames ?? []); return int.TryParse(env, out int parsedValue) ? parsedValue : local; } private double? EnvironmentOverrides(double? local, params string[] environmentVariableNames) { - var env = environmentVariableNames - .Select(_environment.GetEnvironmentVariable) - .FirstOrDefault(value => value != null); + var env = _environment.GetEnvironmentVariableFromList(environmentVariableNames ?? []); return double.TryParse(env, out double parsedValue) ? parsedValue : local; } @@ -2586,9 +2575,7 @@ private bool EnvironmentOverrides(bool local, params string[] environmentVariabl public static bool EnvironmentOverrides(IEnvironment environment, bool local, params string[] environmentVariableNames) { - var env = environmentVariableNames - .Select(environment.GetEnvironmentVariable) - .FirstOrDefault(value => value != null); + var env = environment.GetEnvironmentVariableFromList(environmentVariableNames ?? []); if (env != null) { @@ -3003,7 +2990,8 @@ public static string GetLoggingLevelValue(IEnvironment environment, configuratio var logLevel = "off"; if (isLoggingEnabled) { - logLevel = EnvironmentOverrides(environment, localLogConfiguration.level, "NEWRELIC_LOG_LEVEL").ToUpper(); + // TODO: remove legacy env var name in v11 + logLevel = EnvironmentOverrides(environment, localLogConfiguration.level, "NEW_RELIC_LOG_LEVEL", "NEWRELIC_LOG_LEVEL").ToUpper(); } return logLevel; diff --git a/src/Agent/NewRelic/Agent/Core/SharedInterfaces/Environment.cs b/src/Agent/NewRelic/Agent/Core/SharedInterfaces/Environment.cs index acd0d7f840..cff988370e 100644 --- a/src/Agent/NewRelic/Agent/Core/SharedInterfaces/Environment.cs +++ b/src/Agent/NewRelic/Agent/Core/SharedInterfaces/Environment.cs @@ -4,6 +4,8 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; +using NewRelic.Agent.Extensions.Logging; namespace NewRelic.Agent.Core.SharedInterfaces { @@ -19,11 +21,34 @@ public string GetEnvironmentVariable(string variable) return System.Environment.GetEnvironmentVariable(variable); } + public string GetEnvironmentVariableFromList(params string[] variables) + { + var envValue = (variables ?? Enumerable.Empty()) + .Select(v => GetEnvironmentVariableInternal(v)) + .FirstOrDefault(value => value != null); + + return envValue == string.Empty ? null : envValue; + } + public string GetEnvironmentVariable(string variable, EnvironmentVariableTarget environmentVariableTarget) { return System.Environment.GetEnvironmentVariable(variable, environmentVariableTarget); } + private string GetEnvironmentVariableInternal(string variable, EnvironmentVariableTarget environmentVariableTarget = EnvironmentVariableTarget.Process) + { + var value = System.Environment.GetEnvironmentVariable(variable, environmentVariableTarget); + + // TODO: remove in v11 + if (value != null && variable.StartsWith("NEWRELIC_", StringComparison.OrdinalIgnoreCase)) + { + var preferredVariableName = variable.ToUpper().Replace("NEWRELIC_", "NEW_RELIC_"); + Log.Warn($"The environment variable {variable} is deprecated and will be removed in version 11. Please use {preferredVariableName} instead."); + } + + return value; + } + public Dictionary GetEnvironmentVariablesWithPrefix(string prefix) { var environmentVariables = System.Environment.GetEnvironmentVariables(); diff --git a/src/Agent/NewRelic/Agent/Core/SharedInterfaces/EnvironmentMock.cs b/src/Agent/NewRelic/Agent/Core/SharedInterfaces/EnvironmentMock.cs index e0dddf9bc6..345824c24e 100644 --- a/src/Agent/NewRelic/Agent/Core/SharedInterfaces/EnvironmentMock.cs +++ b/src/Agent/NewRelic/Agent/Core/SharedInterfaces/EnvironmentMock.cs @@ -30,5 +30,10 @@ public Dictionary GetEnvironmentVariablesWithPrefix(string prefi { return _emptyEnvVarDictionary; } + + public string GetEnvironmentVariableFromList(params string[] variables) + { + return null; + } } } diff --git a/src/Agent/NewRelic/Agent/Core/SharedInterfaces/IEnvironment.cs b/src/Agent/NewRelic/Agent/Core/SharedInterfaces/IEnvironment.cs index 0caa4c64c1..47c7c65c8c 100644 --- a/src/Agent/NewRelic/Agent/Core/SharedInterfaces/IEnvironment.cs +++ b/src/Agent/NewRelic/Agent/Core/SharedInterfaces/IEnvironment.cs @@ -43,5 +43,11 @@ public interface IEnvironment /// The caller does not have the required permission to perform this operation. Dictionary GetEnvironmentVariablesWithPrefix(string prefix); + /// + /// Retrieves the value of an environment variable, searching the provided list of variables in order. The first variable found is returned. + /// + /// A list of one or more environment variable names to search, in order of preference + /// The value of the first matching environment variable, if found, otherwise null + string GetEnvironmentVariableFromList(params string[] variables); } } diff --git a/tests/Agent/IntegrationTests/IntegrationTestHelpers/RemoteServiceFixtures/AzureFuncTool.cs b/tests/Agent/IntegrationTests/IntegrationTestHelpers/RemoteServiceFixtures/AzureFuncTool.cs index 8bf87e235b..688060583f 100644 --- a/tests/Agent/IntegrationTests/IntegrationTestHelpers/RemoteServiceFixtures/AzureFuncTool.cs +++ b/tests/Agent/IntegrationTests/IntegrationTestHelpers/RemoteServiceFixtures/AzureFuncTool.cs @@ -58,19 +58,19 @@ public override void Start(string commandLineArguments, Dictionary(); Mock.Arrange(() => collectorWireFactory.GetCollectorWire(null, Arg.IsAny())).IgnoreArguments().Returns(_collectorWire); - Mock.Arrange(() => environment.GetEnvironmentVariable("NEW_RELIC_SECURITY_POLICIES_TOKEN")).Returns("ffff-fbff-ffff-ffff"); + Mock.Arrange(() => environment.GetEnvironmentVariableFromList("NEW_RELIC_SECURITY_POLICIES_TOKEN")).Returns("ffff-fbff-ffff-ffff"); _connectRawData = string.Empty; _receivedSecurityPoliciesException = false; diff --git a/tests/Agent/UnitTests/CompositeTests/EnvironmentTests.cs b/tests/Agent/UnitTests/CompositeTests/EnvironmentTests.cs new file mode 100644 index 0000000000..5aa4e22611 --- /dev/null +++ b/tests/Agent/UnitTests/CompositeTests/EnvironmentTests.cs @@ -0,0 +1,52 @@ +// Copyright 2020 New Relic, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +using NUnit.Framework; + +namespace CompositeTests +{ + [TestFixture] + public class EnvironmentTests + { + private NewRelic.Agent.Core.SharedInterfaces.Environment _env; + + [SetUp] + public void Setup() + { + System.Environment.SetEnvironmentVariable("NEWRELIC_HOME", null); + System.Environment.SetEnvironmentVariable("NEW_RELIC_HOME", null); + + _env = new NewRelic.Agent.Core.SharedInterfaces.Environment(); + } + + [TearDown] + public void TearDown() + { + System.Environment.SetEnvironmentVariable("NEWRELIC_HOME", null); + System.Environment.SetEnvironmentVariable("NEW_RELIC_HOME", null); + } + + // TODO: remove in v11 + [Test] + public void GetEnvironmentVariable_Supports_LegacyNaming() + { + System.Environment.SetEnvironmentVariable("NEWRELIC_HOME", "legacy"); + + var result = _env.GetEnvironmentVariableFromList("NEW_RELIC_HOME", "NEWRELIC_HOME"); + + Assert.That(result, Is.EqualTo("legacy")); + } + + // TODO: remove in v11 + [Test] + public void GetEnvironmentVariable_Prefers_ModernNaming_IfBothAreSpecified() + { + System.Environment.SetEnvironmentVariable("NEWRELIC_HOME", "legacy"); + System.Environment.SetEnvironmentVariable("NEW_RELIC_HOME", "modern"); + + var result = _env.GetEnvironmentVariableFromList("NEW_RELIC_HOME", "NEWRELIC_HOME"); + + Assert.That(result, Is.EqualTo("modern")); + } + } +} diff --git a/tests/Agent/UnitTests/Core.UnitTest/Config/BootstrapLogConfigurationTests.cs b/tests/Agent/UnitTests/Core.UnitTest/Config/BootstrapLogConfigurationTests.cs index 8b3524ba49..5ebe3f8f11 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Config/BootstrapLogConfigurationTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Config/BootstrapLogConfigurationTests.cs @@ -35,7 +35,9 @@ public void SetUp() // together. var environmentMock = Mock.Create(); Mock.Arrange(() => environmentMock.GetEnvironmentVariable(Arg.IsAny())).Returns(MockGetEnvironmentVar); + Mock.Arrange(() => environmentMock.GetEnvironmentVariableFromList(Arg.IsAny())).Returns(MockGetEnvironmentVarFromList); ConfigLoaderHelpers.EnvironmentVariableProxy = environmentMock; + AgentInstallConfiguration.EnvironmentVariableProxy = environmentMock; ClearEnvironmentVars(); _directoryToFullPathMapping.Clear(); @@ -151,6 +153,21 @@ public void TestLogLevelIsOffWhenNotEnabled() [TestCase("error", "info", ExpectedResult = "ERROR")] [TestCase("warn", "debug", ExpectedResult = "WARN")] public string TestLogLevelValue(string environmentValue, string localConfigValue) + { + SetEnvironmentVar("NEW_RELIC_LOG_LEVEL", environmentValue); + _localConfiguration.log.level = localConfigValue; + + var config = CreateLogConfig(); + + return config.LogLevel; + } + + //TODO: remove in v11 + [TestCase(null, "info", ExpectedResult = "INFO")] + [TestCase(null, "debug", ExpectedResult = "DEBUG")] + [TestCase("error", "info", ExpectedResult = "ERROR")] + [TestCase("warn", "debug", ExpectedResult = "WARN")] + public string TestLogLevelValue_UsingLegacyEnvVarName(string environmentValue, string localConfigValue) { SetEnvironmentVar("NEWRELIC_LOG_LEVEL", environmentValue); _localConfiguration.log.level = localConfigValue; @@ -209,7 +226,7 @@ public void LogRollingStrategyValueIsCached() [TestCase("env", "local", "env")] public void LogFileNameUsesExpectedPath(string environmentValue, string localConfigValue, string expectedPath) { - SetEnvironmentVar("NEWRELIC_LOG_DIRECTORY", environmentValue); + SetEnvironmentVar("NEW_RELIC_LOG_DIRECTORY", environmentValue); _localConfiguration.log.directory = localConfigValue; var config = CreateLogConfig(); @@ -227,7 +244,7 @@ public void LogFileNameUsesExpectedPath(string environmentValue, string localCon [Test] public void LogFileFromEnvironmentShouldUseFullPathIfExists() { - SetEnvironmentVar("NEWRELIC_LOG_DIRECTORY", "env"); + SetEnvironmentVar("NEW_RELIC_LOG_DIRECTORY", "env"); _localConfiguration.log.directory = "local"; _directoryToFullPathMapping["env"] = "fullpathenv"; @@ -363,6 +380,15 @@ private string MockGetEnvironmentVar(string name) return null; } + private string MockGetEnvironmentVarFromList(string[] names) + { + foreach (var name in names) + { + if (_envVars.TryGetValue(name, out var value)) return value; + } + return null; + } + private bool DirectoryExists(string path) { return _directoryToFullPathMapping.ContainsKey(path); diff --git a/tests/Agent/UnitTests/Core.UnitTest/Configuration/DefaultConfigurationTests.cs b/tests/Agent/UnitTests/Core.UnitTest/Configuration/DefaultConfigurationTests.cs index 71d0ac571e..13e1b2ef65 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Configuration/DefaultConfigurationTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Configuration/DefaultConfigurationTests.cs @@ -214,7 +214,7 @@ public void TransactionEventsMaxSamplesStoredOverriddenByEventHarvestConfig() [TestCase(null, null, null, ExpectedResult = 10000)] public int TransactionEventsMaxSamplesStoredOverriddenByEnvironment(string environmentSetting, int? localSetting, int? serverSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("MAX_TRANSACTION_SAMPLES_STORED")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("MAX_TRANSACTION_SAMPLES_STORED")).Returns(environmentSetting); if (localSetting != null) { @@ -263,7 +263,7 @@ public void DisableServerConfigIsFalseByDefault() [TestCase("false", ExpectedResult = false)] public bool DisableServerConfigSetFromEnvironment(string environment) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_IGNORE_SERVER_SIDE_CONFIG")).Returns(environment); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_IGNORE_SERVER_SIDE_CONFIG")).Returns(environment); return _defaultConfig.IgnoreServerSideConfiguration; } @@ -368,7 +368,7 @@ public bool InstrumentationLoggingEnabledSetFromLocal(bool local) [TestCase(null, false, ExpectedResult = false)] public bool SendDataOnExitIsOverriddenByEnvironment(string environmentSetting, bool localSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_SEND_DATA_ON_EXIT")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_SEND_DATA_ON_EXIT")).Returns(environmentSetting); _localConfig.service.sendDataOnExit = localSetting; return _defaultConfig.CollectorSendDataOnExit; } @@ -378,7 +378,7 @@ public bool SendDataOnExitIsOverriddenByEnvironment(string environmentSetting, b [TestCase(null, 500f, ExpectedResult = 500f)] public float SendDataOnExitThresholdIsOverriddenByEnvironment(string environmentSetting, float localSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_SEND_DATA_ON_EXIT_THRESHOLD_MS")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_SEND_DATA_ON_EXIT_THRESHOLD_MS")).Returns(environmentSetting); _localConfig.service.sendDataOnExitThreshold = localSetting; return _defaultConfig.CollectorSendDataOnExitThreshold; } @@ -697,7 +697,7 @@ public bool HighSecuritySetFromLocalOverridesServer(bool local, bool? server) [TestCase(null, null, ExpectedResult = false)] public bool HighSecuritySetFromEnvironmentOverridesLocal(bool? localConfigValue, string envConfigValue) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_HIGH_SECURITY")).Returns(envConfigValue); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_HIGH_SECURITY")).Returns(envConfigValue); if (localConfigValue.HasValue) { @@ -835,7 +835,7 @@ public void WhenTransactionTraceThresholdSetToApdexfThenEqualsApdextTimes4() public void ApdexT_SetFromEnvironmentVariable_WhenInServerlessMode() { // set NEW_RELIC_APDEX_T environment variable - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_APDEX_T")).Returns("1.234"); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_APDEX_T")).Returns("1.234"); Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); @@ -1010,7 +1010,7 @@ public string[] ExpectedStatusCodesSetFromLocalServerAndEnvironmentOverrides(str { _serverConfig.RpmConfig.ErrorCollectorExpectedStatusCodes = server; _localConfig.errorCollector.expectedStatusCodes = (local); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERROR_CODES")).Returns(env); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERROR_CODES")).Returns(env); CreateDefaultConfiguration(); @@ -1029,7 +1029,7 @@ public string[] IgnoredStatusCodesSetFromLocalServerAndEnvironmentOverrides(floa { _serverConfig.RpmConfig.ErrorCollectorStatusCodesToIgnore = server; _localConfig.errorCollector.ignoreStatusCodes.code = (local.ToList()); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES")).Returns(env); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES")).Returns(env); CreateDefaultConfiguration(); @@ -1105,7 +1105,7 @@ public string IgnoreAndExpectedMessagesSetFromLocalAndServerOverrides(bool serve [TestCase("ABCD", "bGxs", " ", null, ExpectedResult = "ABCD")] public string Encrypting_Decrypting_ProxyPassword_Tests(string password, string passwordObfuscated, string localConfigObscuringKey, string envObscuringKey) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_CONFIG_OBSCURING_KEY")).Returns(envObscuringKey); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_CONFIG_OBSCURING_KEY")).Returns(envObscuringKey); _localConfig.service.proxy.password = password; _localConfig.service.obscuringKey = localConfigObscuringKey; @@ -1124,7 +1124,7 @@ public string Encrypting_Decrypting_ProxyPassword_Tests(string password, string [TestCase("", "", ExpectedResult = "")] public string ProxyHost_Tests(string localProxyHost, string envProxyHost) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_PROXY_HOST")).Returns(envProxyHost); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_PROXY_HOST")).Returns(envProxyHost); _localConfig.service.proxy.host = localProxyHost; @@ -1141,7 +1141,7 @@ public string ProxyHost_Tests(string localProxyHost, string envProxyHost) [TestCase("", "", ExpectedResult = "")] public string ProxyUriPath_Tests(string localProxyUriPath, string envProxyUriPath) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_PROXY_URI_PATH")).Returns(envProxyUriPath); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_PROXY_URI_PATH")).Returns(envProxyUriPath); _localConfig.service.proxy.uriPath = localProxyUriPath; @@ -1155,7 +1155,7 @@ public string ProxyUriPath_Tests(string localProxyUriPath, string envProxyUriPat [TestCase(1234, "bob", ExpectedResult = 1234)] public int ProxyPort_Tests(int localProxyPort, string envProxyPort) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_PROXY_PORT")).Returns(envProxyPort); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_PROXY_PORT")).Returns(envProxyPort); _localConfig.service.proxy.port = localProxyPort; @@ -1172,7 +1172,7 @@ public int ProxyPort_Tests(int localProxyPort, string envProxyPort) [TestCase("", "", ExpectedResult = "")] public string ProxyUsername_Tests(string localProxyUser, string envProxyUser) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_PROXY_USER")).Returns(envProxyUser); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_PROXY_USER")).Returns(envProxyUser); _localConfig.service.proxy.user = localProxyUser; @@ -1189,7 +1189,7 @@ public string ProxyUsername_Tests(string localProxyUser, string envProxyUser) [TestCase("", "", ExpectedResult = "")] public string ProxyPassword_Tests(string localProxyPassword, string envProxyPassword) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_PROXY_PASS")).Returns(envProxyPassword); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_PROXY_PASS")).Returns(envProxyPassword); _localConfig.service.proxy.password = localProxyPassword; @@ -1206,7 +1206,7 @@ public string ProxyPassword_Tests(string localProxyPassword, string envProxyPass [TestCase("", "", ExpectedResult = "")] public string ProxyDomain_Tests(string localProxyDomain, string envProxyDomain) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_PROXY_DOMAIN")).Returns(envProxyDomain); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_PROXY_DOMAIN")).Returns(envProxyDomain); _localConfig.service.proxy.domain = localProxyDomain; @@ -1418,7 +1418,7 @@ public string LabelsAreOverriddenProperlyAndAreCached(string appConfigValue, str { _localConfig.labels = local; Mock.Arrange(() => _configurationManagerStatic.GetAppSetting(Constants.AppSettingsLabels)).Returns(appConfigValue); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_LABELS")).Returns(environment); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_LABELS")).Returns(environment); // call Labels accessor multiple times to verify caching behavior string result = _defaultConfig.Labels; @@ -1441,32 +1441,22 @@ public string LabelsAreOverriddenProperlyAndAreCached(string appConfigValue, str public string CustomHostEnvironmentOverridesLocal(string environment, string local) { _localConfig.service.host = local; - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_HOST")).Returns(environment); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_HOST")).Returns(environment); return _defaultConfig.CollectorHost; } - [TestCase(null, null, null, null, ExpectedResult = null)] - [TestCase(null, null, null, "foo", ExpectedResult = "foo")] - [TestCase(null, null, "foo", null, ExpectedResult = "foo")] - [TestCase(null, "foo", null, null, ExpectedResult = "foo")] - [TestCase(null, null, "foo", "bar", ExpectedResult = "foo")] - [TestCase(null, "foo", null, "bar", ExpectedResult = "foo")] - [TestCase(null, "foo", "bar", null, ExpectedResult = "foo")] - [TestCase(null, "foo", "bar", "baz", ExpectedResult = "foo")] - [TestCase("foo", null, null, null, ExpectedResult = "foo")] - [TestCase("foo", null, null, "foo", ExpectedResult = "foo")] - [TestCase("foo", null, "foo", null, ExpectedResult = "foo")] - [TestCase("foo", "foo", null, null, ExpectedResult = "foo")] - [TestCase("foo", null, "foo", "bar", ExpectedResult = "foo")] - [TestCase("foo", "foo", null, "bar", ExpectedResult = "foo")] - [TestCase("foo", "foo", "bar", null, ExpectedResult = "foo")] - [TestCase("foo", "foo", "bar", "baz", ExpectedResult = "foo")] - public string LicenseKeyEnvironmentOverridesLocal(string appSettingEnvironmentName, string newEnvironmentName, string legacyEnvironmentName, string local) + [TestCase(null, null, null, ExpectedResult = null)] + [TestCase(null, "foo", null, ExpectedResult = "foo")] + [TestCase("foo", null, null, ExpectedResult = "foo")] + [TestCase("foo", null, "foo", ExpectedResult = "foo")] + [TestCase("foo", "foo", null, ExpectedResult = "foo")] + [TestCase("foo", "foo", "bar", ExpectedResult = "foo")] + public string LicenseKeyEnvironmentOverridesLocal(string appSettingEnvironmentName, string newEnvironmentName, string local) { _localConfig.service.licenseKey = local; - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_LICENSE_KEY")).Returns(newEnvironmentName); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEWRELIC_LICENSEKEY")).Returns(legacyEnvironmentName); + // TODO: remove legacy name in v11 + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_LICENSE_KEY", "NEWRELIC_LICENSEKEY")).Returns(newEnvironmentName); Mock.Arrange(() => _configurationManagerStatic.GetAppSetting(Constants.AppSettingsLicenseKey)).Returns(appSettingEnvironmentName); return _defaultConfig.AgentLicenseKey; @@ -1482,7 +1472,7 @@ public bool SpanEventsEnabledEnvironmentOverridesLocal(bool localSpanEvents, str _localConfig.spanEvents.enabled = localSpanEvents; _localConfig.distributedTracing.enabled = true; - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_SPAN_EVENTS_ENABLED")).Returns(environmentSpanEvents); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_SPAN_EVENTS_ENABLED")).Returns(environmentSpanEvents); return _defaultConfig.SpanEventsEnabled; } @@ -1496,7 +1486,7 @@ public bool DistributedTracingEnabledEnvironmentOverridesLocal(bool localDistrib { _localConfig.distributedTracing.enabled = localDistributedTracing; - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_DISTRIBUTED_TRACING_ENABLED")).Returns(environmentDistributedTracing); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_DISTRIBUTED_TRACING_ENABLED")).Returns(environmentDistributedTracing); return _defaultConfig.DistributedTracingEnabled; } @@ -1511,7 +1501,7 @@ public bool DistributedTracingEnabledEnvironmentOverridesLocal(bool localDistrib [TestCase("true", ExpectedResult = true)] public bool AppDomainCachingDisabledWorksAsExpected(string environmentAppDomainCachingDisabled) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_DISABLE_APPDOMAIN_CACHING")).Returns(environmentAppDomainCachingDisabled); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_DISABLE_APPDOMAIN_CACHING")).Returns(environmentAppDomainCachingDisabled); return _defaultConfig.AppDomainCachingDisabled; } @@ -1525,7 +1515,7 @@ public bool DisableSamplersEnvironmentOverridesLocal(bool localDisableSamplers, { _localConfig.application.disableSamplers = localDisableSamplers; - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_DISABLE_SAMPLERS")).Returns(environmentDisableSamplers); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_DISABLE_SAMPLERS")).Returns(environmentDisableSamplers); return _defaultConfig.DisableSamplers; } @@ -1780,7 +1770,7 @@ public void TransactionNameWhitelistRulesPullsValueFromServerConfiguration() [TestCase(null, "vietnameseCoconut", ExpectedResult = "vietnameseCoconut")] public string ProcessHostDisplayNameIsSetFromLocalConfigurationAndEnvironmentVariable(string localConfigurationValue, string environmentVariableValue) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_PROCESS_HOST_DISPLAY_NAME")).Returns(environmentVariableValue); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_PROCESS_HOST_DISPLAY_NAME")).Returns(environmentVariableValue); Mock.Arrange(() => _dnsStatic.GetHostName()).Returns("coconut"); _localConfig.processHost.displayName = localConfigurationValue; @@ -2438,7 +2428,7 @@ public void PrimaryApplicationIdValueIsSetFromEnvironmentVariable_WhenInServerle { // Arrange Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_PRIMARY_APPLICATION_ID")).Returns("PrimaryApplicationIdValue"); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_PRIMARY_APPLICATION_ID")).Returns("PrimaryApplicationIdValue"); // Act var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); @@ -2451,7 +2441,7 @@ public void TrustedAccountKeyValueIsSetFromEnvironmentVariable_WhenInServerlessM { // Arrange Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_TRUSTED_ACCOUNT_KEY")).Returns("TrustedAccountKeyValue"); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_TRUSTED_ACCOUNT_KEY")).Returns("TrustedAccountKeyValue"); // Act var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); @@ -2464,7 +2454,7 @@ public void AccountIdValueIsSetFromEnvironmentVariable_WhenInServerlessMode() { // Arrange Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_ACCOUNT_ID")).Returns("AccountIdValue"); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_ACCOUNT_ID")).Returns("AccountIdValue"); // Act var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); @@ -2631,7 +2621,7 @@ public void SpanEventsAttributesExclude(string[] attributes, string[] expectedRe [TestCase(null, -623, ExpectedResult = -623)] public int InfiniteTracing_SpanQueueSize(string envConfigValue, int? localConfigValue) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_QUEUE_SIZE")).Returns(envConfigValue); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_QUEUE_SIZE")).Returns(envConfigValue); if (localConfigValue.HasValue) { @@ -2706,7 +2696,7 @@ public void InfiniteTracing_TraceObserver public int InfiniteTracing_TimeoutData(string envConfigVal, string appSettingsValue) { _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingTimeoutSend", value = appSettingsValue }); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_INFINITE_TRACING_TIMEOUT_SEND")).Returns(envConfigVal); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_TIMEOUT_SEND")).Returns(envConfigVal); var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); @@ -2724,7 +2714,7 @@ public int InfiniteTracing_TimeoutData(string envConfigVal, string appSettingsVa public int InfiniteTracing_TimeoutConnect(string envConfigVal, string appSettingsValue) { _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingTimeoutConnect", value = appSettingsValue }); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_INFINITE_TRACING_TIMEOUT_CONNECT")).Returns(envConfigVal); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_TIMEOUT_CONNECT")).Returns(envConfigVal); var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); @@ -2769,7 +2759,7 @@ public int InfiniteTracing_TimeoutConnect(string envConfigVal, string appSetting public int InfiniteTracing_SpanBatchSize(string envConfigVal, string appSettingVal) { _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingSpanEventsBatchSize", value = appSettingVal }); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_BATCH_SIZE")).Returns(envConfigVal); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_BATCH_SIZE")).Returns(envConfigVal); var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); @@ -2792,7 +2782,7 @@ public int InfiniteTracing_SpanBatchSize(string envConfigVal, string appSettingV public int InfiniteTracing_SpanPartitionCount(string envConfigVal, string appSettingVal) { _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingSpanEventsPartitionCount", value = appSettingVal }); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_PARTITION_COUNT")).Returns(envConfigVal); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_PARTITION_COUNT")).Returns(envConfigVal); var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); @@ -2836,7 +2826,7 @@ public void InfiniteTracing_SpanStreamsCount } _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingSpanEventsStreamsCount", value = appSettingsValue }); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_STREAMS_COUNT")).Returns(envConfigVal); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_STREAMS_COUNT")).Returns(envConfigVal); var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); @@ -2850,7 +2840,7 @@ public void InfiniteTracing_SpanStreamsCount [TestCase(null, null, ExpectedResult = true)] public bool InfiniteTracing_Compression(string envConfigVal, bool? localConfigVal) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_INFINITE_TRACING_COMPRESSION")).Returns(envConfigVal); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_COMPRESSION")).Returns(envConfigVal); if (localConfigVal.HasValue) { @@ -2882,7 +2872,7 @@ public bool InfiniteTracing_Compression(string envConfigVal, bool? localConfigVa [TestCase(null, null, ExpectedResult = true)] // true by default test public bool UtilizationDetectKubernetesConfigurationWorksProperly(string environmentSetting, bool? localSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_UTILIZATION_DETECT_KUBERNETES")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_UTILIZATION_DETECT_KUBERNETES")).Returns(environmentSetting); if (localSetting.HasValue) { @@ -2906,7 +2896,7 @@ public bool UtilizationDetectKubernetesConfigurationWorksProperly(string environ [TestCase(null, null, ExpectedResult = true)] // true by default test public bool UtilizationDetectAwsConfigurationWorksProperly(string environmentSetting, bool? localSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_UTILIZATION_DETECT_AWS")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_UTILIZATION_DETECT_AWS")).Returns(environmentSetting); if (localSetting.HasValue) { @@ -2930,7 +2920,7 @@ public bool UtilizationDetectAwsConfigurationWorksProperly(string environmentSet [TestCase(null, null, ExpectedResult = true)] // true by default test public bool UtilizationDetectAzureConfigurationWorksProperly(string environmentSetting, bool? localSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_UTILIZATION_DETECT_AZURE")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_UTILIZATION_DETECT_AZURE")).Returns(environmentSetting); if (localSetting.HasValue) { @@ -2954,7 +2944,7 @@ public bool UtilizationDetectAzureConfigurationWorksProperly(string environmentS [TestCase(null, null, ExpectedResult = true)] // true by default test public bool UtilizationDetectPcfConfigurationWorksProperly(string environmentSetting, bool? localSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_UTILIZATION_DETECT_PCF")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_UTILIZATION_DETECT_PCF")).Returns(environmentSetting); if (localSetting.HasValue) { @@ -2978,7 +2968,7 @@ public bool UtilizationDetectPcfConfigurationWorksProperly(string environmentSet [TestCase(null, null, ExpectedResult = true)] // true by default test public bool UtilizationDetectGcpConfigurationWorksProperly(string environmentSetting, bool? localSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_UTILIZATION_DETECT_GCP")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_UTILIZATION_DETECT_GCP")).Returns(environmentSetting); if (localSetting.HasValue) { @@ -3002,7 +2992,7 @@ public bool UtilizationDetectGcpConfigurationWorksProperly(string environmentSet [TestCase(null, null, ExpectedResult = true)] // true by default test public bool UtilizationDetectDockerConfigurationWorksProperly(string environmentSetting, bool? localSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_UTILIZATION_DETECT_DOCKER")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_UTILIZATION_DETECT_DOCKER")).Returns(environmentSetting); if (localSetting.HasValue) { @@ -3040,8 +3030,8 @@ public bool UtilizationDetectDockerConfigurationWorksProperly(string environment [TestCase(null, null, false, ExpectedResult = false)] // true by default test public bool UtilizationDetectAzureFunctionConfigurationWorksProperly(string environmentSetting, bool? localSetting, bool azureFunctionModeEnabled) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_AZURE_FUNCTION_MODE_ENABLED")).Returns(azureFunctionModeEnabled.ToString()); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_UTILIZATION_DETECT_AZURE_FUNCTION")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_AZURE_FUNCTION_MODE_ENABLED")).Returns(azureFunctionModeEnabled.ToString()); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_UTILIZATION_DETECT_AZURE_FUNCTION")).Returns(environmentSetting); if (localSetting.HasValue) { @@ -3188,7 +3178,7 @@ public IEnumerable ApplicationLogging_ContextDataInclude_IsOverriddenByE if (environment != null) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CONTEXT_DATA_INCLUDE")).Returns(environment); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CONTEXT_DATA_INCLUDE")).Returns(environment); } return _defaultConfig.ContextDataInclude; @@ -3208,7 +3198,7 @@ public IEnumerable ApplicationLogging_ContextDataExclude_IsOverriddenByE if (environment != null) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CONTEXT_DATA_EXCLUDE")).Returns(environment); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CONTEXT_DATA_EXCLUDE")).Returns(environment); } return _defaultConfig.ContextDataExclude; @@ -3493,7 +3483,7 @@ public void CustomEventsMaxSamplesStoredOverriddenByEventHarvestConfig() [TestCase(null, null, null, ExpectedResult = 30000)] public int CustomEventsMaxSamplesStoredOverriddenByEnvironment(string environmentSetting, int? localSetting, int? serverSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("MAX_EVENT_SAMPLES_STORED")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("MAX_EVENT_SAMPLES_STORED")).Returns(environmentSetting); if (localSetting != null) { @@ -3548,7 +3538,7 @@ public void CustomEventsMaxSamplesOf0ShouldDisableCustomEvents() public string SecurityPoliciesTokenReturned(string environmentValue, string localConfigValue) { _localConfig.securityPoliciesToken = localConfigValue; - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_SECURITY_POLICIES_TOKEN")) + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_SECURITY_POLICIES_TOKEN")) .Returns(environmentValue); return _defaultConfig.SecurityPoliciesToken; } @@ -3563,7 +3553,7 @@ public string SecurityPoliciesTokenReturned(string environmentValue, string loca public bool SecurityPoliciesTokenExists(string environmentValue, string localConfigValue) { _localConfig.securityPoliciesToken = localConfigValue; - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_SECURITY_POLICIES_TOKEN")) + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_SECURITY_POLICIES_TOKEN")) .Returns(environmentValue); _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); @@ -3610,7 +3600,7 @@ public bool AspNetCore6PlusBrowserInjectionTests(string localConfigValue) [TestCase(null, null, ExpectedResult = false)] // false by default test public bool GloballyForceNewTransactionConfigurationTests(string environmentSetting, bool? localSetting) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_FORCE_NEW_TRANSACTION_ON_NEW_THREAD")).Returns(environmentSetting); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_FORCE_NEW_TRANSACTION_ON_NEW_THREAD")).Returns(environmentSetting); if (localSetting.HasValue) { @@ -3646,7 +3636,7 @@ public void CodeLevelMetricsAreEnabledByDefault() [TestCase(null, null, ExpectedResult = true)] public bool ShouldCodeLevelMetricsBeEnabled(bool? localConfigValue, string envConfigValue) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_CODE_LEVEL_METRICS_ENABLED")).Returns(envConfigValue); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_CODE_LEVEL_METRICS_ENABLED")).Returns(envConfigValue); if (localConfigValue.HasValue) { @@ -4053,7 +4043,7 @@ public void AiMonitoringEnabledByLocalConfig() [Test] public void AiMonitoringEnabledByEnvironmentVariable() { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_AI_MONITORING_ENABLED")).Returns("true"); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_AI_MONITORING_ENABLED")).Returns("true"); Assert.That(_defaultConfig.AiMonitoringEnabled, Is.True); } [Test] @@ -4081,7 +4071,7 @@ public void AiMonitoringStreamingEnabledByDefaultWhenAiMonitoringEnabled() public void AiMonitoringStreamingDisabledByEnvironmentVariableWhenAiMonitoringEnabled() { _localConfig.aiMonitoring.enabled = true; - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_AI_MONITORING_STREAMING_ENABLED")).Returns("false"); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_AI_MONITORING_STREAMING_ENABLED")).Returns("false"); Assert.That(_defaultConfig.AiMonitoringStreamingEnabled, Is.False); } @@ -4102,7 +4092,7 @@ public void AiMonitoringRecordContentDisabledByLocalConfig() public void AiMonitoringRecordContentDisabledByEnvironmentVariable() { _localConfig.aiMonitoring.enabled = true; - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_AI_MONITORING_RECORD_CONTENT_ENABLED")).Returns("false"); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_AI_MONITORING_RECORD_CONTENT_ENABLED")).Returns("false"); Assert.That(_defaultConfig.AiMonitoringRecordContentEnabled, Is.False); } [Test] @@ -4133,7 +4123,7 @@ public void LlmTokenCountingCallbackComesFromRuntimeConfig() [TestCase("False", true, ExpectedResult = false)] public bool LoggingEnabledTests(string environmentValue, bool localConfigValue) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_LOG_ENABLED")).Returns(environmentValue); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_LOG_ENABLED")).Returns(environmentValue); _localConfig.log.enabled = localConfigValue; return _defaultConfig.LoggingEnabled; @@ -4163,7 +4153,8 @@ public void LoggingEnabledValueIsCached() [TestCase("info", "finest", ExpectedResult = "INFO")] public string LoggingLevelTests(string environmentValue, string localConfigValue) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEWRELIC_LOG_LEVEL")).Returns(environmentValue); + // TODO: remove legacy name in v11 + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_LOG_LEVEL", "NEWRELIC_LOG_LEVEL")).Returns(environmentValue); _localConfig.log.level = localConfigValue; return _defaultConfig.LoggingLevel; @@ -4223,7 +4214,7 @@ public bool ValidateDisableFileSystemWatcher(bool localWatcherDisabled, bool? en if (envWatcherDisabled.HasValue) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_DISABLE_FILE_SYSTEM_WATCHER")).Returns(envWatcherDisabled.ToString().ToLower()); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_DISABLE_FILE_SYSTEM_WATCHER")).Returns(envWatcherDisabled.ToString().ToLower()); } _localConfig.log.enabled = loggingEnabled; diff --git a/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/DataTransport/CollectorHostNameTests.cs b/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/DataTransport/CollectorHostNameTests.cs index 72f3f3092a..310262fa83 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/DataTransport/CollectorHostNameTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/DataTransport/CollectorHostNameTests.cs @@ -76,22 +76,20 @@ public void RunCrossAgentCollectorHostnameTests(string configFileKey, string env if (envKey != null) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_LICENSE_KEY")).Returns(envKey); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEWRELIC_LICENSEKEY")).Returns(envKey); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_LICENSE_KEY", "NEWRELIC_LICENSEKEY")).Returns(envKey); } else { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_LICENSE_KEY")).Returns(null); - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEWRELIC_LICENSEKEY")).Returns(null); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_LICENSE_KEY", "NEWRELIC_LICENSEKEY")).Returns(null); } if (envOverrideHost != null) { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_HOST")).Returns(envOverrideHost); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_HOST")).Returns(envOverrideHost); } else { - Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_HOST")).Returns(null); + Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_HOST")).Returns(null); } if (configFileKey != null) diff --git a/tests/Agent/UnitTests/Core.UnitTest/Transformers/TransactionTransformer/TransactionAttributeMakerTests.cs b/tests/Agent/UnitTests/Core.UnitTest/Transformers/TransactionTransformer/TransactionAttributeMakerTests.cs index 364d0073a0..3baf1bad11 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Transformers/TransactionTransformer/TransactionAttributeMakerTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Transformers/TransactionTransformer/TransactionAttributeMakerTests.cs @@ -1674,7 +1674,7 @@ public object HostDisplayName_WithLocalConfigurationAndEnvironmentVariableSet(st Mock.Arrange(() => _configurationService.Configuration).Returns(_configuration); Mock.Arrange(() => dnsStatic.GetHostName()).Returns("coconut"); - Mock.Arrange(() => environment.GetEnvironmentVariable("NEW_RELIC_PROCESS_HOST_DISPLAY_NAME")).Returns(environmentVariableValue); + Mock.Arrange(() => environment.GetEnvironmentVariableFromList("NEW_RELIC_PROCESS_HOST_DISPLAY_NAME")).Returns(environmentVariableValue); localConfig.processHost.displayName = localConfigurationValue; EventBus.Publish(new ConfigurationUpdatedEvent(_configuration, ConfigurationUpdateSource.Unknown));