Skip to content

Commit

Permalink
Revert "Add support for capturing the output of Processes (#135)"
Browse files Browse the repository at this point in the history
This reverts commit ebe538b.
  • Loading branch information
brianwp3000 committed Sep 1, 2022
1 parent 5991641 commit 38b8aca
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 347 deletions.
77 changes: 0 additions & 77 deletions VmAgent.Core.UnitTests/ProcessOutputLoggerTest.cs

This file was deleted.

65 changes: 0 additions & 65 deletions VmAgent.Core/Dependencies/FileWriteWrapper.cs

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions VmAgent.Core/Dependencies/Interfaces/IFileWriteWrapper.cs

This file was deleted.

20 changes: 0 additions & 20 deletions VmAgent.Core/Dependencies/Interfaces/IProcessOutputLogger.cs

This file was deleted.

2 changes: 2 additions & 0 deletions VmAgent.Core/Interfaces/BaseSessionHostRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ protected BaseSessionHostRunner(

abstract public Task CollectLogs(string id, string logsFolder, ISessionHostManager sessionHostManager);

abstract public Task CreateStartGameExceptionLogs(string logsFolder, string exceptionMessage);

abstract public Task<SessionHostInfo> CreateAndStart(int instanceNumber, GameResourceDetails gameResourceDetails, ISessionHostManager sessionHostManager);

abstract public Task DeleteResources(SessionHostsStartInfo sessionHostsStartInfo);
Expand Down
5 changes: 5 additions & 0 deletions VmAgent.Core/Interfaces/DockerContainerEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,5 +680,10 @@ private string GetGameWorkingDir(SessionHostsStartInfo request)
}
return null;
}

public override Task CreateStartGameExceptionLogs(string logsFolder, string exceptionMessage)
{
return Task.CompletedTask;
}
}
}
3 changes: 0 additions & 3 deletions VmAgent.Core/Interfaces/IProcessWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Microsoft.Azure.Gaming.VmAgent.Core.Interfaces
{
using System;
using System.Collections.Generic;
using System.Diagnostics;

Expand All @@ -13,8 +12,6 @@ public interface IProcessWrapper

int Start(ProcessStartInfo startInfo);

int StartWithEventHandler(ProcessStartInfo startInfo, Action<object, DataReceivedEventArgs> StdOutputHandler, Action<object, DataReceivedEventArgs> ErrorOutputHandler, Action<object, EventArgs> ProcessExitedHandler);

IEnumerable<int> List();

void WaitForProcessExit(int id);
Expand Down
1 change: 1 addition & 0 deletions VmAgent.Core/Interfaces/ISessionHostRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public interface ISessionHostRunner

Task CollectLogs(string id, string logsFolder, ISessionHostManager sessionHostManager);

Task CreateStartGameExceptionLogs(string logFolder, string exceptionMessage);
}
}
40 changes: 13 additions & 27 deletions VmAgent.Core/Interfaces/ProcessRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ public override Task<SessionHostInfo> CreateAndStart(int instanceNumber, GameRes
string configFolderPathOnVm = _vmConfiguration.GetConfigRootFolderForSessionHost(instanceNumber);
_systemOperations.CreateDirectory(configFolderPathOnVm);

string processOutputFilePathOnVm = Path.Combine(logFolderPathOnVm, ConsoleLogCaptureFileName);
ProcessOutputLogger processOutputLogger = null;
try
{
processOutputLogger = new ProcessOutputLogger(processOutputFilePathOnVm, _logger);
}
catch(Exception exception)
{
_logger.LogException($"Failed to create ProcessOutputLogger with instance number {instanceNumber}", exception);
}

ProcessStartInfo processStartInfo = new ProcessStartInfo();
(string executableFileName, string arguments) = GetExecutableAndArguments(sessionHostStartInfo, instanceNumber);
processStartInfo.FileName = executableFileName;
Expand All @@ -69,10 +58,8 @@ public override Task<SessionHostInfo> CreateAndStart(int instanceNumber, GameRes

try
{
int processId = processOutputLogger != null ?
_processWrapper.StartWithEventHandler(processStartInfo, processOutputLogger.StdOutputHandler, processOutputLogger.ErrorOutputHandler, processOutputLogger.ProcessExitedHandler) : _processWrapper.Start(processStartInfo);

sessionHostManager.UpdateSessionHostTypeSpecificId(sessionHostUniqueId, processId.ToString());
string processId = _processWrapper.Start(processStartInfo).ToString();
sessionHostManager.UpdateSessionHostTypeSpecificId(sessionHostUniqueId, processId);
_logger.LogInformation($"Started process for session host. Instance Number: {instanceNumber}, UniqueId: {sessionHostUniqueId}, ProcessId: {processId}");
}
catch (Exception exception)
Expand All @@ -81,16 +68,9 @@ public override Task<SessionHostInfo> CreateAndStart(int instanceNumber, GameRes
sessionHostManager.RemoveSessionHost(sessionHostUniqueId);
sessionHost = null;
string exceptionMessage = exception.ToString();

if (processOutputLogger != null)
{
CreateStartGameExceptionLogs(processOutputLogger, exceptionMessage);
}
else
{
_logger.LogException($"processOutputlogger is not initialized. Failed to write failed start game error logs to {ConsoleLogCaptureFileName} for Process.", exception);
}
CreateStartGameExceptionLogs(logFolderPathOnVm, exceptionMessage);
}

return Task.FromResult(sessionHost);
}

Expand All @@ -102,19 +82,25 @@ public override Task CollectLogs(string processId, string logsFolder, ISessionHo
return Task.CompletedTask;
}

public void CreateStartGameExceptionLogs(ProcessOutputLogger processOutputLogger, string exceptionMessage)
public override Task CreateStartGameExceptionLogs(string logsFolder, string exceptionMessage)
{
try
{
_logger.LogVerbose("Collecting logs for failed start game process.");
_logger.LogVerbose($"Written logs for failed start game process to {processOutputLogger.GetProcessLogFilePath()}.");
processOutputLogger.Log(exceptionMessage);
string destinationFileName = Path.Combine(logsFolder, ConsoleLogCaptureFileName);

using (StreamWriter sw = File.AppendText(destinationFileName))
{
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK"));
sw.WriteLine($"{exceptionMessage}");
}
_logger.LogVerbose($"Written logs for failed start game process to {destinationFileName}.");
}
catch (Exception ex)
{
_logger.LogException($"Failed to write failed start game error logs for process", ex);
}
return Task.CompletedTask;
}

private (string, string) GetExecutableAndArguments(SessionHostsStartInfo sessionHostsStartInfo, int instanceNumber)
Expand Down
19 changes: 1 addition & 18 deletions VmAgent.Core/Interfaces/ProcessWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.Azure.Gaming.VmAgent.Core.Interfaces
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

public class ProcessWrapper : IProcessWrapper
{
Expand Down Expand Up @@ -34,24 +35,6 @@ public int Start(ProcessStartInfo startInfo)
return Process.Start(startInfo).Id;
}

public int StartWithEventHandler(ProcessStartInfo startInfo, Action<object, DataReceivedEventArgs> StdOutputHandler, Action<object, DataReceivedEventArgs> ErrorOutputHandler, Action<object, EventArgs> ProcessExitedHandler)
{
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;

Process process = new Process();
process.StartInfo = startInfo;
process.OutputDataReceived += new DataReceivedEventHandler(StdOutputHandler);
process.ErrorDataReceived += new DataReceivedEventHandler(ErrorOutputHandler);
process.Exited += new EventHandler(ProcessExitedHandler);
process.EnableRaisingEvents = true;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();

return process.Id;
}

public IEnumerable<int> List()
{
return Process.GetProcesses().Select(x => x.Id);
Expand Down
Loading

0 comments on commit 38b8aca

Please sign in to comment.