-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixup region label for GPC #93
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,12 @@ import ( | |
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const namespace = "unused" | ||
const ( | ||
namespace = "unused" | ||
providerGCP = "GCP" | ||
providerAWS = "AWS" | ||
providerAzure = "Azure" | ||
) | ||
|
||
type metric struct { | ||
desc *prometheus.Desc | ||
|
@@ -261,7 +266,7 @@ func getDiskLabels(d unused.Disk, v bool) []any { | |
} | ||
|
||
func getNamespace(d unused.Disk, p unused.Provider) string { | ||
if strings.ToLower(p.Name()) == "azure" { | ||
if p.Name() == providerAzure { | ||
return d.Meta()["kubernetes.io-created-for-pvc-namespace"] | ||
} | ||
|
||
|
@@ -286,10 +291,12 @@ func lastUsedTS(d unused.Disk) float64 { | |
} | ||
|
||
func getRegionFromZone(p unused.Provider, z string) string { | ||
if strings.ToLower(p.Name()) == "azure" { | ||
switch p.Name() { | ||
case providerAWS : | ||
return z[:len(z)-1] | ||
case providerGCP: | ||
return z[:len(z)-2] | ||
default: | ||
Comment on lines
+294
to
+299
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this warrants adding some tests to ensure a regression isn't introduced and some comments with maybe an example so its' clear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nevermind, it's already legacy, jjo sneaked this one in yesterday 🤣 lemme give it another spin |
||
return z | ||
} | ||
|
||
// Drop the last character to get the region from the zone for GCP and AWS | ||
return z[:len(z)-1] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #93 @jjo introduced a change that allow the user to change the provider name. This would break this switch and the if in line 269. I'd recommend instead doing the following:
Note that by doing this and changing the if in 269 accordingly, you can get rid of the new constants in line 15.