Skip to content

Commit

Permalink
POL-1394 Downsize Multiple Sizes: Azure MySQL (#2790)
Browse files Browse the repository at this point in the history
* update

* fix

* update

* fix

* update

* fix

* update

* update

* update

* update
  • Loading branch information
XOmniverse authored Oct 30, 2024
1 parent 6b5ebe7 commit c764ecf
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 14 deletions.
4 changes: 4 additions & 0 deletions cost/azure/rightsize_mysql_flexible/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.0

- Added support for downsizing multiple sizes where appropriate

## v0.1.1

- Minor code improvements to conform with current standards. Functionality unchanged.
Expand Down
3 changes: 2 additions & 1 deletion cost/azure/rightsize_mysql_flexible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The policy includes the estimated monthly savings. The estimated monthly savings

- The `Estimated Monthly Savings` is calculated by multiplying the amortized cost of the resource for 1 day, as found within Flexera CCO, by 30.44, which is the average number of days in a month.
- For unused resources, the `Estimated Monthly Savings` is the full cost of the resource.
- For underutilized resources, the `Estimated Monthly Savings` is the full cost of the resource is divided by the current capacity of the server, multiplied by the recommended capacity of the server, and then subtracted from the current cost of the server.
- For underutilized resources, the savings is the difference of the current cost of the resource and the estimated cost of the recommended resource type.
- Since the costs of individual resources are obtained from Flexera CCO, they will take into account any Flexera adjustment rules or cloud provider discounts present in the Flexera platform.
- If the resource cannot be found in Flexera CCO, the `Estimated Monthly Savings` is 0.
- The incident message detail includes the sum of each resource `Estimated Monthly Savings` as `Potential Monthly Savings`.
Expand All @@ -45,6 +45,7 @@ The policy includes the estimated monthly savings. The estimated monthly savings
- *Statistic Lookback Period* - How many days back to look at connection and CPU utilization data for servers. This value cannot be set higher than 90 because Azure does not retain metrics for longer than 90 days.
- *Report Unused or Underutilized* - Whether to report on unused servers, underutilized servers, or both. If both are selected, unused servers will not appear in the list of underutilized servers regardless of CPU usage.
- *Underutilized Server CPU Threshold (%)* - The CPU threshold at which to consider an server to be underutilized and therefore be flagged for downsizing.
- *Skip Instance Sizes* - Whether to recommend downsizing multiple sizes. When set to 'No', only the next smaller size will ever be recommended for downsizing. When set to 'Yes', more aggressive downsizing recommendations will be made when appropriate.
- *Automatic Actions* - When this value is set, this policy will automatically take the selected action(s).

Please note that the "Automatic Actions" parameter contains a list of action(s) that can be performed on the resources. When it is selected, the policy will automatically execute the corresponding action on the data that failed the checks, post incident generation. Please leave it blank for *manual* action.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Cost"
severity "low"
default_frequency "weekly"
info(
version: "0.1.1",
version: "0.2.0",
provider: "Azure",
service: "MySQL",
policy_set: "Rightsize Database Instances",
Expand Down Expand Up @@ -142,6 +142,15 @@ parameter "param_stats_lookback" do
default 30
end

parameter "param_downsize_multiple" do
type "string"
category "Policy Settings"
label "Skip Instance Sizes"
description "Whether to recommend downsizing multiple sizes. When set to 'No', only the next smaller size will ever be recommended for downsizing. When set to 'Yes', more aggressive downsizing recommendations will be made when appropriate."
allowed_values "Yes", "No"
default "No"
end

parameter "param_automatic_action" do
type "list"
category "Actions"
Expand Down Expand Up @@ -586,11 +595,11 @@ datasource "ds_azure_mysql_resize_map" do
end

datasource "ds_merged_metrics" do
run_script $js_merged_metrics, $ds_azure_mysql_metrics, $ds_azure_mysql_resize_map, $ds_applied_policy, $param_stats_underutil_threshold_cpu_value, $param_stats_lookback, $param_unused_or_underutilized, $param_stats_threshold
run_script $js_merged_metrics, $ds_azure_mysql_metrics, $ds_azure_mysql_resize_map, $ds_applied_policy, $param_stats_underutil_threshold_cpu_value, $param_stats_lookback, $param_unused_or_underutilized, $param_stats_threshold, $param_downsize_multiple
end

script "js_merged_metrics", type: "javascript" do
parameters "ds_azure_mysql_metrics", "ds_azure_mysql_resize_map", "ds_applied_policy", "param_stats_underutil_threshold_cpu_value", "param_stats_lookback", "param_unused_or_underutilized", "param_stats_threshold"
parameters "ds_azure_mysql_metrics", "ds_azure_mysql_resize_map", "ds_applied_policy", "param_stats_underutil_threshold_cpu_value", "param_stats_lookback", "param_unused_or_underutilized", "param_stats_threshold", "param_downsize_multiple"
result "result"
code <<-'EOS'
// Function to calculate percentiles from metrics
Expand Down Expand Up @@ -735,6 +744,14 @@ script "js_merged_metrics", type: "javascript" do
instance['newResourceType'] = ds_azure_mysql_resize_map[instance['skuTier']][instance['resourceType']]['down_sku']
instance['newCapacity'] = getCapacityFromSKU(instance['newResourceType'])
if (param_downsize_multiple == "Yes") {
while (typeof(ds_azure_mysql_resize_map[instance['skuTier']][instance['newResourceType']]['down_sku']) == 'string' && cpu_test_value * 2 <= param_stats_underutil_threshold_cpu_value) {
cpu_test_value = cpu_test_value * 2
instance['newResourceType'] = ds_azure_mysql_resize_map[instance['skuTier']][instance['newResourceType']]['down_sku']
instance['newCapacity'] = getCapacityFromSKU(instance['newResourceType'])
}
}
instance["recommendationDetails"] = [
"Downsize Azure MySQL Flexible Server ", instance["name"], " ",
"in Azure Subscription ", instance["subscriptionName"], " ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Meta"
default_frequency "15 minutes"
info(
provider: "Azure",
version: "0.1.1", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
version: "0.2.0", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "true",
deprecated: "false"
)
Expand Down Expand Up @@ -167,6 +167,15 @@ parameter "param_stats_lookback" do
default 30
end

parameter "param_downsize_multiple" do
type "string"
category "Policy Settings"
label "Skip Instance Sizes"
description "Whether to recommend downsizing multiple sizes. When set to 'No', only the next smaller size will ever be recommended for downsizing. When set to 'Yes', more aggressive downsizing recommendations will be made when appropriate."
allowed_values "Yes", "No"
default "No"
end

parameter "param_automatic_action" do
type "list"
category "Actions"
Expand Down
4 changes: 4 additions & 0 deletions cost/azure/rightsize_mysql_single/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.0

- Added support for downsizing multiple sizes where appropriate

## v0.1.1

- Minor code improvements to conform with current standards. Functionality unchanged.
Expand Down
3 changes: 2 additions & 1 deletion cost/azure/rightsize_mysql_single/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The policy includes the estimated monthly savings. The estimated monthly savings

- The `Estimated Monthly Savings` is calculated by multiplying the amortized cost of the resource for 1 day, as found within Flexera CCO, by 30.44, which is the average number of days in a month.
- For unused resources, the `Estimated Monthly Savings` is the full cost of the resource.
- For underutilized resources, the `Estimated Monthly Savings` is the full cost of the resource is divided by the current capacity of the server, multiplied by the recommended capacity of the server, and then subtracted from the current cost of the server.
- For underutilized resources, the savings is the difference of the current cost of the resource and the estimated cost of the recommended resource type.
- Since the costs of individual resources are obtained from Flexera CCO, they will take into account any Flexera adjustment rules or cloud provider discounts present in the Flexera platform.
- If the resource cannot be found in Flexera CCO, the `Estimated Monthly Savings` is 0.
- The incident message detail includes the sum of each resource `Estimated Monthly Savings` as `Potential Monthly Savings`.
Expand All @@ -45,6 +45,7 @@ The policy includes the estimated monthly savings. The estimated monthly savings
- *Statistic Lookback Period* - How many days back to look at connection and CPU utilization data for servers. This value cannot be set higher than 90 because Azure does not retain metrics for longer than 90 days.
- *Report Unused or Underutilized* - Whether to report on unused servers, underutilized servers, or both. If both are selected, unused servers will not appear in the list of underutilized servers regardless of CPU usage.
- *Underutilized Server CPU Threshold (%)* - The CPU threshold at which to consider an server to be underutilized and therefore be flagged for downsizing.
- *Skip Instance Sizes* - Whether to recommend downsizing multiple sizes. When set to 'No', only the next smaller size will ever be recommended for downsizing. When set to 'Yes', more aggressive downsizing recommendations will be made when appropriate.
- *Automatic Actions* - When this value is set, this policy will automatically take the selected action(s).

Please note that the "Automatic Actions" parameter contains a list of action(s) that can be performed on the resources. When it is selected, the policy will automatically execute the corresponding action on the data that failed the checks, post incident generation. Please leave it blank for *manual* action.
Expand Down
25 changes: 22 additions & 3 deletions cost/azure/rightsize_mysql_single/azure_rightsize_mysql_single.pt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Cost"
severity "low"
default_frequency "weekly"
info(
version: "0.1.1",
version: "0.2.0",
provider: "Azure",
service: "MySQL",
policy_set: "Rightsize Database Instances",
Expand Down Expand Up @@ -142,6 +142,15 @@ parameter "param_stats_lookback" do
default 30
end

parameter "param_downsize_multiple" do
type "string"
category "Policy Settings"
label "Skip Instance Sizes"
description "Whether to recommend downsizing multiple sizes. When set to 'No', only the next smaller size will ever be recommended for downsizing. When set to 'Yes', more aggressive downsizing recommendations will be made when appropriate."
allowed_values "Yes", "No"
default "No"
end

parameter "param_automatic_action" do
type "list"
category "Actions"
Expand Down Expand Up @@ -586,11 +595,11 @@ datasource "ds_azure_mysql_resize_map" do
end

datasource "ds_merged_metrics" do
run_script $js_merged_metrics, $ds_azure_mysql_metrics, $ds_azure_mysql_resize_map, $ds_applied_policy, $param_stats_underutil_threshold_cpu_value, $param_stats_lookback, $param_unused_or_underutilized, $param_stats_threshold
run_script $js_merged_metrics, $ds_azure_mysql_metrics, $ds_azure_mysql_resize_map, $ds_applied_policy, $param_stats_underutil_threshold_cpu_value, $param_stats_lookback, $param_unused_or_underutilized, $param_stats_threshold, $param_downsize_multiple
end

script "js_merged_metrics", type: "javascript" do
parameters "ds_azure_mysql_metrics", "ds_azure_mysql_resize_map", "ds_applied_policy", "param_stats_underutil_threshold_cpu_value", "param_stats_lookback", "param_unused_or_underutilized", "param_stats_threshold"
parameters "ds_azure_mysql_metrics", "ds_azure_mysql_resize_map", "ds_applied_policy", "param_stats_underutil_threshold_cpu_value", "param_stats_lookback", "param_unused_or_underutilized", "param_stats_threshold", "param_downsize_multiple"
result "result"
code <<-'EOS'
// Function to calculate percentiles from metrics
Expand Down Expand Up @@ -727,6 +736,16 @@ script "js_merged_metrics", type: "javascript" do
if (typeof(ds_azure_mysql_resize_map[instance['skuTier']][instance['skuName']]['down']) == 'string') {
instance['newResourceType'] = ds_azure_mysql_resize_map[instance['skuTier']][instance['skuName']]['down']
if (param_downsize_multiple == "Yes") {
type = instance['skuName'] + '_' + instance['newResourceType']
while (typeof(ds_azure_sql_resize_map[instance['skuTier']][type]['down']) == 'string' && cpu_test_value * 2 <= param_stats_underutil_threshold_cpu_value) {
cpu_test_value = cpu_test_value * 2
instance['newResourceType'] = ds_azure_sql_resize_map[instance['skuTier']][type]['down']
type = instance['skuName'] + '_' + instance['newResourceType']
}
}
instance["recommendationDetails"] = [
"Downsize Azure MySQL Single Server ", instance["name"], " ",
"in Azure Subscription ", instance["subscriptionName"], " ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Meta"
default_frequency "15 minutes"
info(
provider: "Azure",
version: "0.1.1", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
version: "0.2.0", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "true",
deprecated: "false"
)
Expand Down Expand Up @@ -167,6 +167,15 @@ parameter "param_stats_lookback" do
default 30
end

parameter "param_downsize_multiple" do
type "string"
category "Policy Settings"
label "Skip Instance Sizes"
description "Whether to recommend downsizing multiple sizes. When set to 'No', only the next smaller size will ever be recommended for downsizing. When set to 'Yes', more aggressive downsizing recommendations will be made when appropriate."
allowed_values "Yes", "No"
default "No"
end

parameter "param_automatic_action" do
type "list"
category "Actions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3857,7 +3857,7 @@
{
"id": "./cost/azure/rightsize_mysql_flexible/azure_rightsize_mysql_flexible.pt",
"name": "Azure Rightsize MySQL Flexible Servers",
"version": "0.1.1",
"version": "0.2.0",
"providers": [
{
"name": "azure_rm",
Expand Down Expand Up @@ -3901,7 +3901,7 @@
{
"id": "./cost/azure/rightsize_mysql_single/azure_rightsize_mysql_single.pt",
"name": "Azure Rightsize MySQL Single Servers",
"version": "0.1.1",
"version": "0.2.0",
"providers": [
{
"name": "azure_rm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@
required: true
- id: "./cost/azure/rightsize_mysql_flexible/azure_rightsize_mysql_flexible.pt"
name: Azure Rightsize MySQL Flexible Servers
version: 0.1.1
version: 0.2.0
:providers:
- :name: azure_rm
:permissions:
Expand All @@ -2263,7 +2263,7 @@
required: true
- id: "./cost/azure/rightsize_mysql_single/azure_rightsize_mysql_single.pt"
name: Azure Rightsize MySQL Single Servers
version: 0.1.1
version: 0.2.0
:providers:
- :name: azure_rm
:permissions:
Expand Down

0 comments on commit c764ecf

Please sign in to comment.