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

Estimate GCP VM pricing #776

Merged

Conversation

PumpkinSeed
Copy link
Contributor

@PumpkinSeed PumpkinSeed commented May 5, 2023

Resolve: #652

The price calculation of the GCP VM instances are a very complex thing, but it can be broken down to smaller pieces. The first piece is to calculate the price of the machine type what the instance originated. This solution get the actual pricing from the https://www.gstatic.com/cloud-site-ux/pricing/data/gcp-compute.json and start the calculation with the number of CPUs and memory under a certain machine type.

@PumpkinSeed PumpkinSeed changed the title Estimate GCP VM pricing [Draft] Estimate GCP VM pricing May 5, 2023
Copy link
Collaborator

@mlabouardy mlabouardy left a comment

Choose a reason for hiding this comment

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

Great job @PumpkinSeed I've shared some comments below once addressed we can move forward with the PR :)

go.mod Outdated Show resolved Hide resolved
}

var opts = gcpcomputepricing.Opts{
Commitment: gcpcomputepricing.OnDemand, // TODO decide this based on normal or Spot instance
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we pass this as a param to the calculateCost function instead of hardcoding it here? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is why the TODO is there. But I need to figure out which field will return that value from the VM instance's struct.

Copy link
Collaborator

Choose a reason for hiding this comment

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

if its not doable we can set OnDemand by default and in a future release we can allow user to change instance type (ondemand or spot) from the Komiser dashboard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just needed to check where the instance stores that information (whether it is preemptible or not). I found it, so I just modified it. It won't be 100% accurate, because it can be 1 year or 3 year commitment as well, but until that it is good to go.

providers/gcp/compute/instances.go Outdated Show resolved Hide resolved
@mlabouardy mlabouardy added the gcp label May 11, 2023
@PumpkinSeed
Copy link
Contributor Author

Cool, as soon as I will have time, I will do the changes. I agree that it would be much easier to maintain.

@mlabouardy mlabouardy added this to the v3.0.17 milestone May 15, 2023
@mlabouardy mlabouardy changed the base branch from master to develop May 15, 2023 11:43
@PumpkinSeed PumpkinSeed changed the title [Draft] Estimate GCP VM pricing Estimate GCP VM pricing May 18, 2023
Copy link
Collaborator

@mlabouardy mlabouardy left a comment

Choose a reason for hiding this comment

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

Thanks a lot @PumpkinSeed for the feature and for introducing tests as well :)

@mlabouardy mlabouardy merged commit 02dd8b6 into tailwarden:develop May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Estimate cost of GCP VM Instances
2 participants