Skip to content

Commit

Permalink
POL-1393 Downsize Multiple Sizes: Azure Rightsize SQL Databases (#2788)
Browse files Browse the repository at this point in the history
* update

* fix

* update

* fix

* update

* fix

* update

* update

* update

* update

* update
  • Loading branch information
XOmniverse authored Oct 29, 2024
1 parent cbb55c5 commit 7fde85f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
4 changes: 4 additions & 0 deletions cost/azure/rightsize_sql_instances/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v5.5.0

- Added support for downsizing multiple sizes where appropriate

## v5.4.2

- Minor code improvements to conform with current standards. Functionality unchanged.
Expand Down
3 changes: 2 additions & 1 deletion cost/azure/rightsize_sql_instances/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 instance, multiplied by the recommended capacity of the instance, and then subtracted from the current cost of the instance.
- 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 Down Expand Up @@ -46,6 +46,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 instances. 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 instances, underutilized instances, or both. If both are selected, unused instances will not appear in the list of underutilized instances regardless of CPU usage.
- *Underutilized Instance CPU Threshold (%)* - The CPU threshold at which to consider an instance 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: "5.4.2",
version: "5.5.0",
provider: "Azure",
service: "SQL",
policy_set: "Rightsize Database Instances",
Expand Down Expand Up @@ -151,6 +151,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 @@ -657,11 +666,11 @@ datasource "ds_azure_sql_resize_map" do
end

datasource "ds_merged_metrics" do
run_script $js_merged_metrics, $ds_azure_sql_database_metrics, $ds_azure_sql_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_sql_database_metrics, $ds_azure_sql_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_sql_database_metrics", "ds_azure_sql_resize_map", "ds_applied_policy", "param_stats_underutil_threshold_cpu_value", "param_stats_lookback", "param_unused_or_underutilized", "param_stats_threshold"
parameters "ds_azure_sql_database_metrics", "ds_azure_sql_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 @@ -804,6 +813,16 @@ script "js_merged_metrics", type: "javascript" do
if (typeof(ds_azure_sql_resize_map[tier][type]['down']) == 'string') {
instance['newResourceType'] = ds_azure_sql_resize_map[tier][type]['down']
if (param_downsize_multiple == "Yes") {
type = instance['sku']['name'] + '_' + instance['newResourceType']
while (typeof(ds_azure_sql_resize_map[tier][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[tier][type]['down']
type = instance['sku']['name'] + '_' + instance['newResourceType']
}
}
instance["recommendationDetails"] = [
"Downsize Azure SQL database ", 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: "5.4.2", # 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: "5.5.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 @@ -176,6 +176,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 @@ -3994,7 +3994,7 @@
{
"id": "./cost/azure/rightsize_sql_instances/azure_rightsize_sql_instances.pt",
"name": "Azure Rightsize SQL Databases",
"version": "5.4.2",
"version": "5.5.0",
"providers": [
{
"name": "azure_rm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,7 @@
required: true
- id: "./cost/azure/rightsize_sql_instances/azure_rightsize_sql_instances.pt"
name: Azure Rightsize SQL Databases
version: 5.4.2
version: 5.5.0
:providers:
- :name: azure_rm
:permissions:
Expand Down

0 comments on commit 7fde85f

Please sign in to comment.