Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions cmd/unused-exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
}

Expand All @@ -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]
Comment on lines +295 to +298
Copy link
Collaborator

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:

Suggested change
case providerAWS :
return z[:len(z)-1]
case providerGCP:
return z[:len(z)-2]
case aws.ProviderName:
return z[:len(z)-1]
case gcp.ProviderName:
return z[:len(z)-2]

Note that by doing this and changing the if in 269 accordingly, you can get rid of the new constants in line 15.

default:
Comment on lines +294 to +299
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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]
}
Loading