public async Task NoEnvironmentVariables() { using var helper = await StartConsole(enableProfiler : false); var processInfo = ProcessInfo.GetProcessInfo(helper.Process.Id); processInfo.Should().NotBeNull(); using var console = ConsoleHelper.Redirect(); var result = ProcessBasicCheck.Run(processInfo, MockRegistryService(Array.Empty <string>(), ProfilerPath)); result.Should().BeFalse(); console.Output.Should().ContainAll( ProfilerNotLoaded, TracerNotLoaded, EnvironmentVariableNotSet("DD_DOTNET_TRACER_HOME"), WrongEnvironmentVariableFormat(CorProfilerKey, Utils.Profilerid, null), WrongEnvironmentVariableFormat(CorEnableKey, "1", null)); if (RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) { // The variable is not required on Windows because the path is set through the registry console.Output.Should().NotContain(EnvironmentVariableNotSet(CorProfilerPathKey)); } else { console.Output.Should().Contain(EnvironmentVariableNotSet(CorProfilerPathKey)); } }
public async Task Working() { using var helper = await StartConsole(enableProfiler : true); var processInfo = ProcessInfo.GetProcessInfo(helper.Process.Id); processInfo.Should().NotBeNull(); using var console = ConsoleHelper.Redirect(); var result = ProcessBasicCheck.Run(processInfo, MockRegistryService(Array.Empty <string>(), ProfilerPath)); using var scope = new AssertionScope(); scope.AddReportable("Output", console.Output); result.Should().BeTrue(); console.Output.Should().NotContainAny( ProfilerNotLoaded, TracerNotLoaded, "DD_DOTNET_TRACER_HOME", CorProfilerKey, CorEnableKey, CorProfilerPathKey, CorProfilerPath32Key, CorProfilerPath64Key); }
public async Task WrongEnvironmentVariables() { using var helper = await StartConsole( enableProfiler : false, ("DD_DOTNET_TRACER_HOME", "TheDirectoryDoesNotExist"), (CorProfilerKey, Guid.Empty.ToString("B")), (CorEnableKey, "0"), (CorProfilerPathKey, "dummyPath"), (CorProfilerPath32Key, "dummyPath"), (CorProfilerPath64Key, "dummyPath")); var processInfo = ProcessInfo.GetProcessInfo(helper.Process.Id); processInfo.Should().NotBeNull(); using var console = ConsoleHelper.Redirect(); var result = ProcessBasicCheck.Run(processInfo, MockRegistryService(Array.Empty <string>(), ProfilerPath)); result.Should().BeFalse(); console.Output.Should().ContainAll( ProfilerNotLoaded, TracerNotLoaded, TracerHomeNotFoundFormat("TheDirectoryDoesNotExist"), WrongEnvironmentVariableFormat(CorProfilerKey, Utils.Profilerid, Guid.Empty.ToString("B")), WrongEnvironmentVariableFormat(CorEnableKey, "1", "0"), MissingProfilerEnvironment(CorProfilerPathKey, "dummyPath"), WrongProfilerEnvironment(CorProfilerPathKey, "dummyPath"), MissingProfilerEnvironment(CorProfilerPath32Key, "dummyPath"), WrongProfilerEnvironment(CorProfilerPath32Key, "dummyPath"), MissingProfilerEnvironment(CorProfilerPath64Key, "dummyPath"), WrongProfilerEnvironment(CorProfilerPath64Key, "dummyPath")); }
public async Task VersionConflict1X() { var environmentHelper = new EnvironmentHelper("VersionConflict.1x", typeof(TestHelper), Output); using var helper = await StartConsole(environmentHelper, enableProfiler : true); var processInfo = ProcessInfo.GetProcessInfo(helper.Process.Id); processInfo.Should().NotBeNull(); using var console = ConsoleHelper.Redirect(); var result = ProcessBasicCheck.Run(processInfo, MockRegistryService(Array.Empty <string>(), ProfilerPath)); result.Should().BeFalse(); console.Output.Should().Contain(VersionConflict); console.Output.Should().Contain(MultipleTracers(new[] { "1.29.0.0", TracerConstants.AssemblyVersion })); }
public async Task DetectRuntime() { using var helper = await StartConsole(enableProfiler : false); var processInfo = ProcessInfo.GetProcessInfo(helper.Process.Id); processInfo.Should().NotBeNull(); using var console = ConsoleHelper.Redirect(); ProcessBasicCheck.Run(processInfo, MockRegistryService(Array.Empty <string>(), ProfilerPath)); #if NET_FRAMEWORK const string expectedOutput = NetFrameworkRuntime; #else const string expectedOutput = NetCoreRuntime; #endif console.Output.Should().Contain(expectedOutput); }
public override async Task <int> ExecuteAsync(CommandContext context, CheckProcessSettings settings) { AnsiConsole.WriteLine("Running checks on process " + settings.Pid); var process = ProcessInfo.GetProcessInfo(settings.Pid); if (process == null) { Utils.WriteError("Could not fetch information about target process. Make sure to run the command from an elevated prompt, and check that the pid is correct."); return(1); } var mainModule = process.MainModule != null?Path.GetFileName(process.MainModule) : null; if (mainModule == "w3wp.exe" || mainModule == "iisexpress.exe") { if (process.EnvironmentVariables.ContainsKey("APP_POOL_ID")) { Utils.WriteWarning(IisProcess); } } var foundIssue = !ProcessBasicCheck.Run(process); if (foundIssue) { return(1); } foundIssue = !await AgentConnectivityCheck.RunAsync(process).ConfigureAwait(false); if (foundIssue) { return(1); } Utils.WriteSuccess("No issue found with the target process."); return(0); }
internal static async Task <int> ExecuteAsync(CheckIisSettings settings, string applicationHostConfigurationPath, int?pid, IRegistryService registryService = null) { var values = settings.SiteName.Split('/'); var siteName = values[0]; var applicationName = values.Length > 1 ? $"/{values[1]}" : "/"; AnsiConsole.WriteLine(FetchingApplication(siteName, applicationName)); var serverManager = new ServerManager(readOnly: true, applicationHostConfigurationPath); var site = serverManager.Sites[siteName]; if (site == null) { Utils.WriteError(CouldNotFindSite(siteName, serverManager.Sites.Select(s => s.Name))); return(1); } var application = site.Applications[applicationName]; if (application == null) { Utils.WriteError(CouldNotFindApplication(siteName, applicationName, site.Applications.Select(a => a.Path))); return(1); } var pool = serverManager.ApplicationPools[application.ApplicationPoolName]; // The WorkerProcess part of ServerManager doesn't seem to be compatible with IISExpress // so we skip this bit when launched from the tests if (pid == null) { var workerProcesses = pool.WorkerProcesses; if (workerProcesses.Count > 0) { // If there are multiple worker processes, we just take the first one // In theory, all worker processes have the same configuration pid = workerProcesses[0].ProcessId; } } if (pid == null) { Utils.WriteWarning(NoWorkerProcess); } else { AnsiConsole.WriteLine(InspectingWorkerProcess(pid.Value)); var rootDirectory = application.VirtualDirectories.FirstOrDefault(d => d.Path == "/")?.PhysicalPath; IConfigurationSource appSettingsConfigurationSource = null; try { var config = application.GetWebConfiguration(); var appSettings = config.GetSection("appSettings"); var collection = appSettings.GetCollection(); appSettingsConfigurationSource = new DictionaryConfigurationSource( collection.ToDictionary(c => (string)c.Attributes["key"].Value, c => (string)c.Attributes["value"].Value)); } catch (Exception ex) { Utils.WriteWarning(ErrorExtractingConfiguration(ex.Message)); } var process = ProcessInfo.GetProcessInfo(pid.Value, rootDirectory, appSettingsConfigurationSource); if (process == null) { Utils.WriteError(GetProcessError); return(1); } if (process.DotnetRuntime.HasFlag(ProcessInfo.Runtime.NetCore) && !string.IsNullOrEmpty(pool.ManagedRuntimeVersion)) { Utils.WriteWarning(IisMixedRuntimes); } if (process.Modules.Any(m => Path.GetFileName(m).Equals("aspnetcorev2_outofprocess.dll", StringComparison.OrdinalIgnoreCase))) { // IIS site is hosting aspnetcore in out-of-process mode // Trying to locate the actual application process AnsiConsole.WriteLine(OutOfProcess); var childProcesses = process.GetChildProcesses(); // Get either the first process that is dotnet, or the first that is not conhost int?dotnetPid = null; int?fallbackPid = null; foreach (var childPid in childProcesses) { using var childProcess = Process.GetProcessById(childPid); if (childProcess.ProcessName.Equals("dotnet", StringComparison.OrdinalIgnoreCase)) { dotnetPid = childPid; break; } if (!childProcess.ProcessName.Equals("conhost", StringComparison.OrdinalIgnoreCase)) { fallbackPid = childPid; } } var aspnetCorePid = dotnetPid ?? fallbackPid; if (aspnetCorePid == null) { Utils.WriteError(AspNetCoreProcessNotFound); return(1); } AnsiConsole.WriteLine(AspNetCoreProcessFound(aspnetCorePid.Value)); process = ProcessInfo.GetProcessInfo(aspnetCorePid.Value); if (process == null) { Utils.WriteError(GetProcessError); return(1); } } if (!ProcessBasicCheck.Run(process, registryService)) { return(1); } if (!await AgentConnectivityCheck.RunAsync(process).ConfigureAwait(false)) { return(1); } } if (!GacCheck.Run()) { return(1); } Utils.WriteSuccess(IisNoIssue); return(0); }