Skip to content

Commit

Permalink
POL-1443 AWS Rightsize Elasticache - Fix undeclared variable causing …
Browse files Browse the repository at this point in the history
…policy to fail (#2916)

* restructure code so `savings` is declared before being referenced

* updated changelog to reflect change

* update meta parent policy for aws rightsize elasticache

* updated policy permissions list to reflect correct template version
  • Loading branch information
nia-vf1 authored Jan 8, 2025
1 parent b225f99 commit bac94ed
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 56 deletions.
4 changes: 4 additions & 0 deletions cost/aws/rightsize_elasticache/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.3

- Fixed issue with a variable causing the policy to fail.

## v0.2.2

- Fixed issue with numeric currency values sometimes showing 'undefined' instead of currency separators
Expand Down
108 changes: 55 additions & 53 deletions cost/aws/rightsize_elasticache/aws_rightsize_elasticache.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.2.2",
version: "0.2.3",
provider: "AWS",
service: "Database",
policy_set: "Rightsize Database Instances",
Expand Down Expand Up @@ -1046,7 +1046,7 @@ script "js_underutilized_elasticache_clusters", type: "javascript" do
mem_underutilized = mem_stat > param_stats_threshold_mem_value || param_stats_threshold_mem_value == -1
// Check if cluster is underutilized and if savings is above threshold
if (cpu_underutilized && mem_underutilized && savings >= param_min_savings) {
if (cpu_underutilized && mem_underutilized) {
normalizedNewType = ds_aws_instance_size_map[cluster['normalizedType']]['down']
savingsMultiplier = 1
Expand Down Expand Up @@ -1085,61 +1085,63 @@ script "js_underutilized_elasticache_clusters", type: "javascript" do
savings = ds_cluster_costs_grouped[cluster['id']] / (2 * savingsMultiplier)
}
total_savings += savings
if (savings >= param_min_savings) {
total_savings += savings
recommendationDetails = [
"Change node type of ElastiCache cluster ", cluster['id'], " ",
"in AWS Account ", ds_aws_account['name'], " ",
"(", ds_aws_account['id'], ") ",
"from ", cluster['resourceType'], " ",
"to ", cluster['newResourceType']
].join('')
recommendationDetails = [
"Change node type of ElastiCache cluster ", cluster['id'], " ",
"in AWS Account ", ds_aws_account['name'], " ",
"(", ds_aws_account['id'], ") ",
"from ", cluster['resourceType'], " ",
"to ", cluster['newResourceType']
].join('')
tags = []
tags = []
if (typeof(cluster['tags']) == 'object') {
tags = _.map(cluster['tags'], function(tag) { return [tag['Key'], tag['Value']].join('=') })
}
if (typeof(cluster['tags']) == 'object') {
tags = _.map(cluster['tags'], function(tag) { return [tag['Key'], tag['Value']].join('=') })
}
result.push({
accountID: ds_aws_account['id'],
accountName: ds_aws_account['name'],
id: cluster["id"],
resourceID: cluster["resourceID"],
resourceName: cluster["resourceName"],
resourceARN: cluster["resourceARN"],
status: cluster["status"],
numberOfNodes: cluster["numberOfNodes"],
autoMinorVersionUpgrade: cluster["autoMinorVersionUpgrade"],
availabilityZone: cluster["availabilityZone"],
createTime: cluster["createTime"],
engine: cluster["engine"],
engineVersion: cluster["engineVersion"],
region: cluster["region"],
resourceType: cluster["resourceType"],
newResourceType: cluster["newResourceType"],
tags: tags.join(', '),
cpuAverage: Math.round(cluster["cpuAverage"] * 100) / 100,
cpuMinimum: Math.round(cluster["cpuMinimum"] * 100) / 100,
cpuMaximum: Math.round(cluster["cpuMaximum"] * 100) / 100,
cpuP90: Math.round(cluster["cpuP90"] * 100) / 100,
cpuP95: Math.round(cluster["cpuP95"] * 100) / 100,
cpuP99: Math.round(cluster["cpuP99"] * 100) / 100,
memAverage: Math.round(cluster["memAverage"] * 100) / 100,
memMinimum: Math.round(cluster["memMinimum"] * 100) / 100,
memMaximum: Math.round(cluster["memMaximum"] * 100) / 100,
memP90: Math.round(cluster["memP90"] * 100) / 100,
memP95: Math.round(cluster["memP95"] * 100) / 100,
memP99: Math.round(cluster["memP99"] * 100) / 100,
service: "AmazonElastiCache",
recommendationDetails: recommendationDetails,
savings: Math.round(savings * 1000) / 1000,
savingsCurrency: ds_currency['symbol'],
policy_name: ds_applied_policy['name'],
// These are to avoid errors when we hash_exclude these fields
message: "",
total_savings: ""
})
result.push({
accountID: ds_aws_account['id'],
accountName: ds_aws_account['name'],
id: cluster["id"],
resourceID: cluster["resourceID"],
resourceName: cluster["resourceName"],
resourceARN: cluster["resourceARN"],
status: cluster["status"],
numberOfNodes: cluster["numberOfNodes"],
autoMinorVersionUpgrade: cluster["autoMinorVersionUpgrade"],
availabilityZone: cluster["availabilityZone"],
createTime: cluster["createTime"],
engine: cluster["engine"],
engineVersion: cluster["engineVersion"],
region: cluster["region"],
resourceType: cluster["resourceType"],
newResourceType: cluster["newResourceType"],
tags: tags.join(', '),
cpuAverage: Math.round(cluster["cpuAverage"] * 100) / 100,
cpuMinimum: Math.round(cluster["cpuMinimum"] * 100) / 100,
cpuMaximum: Math.round(cluster["cpuMaximum"] * 100) / 100,
cpuP90: Math.round(cluster["cpuP90"] * 100) / 100,
cpuP95: Math.round(cluster["cpuP95"] * 100) / 100,
cpuP99: Math.round(cluster["cpuP99"] * 100) / 100,
memAverage: Math.round(cluster["memAverage"] * 100) / 100,
memMinimum: Math.round(cluster["memMinimum"] * 100) / 100,
memMaximum: Math.round(cluster["memMaximum"] * 100) / 100,
memP90: Math.round(cluster["memP90"] * 100) / 100,
memP95: Math.round(cluster["memP95"] * 100) / 100,
memP99: Math.round(cluster["memP99"] * 100) / 100,
service: "AmazonElastiCache",
recommendationDetails: recommendationDetails,
savings: Math.round(savings * 1000) / 1000,
savingsCurrency: ds_currency['symbol'],
policy_name: ds_applied_policy['name'],
// These are to avoid errors when we hash_exclude these fields
message: "",
total_savings: ""
})
}
}
})
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: "AWS",
version: "0.2.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: "0.2.3", # 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",
hide_skip_approvals: "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@
{
"id": "./cost/aws/rightsize_elasticache/aws_rightsize_elasticache.pt",
"name": "AWS Rightsize ElastiCache",
"version": "0.2.2",
"version": "0.2.3",
"providers": [
{
"name": "aws",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@
required: true
- id: "./cost/aws/rightsize_elasticache/aws_rightsize_elasticache.pt"
name: AWS Rightsize ElastiCache
version: 0.2.2
version: 0.2.3
:providers:
- :name: aws
:permissions:
Expand Down

0 comments on commit bac94ed

Please sign in to comment.