Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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