Revert "Update to XElite (#1287)" (#1334)

This reverts commit 822a6459ce.
This commit is contained in:
Alan Ren
2021-12-08 10:49:23 -08:00
committed by GitHub
parent 51c801eb33
commit 0d7a3b4168
15 changed files with 326 additions and 243 deletions

View File

@@ -18,7 +18,6 @@ using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.XEvent;
using Microsoft.SqlServer.Management.XEventDbScoped;
using Microsoft.SqlServer.XEvent.XELite;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.Connection;
@@ -121,42 +120,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
this.SessionMonitor.AddSessionListener(this);
}
/// <summary>
/// Handle request to start a profiling session
/// </summary>
internal async Task HandleStartProfilingRequest(StartProfilingParams parameters, RequestContext<StartProfilingResult> requestContext)
{
await Task.Run(async () =>
{
try
{
Logger.Write(TraceEventType.Verbose, "HandleStartProfilingRequest started");
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
if (connInfo != null)
{
// create a new XEvent session and Profiler session
var xeSession = this.XEventSessionFactory.GetXEventSession(parameters.SessionName, connInfo);
monitor.StartMonitoringSession(parameters.OwnerUri, xeSession);
var result = new StartProfilingResult();
await requestContext.SendResult(result);
}
else
{
Logger.Write(TraceEventType.Error, "Connection Info could not be found for " + parameters.OwnerUri);
throw new Exception(SR.ProfilerConnectionNotFound);
}
}
catch (Exception e)
{
Logger.Write(TraceEventType.Error, "HandleStartProfilingRequest failed for uri " + parameters.OwnerUri);
await requestContext.SendError(new Exception (SR.StartProfilingFailed(e.Message), e));
}
});
}
/// <summary>
/// Handle request to start a profiling session
/// </summary>
@@ -166,24 +129,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
try
{
Logger.Write(TraceEventType.Verbose, "HandleCreateXEventSessionRequest started");
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
if (connInfo == null)
{
Logger.Write(TraceEventType.Error, "Connection Info could not be found for " + parameters.OwnerUri);
throw new Exception(SR.ProfilerConnectionNotFound);
}
else if (parameters.SessionName == null)
{
Logger.Write(TraceEventType.Error, "Session Name could not be found for " + parameters.OwnerUri);
throw new ArgumentNullException("SessionName");
}
else if (parameters.Template == null)
{
Logger.Write(TraceEventType.Error, "Template could not be found for " + parameters.OwnerUri);
throw new ArgumentNullException("Template");
}
else
@@ -197,13 +156,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
xeSession = this.XEventSessionFactory.GetXEventSession(parameters.SessionName, connInfo);
}
catch {
Logger.Write(TraceEventType.Verbose, "Session with name '" + parameters.SessionName + "' was not found");
}
catch { }
if (xeSession == null)
{
Logger.Write(TraceEventType.Verbose, "Creating new XEventSession with SessionName " + parameters.SessionName);
// create a new XEvent session and Profiler session
xeSession = this.XEventSessionFactory.CreateXEventSession(parameters.Template.CreateStatement, parameters.SessionName, connInfo);
}
@@ -219,8 +175,42 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
}
catch (Exception e)
{
Logger.Write(TraceEventType.Error, "HandleCreateXEventSessionRequest failed for uri " + parameters.OwnerUri);
await requestContext.SendError(new Exception (SR.CreateSessionFailed(e.Message), e));
await requestContext.SendError(new Exception(SR.CreateSessionFailed(e.Message)));
}
});
}
/// <summary>
/// Handle request to start a profiling session
/// </summary>
internal async Task HandleStartProfilingRequest(StartProfilingParams parameters, RequestContext<StartProfilingResult> requestContext)
{
await Task.Run(async () =>
{
try
{
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
if (connInfo != null)
{
// create a new XEvent session and Profiler session
var xeSession = this.XEventSessionFactory.GetXEventSession(parameters.SessionName, connInfo);
// start monitoring the profiler session
monitor.StartMonitoringSession(parameters.OwnerUri, xeSession);
var result = new StartProfilingResult();
await requestContext.SendResult(result);
}
else
{
throw new Exception(SR.ProfilerConnectionNotFound);
}
}
catch (Exception e)
{
await requestContext.SendError(new Exception(SR.StartSessionFailed(e.Message)));
}
});
}
@@ -234,7 +224,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
try
{
Logger.Write(TraceEventType.Verbose, "HandleStopProfilingRequest started");
ProfilerSession session;
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
@@ -251,12 +240,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
await requestContext.SendResult(new StopProfilingResult { });
break;
}
catch (InvalidOperationException e)
catch (InvalidOperationException)
{
remainingAttempts--;
if (remainingAttempts == 0)
{
Logger.Write(TraceEventType.Error, "Stop profiler session '" + session.XEventSession.Session.Name + "' failed after three retries, last exception was: " + e.Message);
throw;
}
Thread.Sleep(500);
@@ -270,7 +258,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
}
catch (Exception e)
{
Logger.Write(TraceEventType.Error, "HandleStopProfilingRequest failed for uri " + parameters.OwnerUri);
await requestContext.SendError(new Exception(SR.StopSessionFailed(e.Message)));
}
});
@@ -285,14 +272,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
try
{
Logger.Write(TraceEventType.Verbose, "HandlePauseProfilingRequest started");
monitor.PauseViewer(parameters.OwnerUri);
await requestContext.SendResult(new PauseProfilingResult { });
}
catch (Exception e)
{
Logger.Write(TraceEventType.Error, "HandlePauseProfilingRequest failed for uri " + parameters.OwnerUri);
await requestContext.SendError(new Exception(SR.PauseSessionFailed(e.Message)));
}
});
@@ -307,7 +292,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
try
{
Logger.Write(TraceEventType.Verbose, "HandleGetXEventSessionsRequest started");
var result = new GetXEventSessionsResult();
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
@@ -315,7 +299,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
out connInfo);
if (connInfo == null)
{
Logger.Write(TraceEventType.Error, "Connection Info could not be found for " + parameters.OwnerUri);
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
}
else
@@ -327,7 +310,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
}
catch (Exception e)
{
Logger.Write(TraceEventType.Error, "HandleGetXEventSessionsRequest failed for uri " + parameters.OwnerUri);
await requestContext.SendError(e);
}
});
@@ -342,13 +324,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
try
{
Logger.Write(TraceEventType.Verbose, "HandleDisconnectSessionRequest started");
ProfilerSession session;
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
}
catch (Exception e)
{
Logger.Write(TraceEventType.Error, "HandleDisconnectSessionRequest failed for uri " + parameters.OwnerUri);
await requestContext.SendError(e);
}
});
@@ -394,15 +374,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
return store;
}
/// <summary>
/// Nulls out properties in ConnectionDetails that aren't compatible with XElite.
/// </summary>
private static void RemoveIncompatibleConnectionProperties(ConnectionDetails connDetails){
connDetails.ConnectRetryCount = null;
connDetails.ConnectRetryInterval = null;
connDetails.MultiSubnetFailover = null;
}
/// <summary>
/// Gets an XEvent session with the given name per the IXEventSessionFactory contract
/// Also starts the session if it isn't currently running
@@ -412,7 +383,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
var sqlConnection = ConnectionService.OpenSqlConnection(connInfo);
SqlStoreConnection connection = new SqlStoreConnection(sqlConnection);
BaseXEStore store = CreateXEventStore(connInfo, connection);
RemoveIncompatibleConnectionProperties(connInfo.ConnectionDetails);
Session session = store.Sessions[sessionName];
// start the session if it isn't already running
@@ -429,7 +399,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
// create xevent session wrapper
return new XEventSession()
{
ConnectionDetails = connInfo.ConnectionDetails,
Session = session
};
}