Skip to content

Commit 2cafcb1

Browse files
committed
fix: Fixes right sizing pull request
1 parent 60b1b1b commit 2cafcb1

File tree

5 files changed

+158
-120
lines changed

5 files changed

+158
-120
lines changed

Diff for: cmd/terraform.go

+15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/spf13/cobra"
1515
"github.com/zclconf/go-cty/cty"
1616
"regexp"
17+
"strconv"
1718
"strings"
1819
"time"
1920
)
@@ -23,6 +24,7 @@ var terraformCmd = &cobra.Command{
2324
Short: "Create pull request for right sizing opportunities on your terraform git",
2425
Long: "Create pull request for right sizing opportunities on your terraform git",
2526
RunE: func(cmd *cobra.Command, args []string) error {
27+
ignoreYoungerThan := utils.ReadIntFlag(cmd, "ignore-younger-than")
2628
contentBytes, err := github.GetFile(
2729
utils.ReadStringFlag(cmd, "github-owner"),
2830
utils.ReadStringFlag(cmd, "github-repo"),
@@ -100,13 +102,22 @@ var terraformCmd = &cobra.Command{
100102
rightSizingDescription := map[string]string{}
101103
for _, item := range jsonObj.Items {
102104
var recommendedInstanceSize string
105+
maxRuntimeHours := int64(1) // since default for ignoreYoungerThan is 1
103106
for _, device := range item.Devices {
104107
for _, property := range device.Properties {
108+
if property.Key == "RuntimeHours" {
109+
i, _ := strconv.ParseInt(property.Current, 10, 64)
110+
maxRuntimeHours = max(maxRuntimeHours, i)
111+
}
105112
if property.Key == "Instance Size" && property.Current != property.Recommended {
106113
recommendedInstanceSize = property.Recommended
107114
}
108115
}
109116
}
117+
118+
if maxRuntimeHours < ignoreYoungerThan {
119+
continue
120+
}
110121
if recommendedInstanceSize == "" {
111122
continue
112123
}
@@ -176,6 +187,10 @@ var terraformCmd = &cobra.Command{
176187
description += fmt.Sprintf("Changing instance class of %s to %s\n", id, recommendation[id])
177188
description += rightSizingDescription[id] + "\n\n"
178189
}
190+
191+
if countRightSized == 0 {
192+
return nil
193+
}
179194
return github.ApplyChanges(
180195
utils.ReadStringFlag(cmd, "github-owner"),
181196
utils.ReadStringFlag(cmd, "github-repo"),

Diff for: pkg/plugin/proto/plugin.proto

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ message Property {
4444
string average = 3;
4545
string max = 4;
4646
string recommended = 5;
47+
bool hidden = 6;
4748
}
4849

4950
message Device {

0 commit comments

Comments
 (0)