-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
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.
"Extreme PD Capacity", | ||
"Storage PD Capacity", |
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.
Removes these because we explicitly need them now.
price, err := getPricingInfoFromSku(sku) | ||
if err != nil { | ||
return nil, PricingDataIsOff | ||
} | ||
|
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.
Moved this into the respective code blocks for compute and storage parsing.
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.
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?
pkg/google/compute/pricing_map.go
Outdated
) | ||
|
||
const ( | ||
hoursInMonth = 730.5 |
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.
Is it possible we have this value already in another module?
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.
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?
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.
create something like pkg/utils/consts.go
?
to put magic numbers in
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.
This feels too much of a magic number. Perhaps something like the following makes it easier to maintain in the future:
hoursInMonth = 730.5 | |
// hoursInMonth is the average of hours in a month, computed as | |
hoursInMonth = 24.35 * 30 |
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.
I like pkg/utils/consts.go
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.
Let's do it
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.
Moved over on latest push. Thanks all!
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.
So far LGTM! Left a few comments, happy to discuss them 😸
pkg/google/compute/pricing_map.go
Outdated
) | ||
|
||
const ( | ||
hoursInMonth = 730.5 |
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.
This feels too much of a magic number. Perhaps something like the following makes it easier to maintain in the future:
hoursInMonth = 730.5 | |
// hoursInMonth is the average of hours in a month, computed as | |
hoursInMonth = 24.35 * 30 |
pkg/google/compute/pricing_map.go
Outdated
@@ -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) |
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.
Nitpick: remove commented out lines.
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.
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/compute/pricing_map.go
Outdated
) | ||
|
||
const ( | ||
hoursInMonth = 730.5 |
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.
create something like pkg/utils/consts.go
?
to put magic numbers in
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.
Getting nicer and nicer! FWIW, LGTM.
Co-authored-by: Leandro López <[email protected]>
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.
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
This implements a
ListDisks
method ingke
that is then used to list out disks for the GKE projects by zone.ListDisks
will currently return a rawcompute.Disk
struct that is filtered by2. Disks only associated with GKE clusters