Skip to content

Commit

Permalink
compute: retrieving the Resource SKUs for the current location only
Browse files Browse the repository at this point in the history
This fixes an issue where we're unintentionally loading information about all SKUs in all Locations rather
than filtering to the specific location - which has become progressively larger.

This reduces the memory footprint passing through this function down by 10x
  • Loading branch information
tombuildsstuff committed Apr 9, 2024
1 parent 38c1fd7 commit e0272d8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions internal/services/compute/no_downtime_resize.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package compute
import (
"context"
"fmt"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"

Check failure on line 9 in internal/services/compute/no_downtime_resize.go

View workflow job for this annotation

GitHub Actions / golint

File is not `goimports`-ed (goimports)
"log"
"strings"

Expand Down Expand Up @@ -81,16 +82,24 @@ func determineIfVirtualMachineSkuSupportsNoDowntimeResize(ctx context.Context, v
return nil, fmt.Errorf("retrieving %s: %+v", *virtualMachineId, err)
}

vmLocation := ""
vmSku := ""
if model := virtualMachine.Model; model != nil && model.Properties != nil && model.Properties.HardwareProfile != nil && model.Properties.HardwareProfile.VMSize != nil {
vmSku = string(*model.Properties.HardwareProfile.VMSize)
if model := virtualMachine.Model; model != nil {
vmLocation = location.Normalize(model.Location)
if model.Properties != nil && model.Properties.HardwareProfile != nil && model.Properties.HardwareProfile.VMSize != nil {
vmSku = string(*model.Properties.HardwareProfile.VMSize)
}
}
if vmSku == "" {
if vmLocation == "" || vmSku == "" {
return pointer.To(false), nil
}

subscriptionId := commonids.NewSubscriptionID(virtualMachineId.SubscriptionId)
skusResponse, err := skusClient.ResourceSkusListComplete(ctx, subscriptionId, skus.DefaultResourceSkusListOperationOptions())
opts := skus.DefaultResourceSkusListOperationOptions()
// @tombuildsstuff: by default this API returns EVERY SKU in EVERY LOCATION meaning this will get
// progressively larger each time - instead we filter to the current Location only.
opts.Filter = pointer.To(fmt.Sprintf("location eq '%s'", vmLocation))
skusResponse, err := skusClient.ResourceSkusListComplete(ctx, subscriptionId, opts)
if err != nil {
return nil, fmt.Errorf("retrieving information about the Resource SKUs to check if the Virtual Machine/Disk combination supports no-downtime-resizing: %+v", err)
}
Expand Down

0 comments on commit e0272d8

Please sign in to comment.