-
Notifications
You must be signed in to change notification settings - Fork 435
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
Add initial support of GCP disks and snaphosts cost #853
Add initial support of GCP disks and snaphosts cost #853
Conversation
nemca
commented
Jun 14, 2023
•
edited
Loading
edited
- initial support of GCP disks cost
- new time helper EndingOfMonth
- linting fix version subcommand
- refactoring instance cost calculation
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.
Hey @nemca, amazing work on this! And the fact that you have also added tests for the same, hats off! 🚀
I have just left some small refactoring and nits, let me know what you think of those!
I tested the pricing for a couple of my disks on GCP and it seemed accurate to me. However, I'll comment more on this once we have the Catalog API implemented (if we go ahead with it).
All in all, adding cost calculation is my favourite kind of PR reviews haha!
providers/gcp/compute/disks.go
Outdated
type calculateDiskCostData struct { | ||
diskType string | ||
size int64 | ||
project string | ||
zone string | ||
pricing *gcpcomputepricing.Pricing | ||
} |
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.
Can we shift this to a types_gcp_disks.go
under utils/ directory for uniformity? What do you think?
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.
Good idea, i'll be 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.
Move to utils/gcpcomputepricing/types_disk.go
providers/gcp/compute/disks.go
Outdated
case strings.Contains(strings.ToLower(*dt.Name), strings.ToLower(gcpcomputepricing.Standard)): | ||
opts.DiskType = gcpcomputepricing.Standard | ||
case strings.Contains(strings.ToLower(*dt.Name), strings.ToLower(gcpcomputepricing.SSD)): | ||
opts.DiskType = gcpcomputepricing.SSD | ||
case strings.Contains(strings.ToLower(*dt.Name), strings.ToLower(gcpcomputepricing.Balanced)): | ||
opts.DiskType = gcpcomputepricing.Balanced |
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.
small nit: we can prolly wrap the strings.Contains(strings.ToLower(str))
in a function and just call it directly leading to better code readability
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
DiskType string | ||
DiskSize uint64 |
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.
verify if this addition to the Opts
struct can be used to get more accurate costs in other cases as well
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 didn't understand your question very well.
But I refactored the code and removed the redundant DiskType
field from this structure.
I plan to start migrating to the Catalog API right now. |
Pricing for PD Standard work well ;-) |
providers/gcp/compute/disks.go
Outdated
case strings.Contains(strings.ToLower(*dt.Name), strings.ToLower(gcpcomputepricing.Standard)): | ||
opts.DiskType = gcpcomputepricing.Standard | ||
case strings.Contains(strings.ToLower(*dt.Name), strings.ToLower(gcpcomputepricing.SSD)): | ||
opts.DiskType = gcpcomputepricing.SSD | ||
case strings.Contains(strings.ToLower(*dt.Name), strings.ToLower(gcpcomputepricing.Balanced)): | ||
opts.DiskType = gcpcomputepricing.Balanced |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Hey @nemca, great work! thanks for incorporating the feedback! I see that you also added support for GCP Snapshots as well! 👏🏼 I like the code structuring now :)) I still saw a couple of ToDos so let me know once they are wrapped up and I'll try to checkout and see your feature locally here haha! But great work! No major feedback from me rn, might come up when I test it 🤞🏼 |
I'm found a bug with calculating instances cost. Stay tuned... |
v3.0.19 release 🚀
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!
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.
Please see if you can handle the suggested small changes, would be helpful
providers/gcp/compute/snapshots.go
Outdated
logrus.WithFields(logrus.Fields{ | ||
"provider": "GCP", | ||
"account": client.Name, | ||
"service": "Compute Engine", |
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.
nit: renaming this to Snapshots?
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.
@nemca could you make this small changes please? might help in the future in debugging?
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.
good catch, I agree :)
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.
nit: renaming this to Snapshots?
Maybe Compute Engine Snapshots
?
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.
Or Compute Disk Snapshot
, like the value of the Service
field above in the resource?
|
||
func typeSnapshotGetter(p *Pricing, opts Opts) (Subtype, error) { | ||
var capacity Subtype | ||
// TODO: switch by snapshot type |
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 this still pending? or have you handled this?
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.
Yes, still pending. I'm can't found where I can fetch snapshot types from API
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.
Hey @nemca, just reviewed and tested the PR and it looks amazing!
Adding cost calculation to GCP Disks is a great feature you have just added since it is used by most of the Instances and commonly seen across most of the cloud projects. The PR looks great to me and thank you so much for being patient with all the small and nit queries I had. Great work! Really excited to see this go live now! 🚀
Over to youuu @mlabouardy