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

Get disk pricing working #118

Merged
merged 20 commits into from
Mar 22, 2024
Merged

Get disk pricing working #118

merged 20 commits into from
Mar 22, 2024

Conversation

Pokom
Copy link
Contributor

@Pokom Pokom commented Feb 22, 2024

This implements a ListDisks method in gke that is then used to list out disks for the GKE projects by zone.
ListDisks will currently return a raw compute.Disk struct that is filtered by
2. Disks only associated with GKE clusters

This implements a `ListDisks` method in `gke` that is then used to list
out disks for the GKE projects by zone.
`ListDisks` will currently return a raw `compute.Disk` struct that is
filtered by
1. Used disks
2. Disks only associated with GKE clusters

The exported price is assuming the disks costs $0.05/GiB/Month and
does not account for the type of disk.
Starts to updating compute pricing_map to also take into account
storage. Still need to add regex's to capture the data.

Added documentation for the pvc metrics.
Comment on lines -189 to -190
"Extreme PD Capacity",
"Storage PD Capacity",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes these because we explicitly need them now.

Comment on lines -204 to +251
price, err := getPricingInfoFromSku(sku)
if err != nil {
return nil, PricingDataIsOff
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this into the respective code blocks for compute and storage parsing.

@logyball logyball self-requested a review March 20, 2024 17:01
@Pokom Pokom marked this pull request as ready for review March 20, 2024 19:13
@Pokom Pokom requested a review from the-it March 20, 2024 19:40
Copy link
Member

@the-it the-it left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a first run on it (second view + local testing will follow). Should we implemend also a metric for compute, as a pure VM can also have persistent disks?

docs/metrics/gcp/persistentvolumes.md Outdated Show resolved Hide resolved
)

const (
hoursInMonth = 730.5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible we have this value already in another module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do, but I don't know if we have one common spot where we can introduce variables like this. Do you have any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create something like pkg/utils/consts.go?

to put magic numbers in

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels too much of a magic number. Perhaps something like the following makes it easier to maintain in the future:

Suggested change
hoursInMonth = 730.5
// hoursInMonth is the average of hours in a month, computed as
hoursInMonth = 24.35 * 30

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like pkg/utils/consts.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved over on latest push. Thanks all!

Copy link

@inkel inkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far LGTM! Left a few comments, happy to discuss them 😸

)

const (
hoursInMonth = 730.5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels too much of a magic number. Perhaps something like the following makes it easier to maintain in the future:

Suggested change
hoursInMonth = 730.5
// hoursInMonth is the average of hours in a month, computed as
hoursInMonth = 24.35 * 30

@@ -140,43 +172,68 @@ func GeneratePricingMap(skus []*billingpb.Sku) (*StructuredPricingMap, error) {
rawData, err := getDataFromSku(sku)

if errors.Is(err, SkuNotRelevant) {
log.Printf("%v: %s", SkuNotRelevant, sku.Description)
//log.Printf("%v: %s", SkuNotRelevant, sku.Description)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: remove commented out lines.

pkg/google/compute/pricing_map.go Outdated Show resolved Hide resolved
pkg/google/compute/pricing_map.go Outdated Show resolved Hide resolved
pkg/google/compute/pricing_map.go Outdated Show resolved Hide resolved
scripts/gcp-fetch-skus/gcp-fetch-skus.go Outdated Show resolved Hide resolved
Copy link
Contributor

@logyball logyball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! This is really cool stuff and overall works quite well.

I have a couple of NIT comments as well as questions. There's one thing that I think should absolutely be addressed (case where region is populated on the disk and spits out something like us-central1-f, resulting in missing the disk.

However, this is very impressive stuff. Let me know when you have a chance to take a look!

pkg/google/billing/billing.go Outdated Show resolved Hide resolved
)

const (
hoursInMonth = 730.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create something like pkg/utils/consts.go?

to put magic numbers in

pkg/google/compute/pricing_map.go Outdated Show resolved Hide resolved
pkg/google/compute/pricing_map.go Outdated Show resolved Hide resolved
pkg/google/compute/pricing_map.go Outdated Show resolved Hide resolved
pkg/google/compute/pricing_map_test.go Show resolved Hide resolved
pkg/google/gke/gke.go Show resolved Hide resolved
pkg/google/gke/gke.go Outdated Show resolved Hide resolved
pkg/google/gke/gke_test.go Outdated Show resolved Hide resolved
pkg/google/gke/gke_test.go Outdated Show resolved Hide resolved
Copy link

@inkel inkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting nicer and nicer! FWIW, LGTM.

pkg/google/compute/pricing_map.go Show resolved Hide resolved
pkg/google/gke/gke.go Show resolved Hide resolved
pkg/google/gke/gke.go Show resolved Hide resolved
@Pokom Pokom requested a review from logyball March 22, 2024 14:17
pkg/utils/consts.go Outdated Show resolved Hide resolved
pkg/google/gke/gke_test.go Outdated Show resolved Hide resolved
pkg/google/gke/gke_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@logyball logyball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice work.

As for the copying versus importing, I can see there being other use cases for the const package, but I also tend to agree with the "do the single thing" approach, and a "const" file is doing many things. But I also don't always agree with the programming dogmatism (my opinion here) that utility classes/functions/variables/etc are evil, as they often make it easier to not forget to update something in more than one place as a project grows.

That being said, unit and other tests are probably the things that we should rely on here rather than programming anti-patterns, even if you don't agree with them always being anti-patterns :D

@Pokom Pokom merged commit 47f5228 into main Mar 22, 2024
1 check passed
@Pokom Pokom deleted the feat/gke-pvcs branch March 22, 2024 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants