Skip to content

Commit

Permalink
POL-1329 Fix calculation of IOPS and Bandwith at Azure Rightsize Mana…
Browse files Browse the repository at this point in the history
…ged Disk (#2713)

* POL-1329 Fix calculation

* Simplify formula for maxIops

* Replace while(true) by do while

---------

Co-authored-by: midir99 <[email protected]>
  • Loading branch information
midir99 and midir99 authored Oct 3, 2024
1 parent c2d5784 commit 19b75bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions cost/azure/rightsize_managed_disks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v2.4.1

- Fixed a bug that showed wrong calculations for changing the disk capacity, IOPS and throughput.

## v2.4.0

- Added a parameter to select the interval to use when gathering Azure metrics data.
Expand Down
37 changes: 22 additions & 15 deletions cost/azure/rightsize_managed_disks/azure_rightsize_managed_disks.pt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Cost"
severity "low"
default_frequency "monthly"
info(
version: "2.4.0",
version: "2.4.1",
provider: "Azure",
service: "Managed Disks",
policy_set: "Rightsize Storage",
Expand Down Expand Up @@ -1060,42 +1060,49 @@ script "js_disk_rightsizing_recommendations", type: "javascript" do
return priceData
}
// When looking at the findPremSsdV2Price function check: https://learn.microsoft.com/es-es/azure/virtual-machines/disks-types#premium-ssd-v2-performance
function findPremSsdV2Price(diskRegion, currentUsedGB, currentUsedIops, currentUsedThroughput) {
var premSsdV2Pricing = ds_azure_md_pricing[diskRegion]
if (premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_CAPACITY === undefined) { return }
if (currentUsedIops <= 3000 && currentUsedThroughput <= 3000) {
if (currentUsedIops <= 3000 && currentUsedThroughput <= 125) {
return {
pricePerUnit: Math.round( premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_CAPACITY.pricePerUnit * 720 * currentUsedGB ),
currencyCode: premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_CAPACITY.currencyCode,
sizeGiB: currentUsedGB,
// Premium SSD v2 provides a baseline performance of 3,000 IOPS and 125 MB/s for any disk size
// Premium SSD v2 provides a baseline performance of 3000 IOPS and 125 MB/s for any disk size without extra charge.
IOPS: 3000,
throughput: 125,
unitOfMeasure: premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_CAPACITY.unitOfMeasure
}
}
var diskIopsAndThroughputDontFitInDiskSize = true
var suggestedDiskSize = currentUsedGB
var maxIops = 0
var maxThroughput = 0
while (diskIopsAndThroughputDontFitInDiskSize) {
maxIops = suggestedDiskSize * 500
maxThroughput = maxIops * 0.25
if (currentUsedIops <= maxIops && currentUsedThroughput <= maxThroughput) {
diskIopsAndThroughputDontFitInDiskSize = false
do {
if (suggestedDiskSize <= 6) {
maxIops = 3000
} else {
maxIops = suggestedDiskSize * 500
if (maxIops > 80000) {
maxIops = 80000
}
}
maxThroughput = maxIops / 4
if (maxThroughput > 1250) {
maxThroughput = 1250
}
suggestedDiskSize += 1
}
} while (currentUsedIops > maxIops || currentUsedThroughput > maxThroughput)
return {
pricePerUnit: Math.round(
(premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_CAPACITY.pricePerUnit * 720 * suggestedDiskSize)
+ (premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_IOPS.pricePerUnit * 720 * currentUsedIops)
+ (premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_THROUGHPUT_MBPS.pricePerUnit * 720 * currentUsedThroughput)
(premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_CAPACITY.pricePerUnit * 720 * suggestedDiskSize)
+ (premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_IOPS.pricePerUnit * 720 * (currentUsedIops - 3000)) // At this point currentUsedIops is greater than 3000.
+ (premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_THROUGHPUT_MBPS.pricePerUnit * 720 * (currentUsedThroughput - 125)) // At this point currentUsedThroughput is greater than 125.
),
currencyCode: premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_CAPACITY.currencyCode,
sizeGiB: suggestedDiskSize,
IOPS: maxIops,
throughput: maxThroughput,
IOPS: currentUsedIops,
throughput: currentUsedThroughput,
unitOfMeasure: premSsdV2Pricing.PREMIUM_LRS_PROVISIONED_CAPACITY.unitOfMeasure,
}
}
Expand Down

0 comments on commit 19b75bf

Please sign in to comment.