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

Fixed underutilized Premium SSD disk recommendation not reporting results #2

Merged
merged 4 commits into from
Jul 23, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/aoe-cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- dev
paths:
- 'docs/deploy/optimization-engine/**'
- 'src/optimization-engine/**'
permissions:
id-token: write
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/aoe-cd-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
paths:
- 'docs/deploy/optimization-engine/**'
- 'src/optimization-engine/**'
permissions:
id-token: write
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/aoe-cd-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- features/aoe
paths:
- 'docs/deploy/optimization-engine/**'
- 'src/optimization-engine/**'
permissions:
id-token: write
Expand Down
6 changes: 3 additions & 3 deletions src/optimization-engine/azuredeploy-nested.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ var csvParameterizedExports = [
exportJobId: monitorDiskIOPSAvgExportJobId
parameters: {
ResourceType: 'microsoft.compute/disks'
ARGFilter: 'sku.name =~ \'Premium_LRS\' and properties.diskState != \'Unattached\''
ARGFilter: 'sku.name startswith \'Premium_\' and properties.diskState =~ \'Attached\''
TimeSpan: '01:00:00'
aggregationType: 'Average'
AggregationOfType: 'Maximum'
Expand All @@ -748,7 +748,7 @@ var csvParameterizedExports = [
exportJobId: monitorDiskMBPsAvgExportJobId
parameters: {
ResourceType: 'microsoft.compute/disks'
ARGFilter: 'sku.name =~ \'Premium_LRS\' and properties.diskState != \'Unattached\''
ARGFilter: 'sku.name startswith \'Premium_\' and properties.diskState =~ \'Attached\''
TimeSpan: '01:00:00'
aggregationType: 'Average'
AggregationOfType: 'Maximum'
Expand Down Expand Up @@ -1179,7 +1179,7 @@ var runbooks = [
}
{
name: diskOptimizationsRecommendationsRunbookName
version: '1.1.1.0'
version: '1.1.2.0'
description: 'Generates Disk optimizations recommendations'
type: 'PowerShell'
scriptUri: uri(templateLocation, 'runbooks/recommendations/${diskOptimizationsRecommendationsRunbookName}.ps1')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Find-DiskMonthlyPrice {
[string] $DiskSizeTier
)

$diskSkus = $SKUPriceSheet | Where-Object { $_.MeterName_s.Replace(" Disks","") -eq $DiskSizeTier }
$diskSkus = $SKUPriceSheet | Where-Object { $_.MeterName_s.Replace(" Disks","").Replace(" Disk","") -eq $DiskSizeTier }
$targetMonthlyPrice = [double]::MaxValue
if ($diskSkus)
{
Expand Down Expand Up @@ -182,7 +182,7 @@ try
$baseQuery = @"
$pricesheetTableName
| where TimeGenerated > ago(14d)
| where MeterCategory_s == 'Storage' and MeterSubCategory_s endswith "Managed Disks" and MeterName_s endswith "Disks" and MeterRegion_s == '$pricesheetRegion' and PriceType_s == 'Consumption'
| where MeterCategory_s == 'Storage' and MeterSubCategory_s contains "Managed Disk" and (MeterName_s endswith "Disk" or MeterName_s endswith "Disks") and MeterName_s !has 'Special' and MeterRegion_s == '$pricesheetRegion' and PriceType_s == 'Consumption'
| distinct MeterName_s, MeterSubCategory_s, MeterCategory_s, MeterRegion_s, UnitPrice_s, UnitOfMeasure_s
"@

Expand Down Expand Up @@ -222,7 +222,8 @@ $baseQuery = @"
| summarize MaxIOPSMetric = max(todouble(MetricValue_s)) by ResourceId
| join kind=inner (
$disksTableName
| where TimeGenerated > ago(1d) and DiskState_s != 'Unattached' and SKU_s startswith 'Premium'
| where TimeGenerated > ago(1d) and DiskState_s =~ 'Attached' and SKU_s startswith 'Premium'
| extend DiskTier_s = strcat(DiskTier_s, ' ', tostring(split(SKU_s, '_')[1]))
| project ResourceId=InstanceId_s, DiskName_s, ResourceGroup = ResourceGroupName_s, SubscriptionId = SubscriptionGuid_g, Cloud_s, TenantGuid_g, Tags_s, MaxIOPSDisk=toint(DiskIOPS_s), DiskSizeGB_s, SKU_s, DiskTier_s, DiskType_s
) on ResourceId
| project-away ResourceId1
Expand All @@ -234,7 +235,8 @@ $baseQuery = @"
| summarize MaxMBsMetric = max(todouble(MetricValue_s)/1024/1024) by ResourceId
| join kind=inner (
$disksTableName
| where TimeGenerated > ago(1d) and DiskState_s != 'Unattached' and SKU_s startswith 'Premium'
| where TimeGenerated > ago(1d) and DiskState_s =~ 'Attached' and SKU_s startswith 'Premium'
| extend DiskTier_s = strcat(DiskTier_s, ' ', tostring(split(SKU_s, '_')[1]))
| project ResourceId=InstanceId_s, DiskName_s, ResourceGroup = ResourceGroupName_s, SubscriptionId = SubscriptionGuid_g, Cloud_s, TenantGuid_g, Tags_s, MaxMBsDisk=toint(DiskThroughput_s), DiskSizeGB_s, SKU_s, DiskTier_s, DiskType_s
) on ResourceId
| project-away ResourceId1
Expand Down Expand Up @@ -280,7 +282,7 @@ foreach ($result in $results)
$targetSku = $null
$currentDiskTier = $null

if ([string]::IsNullOrEmpty($result.DiskTier_s)) # older disks do not have Tier info in their properties
if ([string]::IsNullOrEmpty($result.DiskTier_s) -or $result.DiskTier_s.Trim().Length -le 3) # older disks do not have Tier info in their properties
{
$currentSkuCandidates = @()
foreach ($sku in $skus)
Expand All @@ -294,13 +296,14 @@ foreach ($result in $results)
if ($sku.Name -eq $result.SKU_s -and $skuMinSizeGB -lt [int]$result.DiskSizeGB_s -and $skuMaxSizeGB -ge [int]$result.DiskSizeGB_s `
-and [int]$skuMaxIOps -eq [int]$result.MaxIOPSDisk -and [int]$skuMaxBandwidthMBps -eq [int]$result.MaxMBsDisk)
{
if ($null -eq $skuPricesFound[$sku.Size])
$skuSize = $sku.Size + " " + $result.SKU_s.Split("_")[1]
if ($null -eq $skuPricesFound[$skuSize])
{
$skuPricesFound[$sku.Size] = Find-DiskMonthlyPrice -DiskSizeTier $sku.Size -SKUPriceSheet $pricesheetEntries
$skuPricesFound[$sku.Size] = Find-DiskMonthlyPrice -DiskSizeTier $skuSize -SKUPriceSheet $pricesheetEntries
}

$currentSkuCandidate = New-Object PSObject -Property @{
Name = $sku.Size
Name = $skuSize
MaxSizeGB = $skuMaxSizeGB
}

Expand Down Expand Up @@ -334,16 +337,17 @@ foreach ($result in $results)
if ($sku.Name -eq $targetSkuPerfTier -and $skuMinSizeGB -lt [int]$result.DiskSizeGB_s -and $skuMaxSizeGB -ge [int]$result.DiskSizeGB_s `
-and [double]$skuMaxIOps -ge [double]$result.MaxIOPSMetric -and [double]$skuMaxBandwidthMBps -ge [double]$result.MaxMBsMetric)
{
$skuSize = $sku.Size + " " + $targetSkuPerfTier.Split("_")[1]
if ($null -eq $skuPricesFound[$sku.Size])
{
$skuPricesFound[$sku.Size] = Find-DiskMonthlyPrice -DiskSizeTier $sku.Size -SKUPriceSheet $pricesheetEntries
$skuPricesFound[$skuSize] = Find-DiskMonthlyPrice -DiskSizeTier $skuSize -SKUPriceSheet $pricesheetEntries
}

if ($skuPricesFound[$sku.Size] -lt [double]::MaxValue -and $skuPricesFound[$sku.Size] -lt $skuPricesFound[$currentDiskTier])
if ($skuPricesFound[$skuSize] -lt [double]::MaxValue -and $skuPricesFound[$skuSize] -lt $skuPricesFound[$currentDiskTier])
{
$targetSkuCandidate = New-Object PSObject -Property @{
Name = $sku.Size
MonthlyPrice = $skuPricesFound[$sku.Size]
Name = $skuSize
MonthlyPrice = $skuPricesFound[$skuSize]
MaxSizeGB = $skuMaxSizeGB
MaxIOPS = $skuMaxIOps
MaxMBps = $skuMaxBandwidthMBps
Expand Down
6 changes: 3 additions & 3 deletions src/optimization-engine/upgrade-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@
"schedule": "AzureOptimization_ExportMonitorDiskIOPSHourly",
"parameters": {
"ResourceType": "microsoft.compute/disks",
"ARGFilter": "sku.name =~ 'Premium_LRS' and properties.diskState != 'Unattached'",
"ARGFilter": "sku.name startswith 'Premium_' and properties.diskState =~ 'Attached'",
"TimeSpan": "01:00:00",
"aggregationType": "Average",
"AggregationOfType": "Maximum",
Expand All @@ -675,7 +675,7 @@
"schedule": "AzureOptimization_ExportMonitorDiskMBPsHourly",
"parameters": {
"ResourceType": "microsoft.compute/disks",
"ARGFilter": "sku.name =~ 'Premium_LRS' and properties.diskState != 'Unattached'",
"ARGFilter": "sku.name startswith 'Premium_' and properties.diskState =~ 'Attached'",
"TimeSpan": "01:00:00",
"aggregationType": "Average",
"AggregationOfType": "Maximum",
Expand Down Expand Up @@ -969,7 +969,7 @@
{
"runbook": {
"name": "runbooks/recommendations/Recommend-DiskOptimizationsToBlobStorage.ps1",
"version": "1.1.1.0"
"version": "1.1.2.0"
},
"requiredVariables": [
{
Expand Down