Skip to content

Commit

Permalink
[SQL Migration] Upgrade Microsoft.SqlServer.Migration.Assessment (#1734)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
raymondtruong authored Nov 1, 2022
1 parent 36965f6 commit 783ea39
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ internal class RecommendationResultSet {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 42 additions & 11 deletions src/Microsoft.SqlTools.ServiceLayer/Migration/MigrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
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
{
Expand Down Expand Up @@ -157,7 +159,7 @@ internal async Task HandleMigrationAssessmentsRequest(
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);
}
}
Expand Down Expand Up @@ -271,8 +273,26 @@ internal async Task HandleGetSkuRecommendationsRequest(
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
{
Expand Down Expand Up @@ -586,11 +606,16 @@ public bool TryGetData(string column, out object value)
}
}

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);
Expand Down Expand Up @@ -715,7 +740,7 @@ internal static List<AzureSqlSkuCategory> GetEligibleSkuCategories(string target
switch (targetPlatform)
{
case "AzureSqlDatabase":
// Gen5 BC/GP DB
// Gen5 BC/GP/HS DB
eligibleSkuCategories.Add(new AzureSqlSkuPaaSCategory(
AzureSqlTargetPlatform.AzureSqlDatabase,
AzureSqlPurchasingModel.vCore,
Expand All @@ -729,16 +754,22 @@ internal static List<AzureSqlSkuCategory> GetEligibleSkuCategories(string target
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,
Expand Down

0 comments on commit 783ea39

Please sign in to comment.