Skip to content

Commit

Permalink
Cleanup env vars and copy correct home dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
nrcventura committed Jul 20, 2023
1 parent a95db31 commit 9bb1578
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ContainerApplication(string applicationDirectoryName, string distroTag) :

public override void CopyToRemote()
{
CopyNewRelicHomeCoreClrDirectoryToRemote();
CopyNewRelicHomeCoreClrLinuxDirectoryToRemote("x64");

ModifyNewRelicConfig();
}
Expand All @@ -46,7 +46,6 @@ public override void Start(string commandLineArguments, Dictionary<string, strin
{
var arguments = $"compose up --force-recreate";

var profilerFilePath = Path.Combine(DestinationNewRelicHomeDirectoryPath, Utilities.IsLinux ? @"libNewRelicProfiler.so" : @"NewRelic.Profiler.dll");
var newRelicHomeDirectoryPath = DestinationNewRelicHomeDirectoryPath;
var profilerLogDirectoryPath = DefaultLogFileDirectoryPath;

Expand All @@ -63,6 +62,7 @@ public override void Start(string commandLineArguments, Dictionary<string, strin

Console.WriteLine($"[{DateTime.Now}] RemoteContainer.Start(): FileName=docker, Arguments={arguments}, WorkingDirectory={DestinationRootDirectoryPath}, RedirectStandardOutput={captureStandardOutput}, RedirectStandardError={captureStandardOutput}, RedirectStandardInput={RedirectStandardInput}");

// Cleanup environment variables from the system
startInfo.EnvironmentVariables.Remove("COR_ENABLE_PROFILING");
startInfo.EnvironmentVariables.Remove("COR_PROFILER");
startInfo.EnvironmentVariables.Remove("COR_PROFILER_PATH");
Expand All @@ -74,25 +74,11 @@ public override void Start(string commandLineArguments, Dictionary<string, strin
startInfo.EnvironmentVariables.Remove("NEW_RELIC_LICENSE_KEY");
startInfo.EnvironmentVariables.Remove("NEW_RELIC_HOST");
startInfo.EnvironmentVariables.Remove("NEWRELIC_INSTALL_PATH");

startInfo.EnvironmentVariables.Remove("CORECLR_ENABLE_PROFILING");
startInfo.EnvironmentVariables.Remove("CORECLR_PROFILER");
startInfo.EnvironmentVariables.Remove("CORECLR_PROFILER_PATH");
startInfo.EnvironmentVariables.Remove("CORECLR_NEWRELIC_HOME");

// configure env vars as needed for testing environment overrides
foreach (var envVar in environmentVariables)
{
startInfo.EnvironmentVariables.Add(envVar.Key, envVar.Value);
}

startInfo.EnvironmentVariables.Add("CORECLR_ENABLE_PROFILING", "1");
startInfo.EnvironmentVariables.Add("CORECLR_PROFILER", "{36032161-FFC0-4B61-B559-F6C5D41BAE5A}");
startInfo.EnvironmentVariables.Add("CORECLR_PROFILER_PATH", profilerFilePath);
startInfo.EnvironmentVariables.Add("CORECLR_NEWRELIC_HOME", newRelicHomeDirectoryPath);

startInfo.EnvironmentVariables.Add("NEWRELIC_PROFILER_LOG_DIRECTORY", profilerLogDirectoryPath);

// Docker compose settings
var testConfiguration = IntegrationTestConfiguration.GetIntegrationTestConfiguration("Default");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,33 @@ private static string SourceNewRelicHomeCoreClrDirectoryPath
{
get
{
if (!string.IsNullOrWhiteSpace(_sourceNewRelicHomeCoreClrDirectoryPath))
{
return _sourceNewRelicHomeCoreClrDirectoryPath;
}

var homeRootPath = Environment.GetEnvironmentVariable("NR_DEV_HOMEROOT");

var homeDirName = Utilities.RuntimeHomeDirName;
if (!string.IsNullOrWhiteSpace(homeRootPath) && Directory.Exists(homeRootPath))
{
_sourceNewRelicHomeCoreClrDirectoryPath = Path.Combine(homeRootPath, homeDirName);
return _sourceNewRelicHomeCoreClrDirectoryPath;
}

_sourceNewRelicHomeCoreClrDirectoryPath = Path.Combine(RepositoryRootPath, "src", "Agent", homeDirName);
return _sourceNewRelicHomeCoreClrDirectoryPath;
return GetSourceDirectoryForHomeDir(Utilities.RuntimeHomeDirName);
}
set
{
_sourceNewRelicHomeCoreClrDirectoryPath = value;
}
}

private static string GetSourceDirectoryForHomeDir(string homeDirName)
{
if (!string.IsNullOrWhiteSpace(_sourceNewRelicHomeCoreClrDirectoryPath))
{
return _sourceNewRelicHomeCoreClrDirectoryPath;
}

var homeRootPath = Environment.GetEnvironmentVariable("NR_DEV_HOMEROOT");

if (!string.IsNullOrWhiteSpace(homeRootPath) && Directory.Exists(homeRootPath))
{
_sourceNewRelicHomeCoreClrDirectoryPath = Path.Combine(homeRootPath, homeDirName);
return _sourceNewRelicHomeCoreClrDirectoryPath;
}

_sourceNewRelicHomeCoreClrDirectoryPath = Path.Combine(RepositoryRootPath, "src", "Agent", homeDirName);
return _sourceNewRelicHomeCoreClrDirectoryPath;
}

private static readonly string SourceApplicationLauncherProjectDirectoryPath = Path.Combine(SourceIntegrationTestsSolutionDirectoryPath, "ApplicationLauncher");

private static readonly string SourceApplicationLauncherDirectoryPath = Path.Combine(SourceApplicationLauncherProjectDirectoryPath, "bin", Utilities.Configuration);
Expand Down Expand Up @@ -425,6 +429,12 @@ protected void CopyNewRelicHomeCoreClrDirectoryToRemote()
CommonUtils.CopyDirectory(SourceNewRelicHomeCoreClrDirectoryPath, DestinationNewRelicHomeDirectoryPath);
}

protected void CopyNewRelicHomeCoreClrLinuxDirectoryToRemote(string arch)
{
Directory.CreateDirectory(DestinationNewRelicHomeDirectoryPath);
CommonUtils.CopyDirectory(GetSourceDirectoryForHomeDir(Utilities.GetRuntimeHomeDirNameFor(arch, true)), DestinationNewRelicHomeDirectoryPath);
}

protected void CopyApplicationDirectoryToRemote()
{
Directory.CreateDirectory(DestinationApplicationDirectoryPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public static bool IsAlpine

public static string Arch => RuntimeInformation.OSArchitecture.ToString().ToLower();
public static string CurrentRuntime => $"{(IsLinux ? "linux" : "win")}-{(IsAlpine ? "musl-" : "")}{Arch}";
public static string RuntimeHomeDirName => $"newrelichome_{Arch}_coreclr{(IsLinux ? "_linux" : "")}";
public static string RuntimeHomeDirName => GetRuntimeHomeDirNameFor(Arch, IsLinux);
public static string GetRuntimeHomeDirNameFor(string arch, bool isLinux)
{
return $"newrelichome_{arch}_coreclr{(isLinux ? "_linux" : "")}";
}

public static T ThrowIfNull<T>(T value, string valueName)
{
Expand Down

0 comments on commit 9bb1578

Please sign in to comment.