Skip to content

Commit

Permalink
feat(sql): Added support for Business Critical and Hyperscale
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-mrzyglod committed Nov 9, 2023
1 parent 618e76a commit 501f81c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
8 changes: 8 additions & 0 deletions arm-estimator-tests/Bicep/SqlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public async Task SQLDatabase_WhenGivenSkuIsProvided_ItShouldBeCorrectlyEstimate
[TestCase("GP_Gen5_32", 6246.7118899999996d)]
[TestCase("GP_Gen5_40", 7808.3556500000004d)]
[TestCase("GP_Gen5_80", 15616.574450000002d)]
[TestCase("BC_Gen5_2", 1036.95884d)]
[TestCase("BC_Gen5_4", 2073.3821800000001d)]
[TestCase("BC_Gen5_6", 3109.8055199999999d)]
[TestCase("BC_Gen5_8", 4146.2288600000002d)]
[TestCase("HS_Gen5_2", 439.65895999999998d)]
[TestCase("HS_Gen5_4", 878.96091999999999d)]
[TestCase("HS_Gen5_6", 1318.26288d)]
[TestCase("HS_Gen5_8", 1757.5648399999998d)]
[Parallelizable(ParallelScope.All)]
public async Task SQLDatabase_WhenGivenVCoreIsProvided_ItShouldBeCorrectlyEstimated(string sku, double cost)
{
Expand Down
5 changes: 4 additions & 1 deletion arm-estimator/Products/SQL/SQLEstimationCalculation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
internal class SQLEstimationCalculation : BaseEstimation, IEstimationCalculation
{
private const double HybridBenefitCost = 145.95d;
private const double HybridBenefitCost_BusinessCritical = 547.50d;

public SQLEstimationCalculation(RetailItem[] items, CommonResourceIdentifier id, WhatIfAfterBeforeChange change, double conversionRate)
: base(items, id, change, conversionRate)
Expand Down Expand Up @@ -111,6 +112,8 @@ private double AddHybridBenefitCostIfNeeded(string skuName, IDictionary<string,
return 0;
}

return HybridBenefitCost * this.conversionRate * SQLQueryFilter.GetNumberOfCoresBasedOnSku(skuName) / 2;
var rawCost = skuName.StartsWith("BC_") ? HybridBenefitCost_BusinessCritical : HybridBenefitCost;

return rawCost * this.conversionRate * SQLQueryFilter.GetNumberOfCoresBasedOnSku(skuName) / 2;
}
}
22 changes: 20 additions & 2 deletions arm-estimator/Products/SQL/SQLQueryFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ACE.WhatIf;
 using ACE.WhatIf;
using Microsoft.Extensions.Logging;

internal class SQLQueryFilter : IQueryFilter
Expand Down Expand Up @@ -35,12 +35,27 @@ public SQLQueryFilter(WhatIfAfterBeforeChange afterState, ILogger logger)
// It's vCore model we're talking about here
sku = $"{skuParts[2]} vCore";


if(IsZoneRedundantDatabase())
{
sku += " Zone Redundancy";
}

return $"serviceId eq '{ServiceId}' and armRegionName eq '{location}' and ((skuName eq '{sku}' and productName eq 'SQL Database Single/Elastic Pool General Purpose - Compute Gen5') or (productName eq 'SQL Database Single/Elastic Pool General Purpose - Storage' and meterName eq 'General Purpose Data Stored'))";
var tier = "General Purpose";
if(skuParts[0] == "BC")
{
tier = "Business Critical";

return $"serviceId eq '{ServiceId}' and armRegionName eq '{location}' and ((skuName eq '{sku}' and productName eq 'SQL Database Single/Elastic Pool {tier} - Compute Gen5') or (productName eq 'SQL Database Single/Elastic Pool Business Critical - Storage'))";
}

if(skuParts[0] == "HS")
{
return $"serviceId eq '{ServiceId}' and armRegionName eq '{location}' and ((skuName eq '{sku}' and productName eq 'SQL Database SingleDB/Elastic Pool Hyperscale - Compute Gen5') or (skuName eq 'Hyperscale' and productName eq 'SQL Database SingleDB Hyperscale - Storage'))";
}


return $"serviceId eq '{ServiceId}' and armRegionName eq '{location}' and ((skuName eq '{sku}' and productName eq 'SQL Database Single/Elastic Pool {tier} - Compute Gen5') or (productName eq 'SQL Database Single/Elastic Pool General Purpose - Storage' and meterName eq 'General Purpose Data Stored'))";
}

if(IsStandardTierWithAdditionalStorageTier(sku))
Expand Down Expand Up @@ -77,6 +92,9 @@ private bool IsPremiumTierWithAdditionalStorageTier(string sku)
return tiers.Contains(sku);
}

// Calculate number of cores based on SKU name. As Azure SQL SKUs
// for vCore model are in format like "GP_Gen5_2", we can extract
// number of cores from the SKU name and use it in calculations.
public static int GetNumberOfCoresBasedOnSku(string sku)
{
var skuParts = sku.Split('_');
Expand Down

0 comments on commit 501f81c

Please sign in to comment.