[SQL Migration] Upgrade Microsoft.SqlServer.Migration.Assessment (#1734)

* WIP - update NuGet and add xevent assessment request

* Update API

* Update nupkg to official build

* Add try/catch around individual recommendation models

* Clean up

* Add HS to SQL DB SKU recommendation input
This commit is contained in:
Raymond Truong
2022-11-01 09:29:59 -07:00
committed by GitHub
parent 36965f6355
commit 783ea39e8a
5 changed files with 69 additions and 12 deletions

View File

@@ -27,7 +27,7 @@
<PackageReference Update="Microsoft.Azure.Kusto.Data" Version="9.0.4" />
<PackageReference Update="Microsoft.Azure.Kusto.Language" Version="9.0.4" />
<PackageReference Update="Microsoft.SqlServer.Assessment" Version="[1.1.9]" />
<PackageReference Update="Microsoft.SqlServer.Migration.Assessment" Version="1.0.20221014.16" />
<PackageReference Update="Microsoft.SqlServer.Migration.Assessment" Version="1.0.20221028.23" />
<PackageReference Update="Microsoft.SqlServer.Management.SqlParser" Version="160.22519.0" />
<PackageReference Update="Microsoft.Azure.OperationalInsights" Version="1.0.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="3.10.0" />

View File

@@ -156,6 +156,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration.Contracts
internal string sqlDbReportPath;
internal string sqlMiReportPath;
internal string sqlVmReportPath;
// Create a new empty RecommendationResultSet
internal RecommendationResultSet()
{
this.sqlDbResults = new List<SkuRecommendationResult>();
this.sqlMiResults = new List<SkuRecommendationResult>();
this.sqlVmResults = new List<SkuRecommendationResult>();
this.sqlDbDurationInMs = -1;
this.sqlMiDurationInMs = -1;
this.sqlVmDurationInMs = -1;
this.sqlDbReportPath = "";
this.sqlMiReportPath = "";
this.sqlVmReportPath = "";
}
}
public class GetSkuRecommendationsRequest

View File

@@ -10,8 +10,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration.Contracts
{
public class MigrationAssessmentsParams
{
/// <summary>
/// Owner URI
/// </summary>
public string OwnerUri { get; set; }
/// <summary>
/// List of databases to assess
/// </summary>
public string[] Databases { get; set; }
/// <summary>
/// Folder path to XEvents files to be assessed, if applicable. Empty string to disable XEvents assessment.
/// </summary>
public string XEventsFilesFolderPath { get; set; }
}
public class MigrationAssessmentResult

View File

@@ -39,6 +39,8 @@ using Microsoft.SqlServer.Migration.SkuRecommendation.ElasticStrategy.AzureSqlMa
using Microsoft.SqlServer.Migration.SkuRecommendation.ElasticStrategy.AzureSqlDatabase;
using Microsoft.SqlServer.Migration.SkuRecommendation.Models;
using Microsoft.SqlServer.Migration.SkuRecommendation.Utils;
using Microsoft.SqlServer.Migration.Assessment.Common.Models;
using Microsoft.SqlServer.Migration.Assessment.Common.Utils;
namespace Microsoft.SqlTools.ServiceLayer.Migration
{
@@ -157,7 +159,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
connectionStrings.Add(ConnectionService.BuildConnectionString(connInfo.ConnectionDetails));
}
string[] assessmentConnectionStrings = connectionStrings.ToArray();
var results = await GetAssessmentItems(assessmentConnectionStrings);
var results = await GetAssessmentItems(assessmentConnectionStrings, parameters.XEventsFilesFolderPath);
await requestContext.SendResult(results);
}
}
@@ -271,8 +273,26 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
dbsToInclude: new HashSet<string>(parameters.DatabaseAllowList),
hostRequirements: new SqlServerHostRequirements() { NICCount = 1 });
RecommendationResultSet baselineResults = GenerateBaselineRecommendations(req, parameters);
RecommendationResultSet elasticResults = GenerateElasticRecommendations(req, parameters);
RecommendationResultSet baselineResults;
RecommendationResultSet elasticResults;
try
{
baselineResults = GenerateBaselineRecommendations(req, parameters);
}
catch (Exception e)
{
baselineResults = new RecommendationResultSet();
}
try
{
elasticResults = GenerateElasticRecommendations(req, parameters);
}
catch (Exception e)
{
elasticResults = new RecommendationResultSet();
}
GetSkuRecommendationsResult results = new GetSkuRecommendationsResult
{
@@ -586,11 +606,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
}
}
internal async Task<MigrationAssessmentResult> GetAssessmentItems(string[] connectionStrings)
internal async Task<MigrationAssessmentResult> GetAssessmentItems(string[] connectionStrings, string xEventsFilesFolderPath)
{
SqlAssessmentConfiguration.EnableLocalLogging = true;
SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath = Path.GetDirectoryName(Logger.LogFileFullPath);
DmaEngine engine = new DmaEngine(connectionStrings);
SqlConnectionLocator locator = new SqlConnectionLocator();
locator.ConnectionStrings.AddRange(connectionStrings);
locator.XeventsFilesFolderPath = xEventsFilesFolderPath;
DmaEngine engine = new DmaEngine(locator);
ISqlMigrationAssessmentModel contextualizedAssessmentResult = await engine.GetTargetAssessmentResultsListWithCheck(System.Threading.CancellationToken.None);
var assessmentReportFileName = String.Format("SqlAssessmentReport-{0}.json", DateTime.UtcNow.ToString("yyyyMMddHH-mmss", CultureInfo.InvariantCulture));
var assessmentReportFullPath = Path.Combine(SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath, assessmentReportFileName);
@@ -715,7 +740,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
switch (targetPlatform)
{
case "AzureSqlDatabase":
// Gen5 BC/GP DB
// Gen5 BC/GP/HS DB
eligibleSkuCategories.Add(new AzureSqlSkuPaaSCategory(
AzureSqlTargetPlatform.AzureSqlDatabase,
AzureSqlPurchasingModel.vCore,
@@ -729,16 +754,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
AzureSqlPaaSServiceTier.GeneralPurpose,
ComputeTier.Provisioned,
AzureSqlPaaSHardwareType.Gen5));
eligibleSkuCategories.Add(new AzureSqlSkuPaaSCategory(
AzureSqlTargetPlatform.AzureSqlDatabase,
AzureSqlPurchasingModel.vCore,
AzureSqlPaaSServiceTier.HyperScale,
ComputeTier.Provisioned,
AzureSqlPaaSHardwareType.Gen5));
break;
case "AzureSqlManagedInstance":
// Gen5 BC/GP MI
eligibleSkuCategories.Add(new AzureSqlSkuPaaSCategory(
AzureSqlTargetPlatform.AzureSqlManagedInstance,
AzureSqlPurchasingModel.vCore,
AzureSqlPaaSServiceTier.BusinessCritical,
ComputeTier.Provisioned,
AzureSqlPaaSHardwareType.Gen5));
AzureSqlTargetPlatform.AzureSqlManagedInstance,
AzureSqlPurchasingModel.vCore,
AzureSqlPaaSServiceTier.BusinessCritical,
ComputeTier.Provisioned,
AzureSqlPaaSHardwareType.Gen5));
eligibleSkuCategories.Add(new AzureSqlSkuPaaSCategory(
AzureSqlTargetPlatform.AzureSqlManagedInstance,