Skip to content

Commit d64275b

Browse files
benwitmanmsftOleksii Kononenko
authored and
Oleksii Kononenko
committed
Merged PR 742682: Revert 'Log plugin process stderr if plugin start fails'
Log plugin process stderr if plugin start fails Reverts !739622
1 parent 02f45fb commit d64275b

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

Public/Src/Utilities/Plugin/PluginFactory.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,38 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99
using BuildXL.Utilities.Core;
10-
using BuildXL.Utilities.Instrumentation.Common;
1110

1211
namespace BuildXL.Plugin
1312
{
1413
/// <nodoc />
1514
public class PluginFactory: IPluginFactory
1615
{
1716
/// <nodoc />
18-
private readonly LoggingContext m_loggingContext;
19-
20-
/// <nodoc />
21-
public PluginFactory(LoggingContext loggingContext)
22-
{
23-
m_loggingContext = loggingContext;
24-
}
17+
public static PluginFactory Instance = new PluginFactory();
2518

2619
private const string StartPluginProcessArgumentsForamt = "--ipcmoniker {0} --logdir {1} --logVerbose {2}";
2720

28-
private IPlugin PluginCreation_RunInProcess(PluginCreationArgument argument)
21+
private readonly Func<PluginCreationArgument, IPlugin> m_pluginRunInProcessCreationFunc = argument =>
2922
{
30-
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"PluginFactory starting plugin {argument.PluginPath} with args " +
31-
$"{string.Format(StartPluginProcessArgumentsForamt, argument.ConnectionOption.IpcMoniker, argument.ConnectionOption.LogDir, argument.ConnectionOption.LogVerbose)}");
32-
3323
var processStartInfo = new ProcessStartInfo(argument.PluginPath)
3424
{
3525
Arguments = string.Format(StartPluginProcessArgumentsForamt, argument.ConnectionOption.IpcMoniker, argument.ConnectionOption.LogDir, argument.ConnectionOption.LogVerbose),
3626
UseShellExecute = false,
3727
RedirectStandardOutput = false,
38-
RedirectStandardError = true,
3928
};
4029

4130
string id = argument.PluginId;
4231

4332
var process = new Process();
4433
process.StartInfo = processStartInfo;
45-
bool success = process.Start();
46-
47-
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"PluginFactory start result for plugin {argument.PluginPath}: {success}");
34+
process.Start();
4835

4936
var client = argument.CreatePluginClientFunc.Invoke(argument.ConnectionOption);
5037
var plugin = new Plugin(id, argument.PluginPath, process, client);
5138
return plugin;
52-
}
39+
};
5340

54-
private IPlugin PluginCreation_RunInThread(PluginCreationArgument argument)
41+
private readonly Func<PluginCreationArgument, IPlugin> m_pluginRunInThreadCreationFunc = argument =>
5542
{
5643
Contract.RequiresNotNull(argument, "argument can't be null");
5744
Contract.RequiresNotNull(argument.RunInPluginThreadAction, "runInpluginThead can't be null");
@@ -65,14 +52,14 @@ private IPlugin PluginCreation_RunInThread(PluginCreationArgument argument)
6552
var client = argument.CreatePluginClientFunc.Invoke(argument.ConnectionOption);
6653
var plugin = new Plugin(argument.PluginId, argument.PluginPath, pluginTask, cancellationTokenSource, client);
6754
return plugin;
68-
}
55+
};
6956

7057
/// <nodoc />
7158
public IPlugin CreatePlugin(PluginCreationArgument pluginCreationArgument)
7259
{
7360
return pluginCreationArgument.RunInSeparateProcess ?
74-
PluginCreation_RunInProcess(pluginCreationArgument) :
75-
PluginCreation_RunInThread(pluginCreationArgument);
61+
m_pluginRunInProcessCreationFunc.Invoke(pluginCreationArgument) :
62+
m_pluginRunInThreadCreationFunc.Invoke(pluginCreationArgument);
7663
}
7764

7865
/// <nodoc />
@@ -91,8 +78,6 @@ public async Task<Possible<IPlugin>> CreatePluginAsync(PluginCreationArgument pl
9178
}
9279
else
9380
{
94-
string stderr = await plugin.PluginProcess.StandardError.ReadToEndAsync();
95-
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"Plugin process stderr:\n{stderr}");
9681
plugin.PluginProcess.Kill();
9782
return pluginCreationResult.Failure;
9883
}
@@ -108,5 +93,18 @@ public string CreatePluginId()
10893
{
10994
return Guid.NewGuid().ToString();
11095
}
96+
97+
/// <nodoc />
98+
public static void SetGrpcPluginClientBasedOnMessageType(IPlugin plugin, PluginMessageType messageType)
99+
{
100+
//switch(messageType)
101+
//{
102+
// case PluginMessageType.ParseLogMessage:
103+
// plugin.SetLogParsePluginClient();
104+
// break;
105+
// default:
106+
// break;
107+
//}
108+
}
111109
}
112110
}

Public/Src/Utilities/Plugin/PluginManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class PluginManager
2626
{
2727
private readonly ConcurrentDictionary<string, Task<Possible<IPlugin>>> m_plugins;
2828
private readonly PluginHandlers m_pluginHandlers;
29-
private readonly PluginFactory m_pluginFactory;
3029
private bool m_isDisposed = false;
3130
private readonly LoggingContext m_loggingContext;
3231
private readonly IReadOnlyList<string> m_pluginPaths;
@@ -74,7 +73,6 @@ public PluginManager(LoggingContext loggingContext, string logDirectory, IEnumer
7473
{
7574
m_plugins = new ConcurrentDictionary<string, Task<Possible<IPlugin>>>();
7675
m_pluginHandlers = new PluginHandlers();
77-
m_pluginFactory = new PluginFactory(loggingContext);
7876
m_pluginStopTaskSource = TaskSourceSlim.Create<Unit>();
7977
m_loggingContext = loggingContext;
8078
m_logDirectory = logDirectory;
@@ -180,7 +178,7 @@ private async Task<Possible<IPlugin>> CreatePluginAsync(PluginCreationArgument p
180178
}
181179

182180
var sw = Stopwatch.StartNew();
183-
var result = await m_pluginFactory.CreatePluginAsync(pluginCreationArgument);
181+
var result = await PluginFactory.Instance.CreatePluginAsync(pluginCreationArgument);
184182

185183
Interlocked.Add(ref m_pluginLoadingTime, sw.ElapsedMilliseconds);
186184

@@ -252,7 +250,7 @@ public async Task<Possible<ProcessResultMessageResponse>> ProcessResultAsync(str
252250

253251
private PluginCreationArgument GetPluginArgument(string pluginPath, bool runInSeparateProcess)
254252
{
255-
var pluginId = m_pluginFactory.CreatePluginId();
253+
var pluginId = PluginFactory.Instance.CreatePluginId();
256254
return new PluginCreationArgument()
257255
{
258256
PluginPath = pluginPath,

0 commit comments

Comments
 (0)