crooked-daybreak-55253
08/30/2022, 1:20 PMplain-potato-53219
08/30/2022, 1:50 PMcrooked-daybreak-55253
08/30/2022, 2:04 PMDo we already have means of querying for custom instances on cloud pricing API?Yes it looks like prices for custom instances are already in the cloud pricing DB. This guide has a good example of how to do the search and map them to a cost component
plain-potato-53219
08/31/2022, 2:43 PMquery {
products(
filter: {
vendorName: "gcp",
service: "Compute Engine",
productFamily: "Compute",
region: "europe-central2",
attributeFilters: [
{ key: "resourceGroup", value: "RAM" }
]
},
) {
attributes { key, value }
prices { USD }
}
}
But I'm not sure how I could improve the result accuracy in this query π€ I found in the results some descriptions like Custom Instance Ram running in Warsaw
and I think these should be our case for an object like:
resource "google_container_node_pool" "dev-1" {
cluster = "dev"
name = "dev-1"
location = "europe-central2-c"
autoscaling {
max_node_count = 20
min_node_count = 1
}
management {
auto_repair = true
auto_upgrade = true
}
upgrade_settings {
max_surge = 1
max_unavailable = 0
}
node_config {
preemptible = true
oauth_scopes = [
"<https://www.googleapis.com/auth/cloud-platform>"
]
machine_type = "custom-22-20480"
image_type = "COS_CONTAINERD"
disk_type = "pd-standard"
disk_size_gb = "100"
labels = {
"pool" = "dev-1"
}
workload_metadata_config {
mode = "GKE_METADATA"
}
}
}
customComputeCostComponent
took place.
You can check my progress in this drafted PR: https://github.com/infracost/infracost/pull/2004
Now, I'll get more acquainted with cloud pricing GraphQL API and see how I should build that AttributeFilters
list.
Btw, I let the personal bias lead me to start with google_container_node_pool
resource.crooked-daybreak-55253
08/31/2022, 4:24 PMIβm not sure how I could improve the result accuracy in this queryYeah it may be that a regex against the description is required. If you look at the
guestAcceleratorCostComponent
helper you can see an example of that.plain-potato-53219
09/07/2022, 4:28 PMquery {
products(
filter: {
vendorName: "gcp",
service: "Compute Engine",
productFamily: "Compute",
region: "europe-central2",
attributeFilters: [
{ key: "description", value_regex: "/^Custom Instance Core.*$/" },
]
},
) {
attributes { key, value }
prices { USD }
}
}
---
query {
products(
filter: {
vendorName: "gcp",
service: "Compute Engine",
productFamily: "Compute",
region: "europe-central2",
attributeFilters: [
{ key: "description", value_regex: "/^Custom Instance Ram.*$/" },
]
},
) {
attributes { key, value }
prices { USD }
}
}
But not on the final pricing
google_container_node_pool.dev-1
ββ Standard provisioned storage (pd-standard) 300 GB $14.40
ββ Custom Instance CPU usage (Linux/UNIX, preemptible, custom-20-20480) 2,190 hours $0.00
ββ Custom Instance RAM usage (Linux/UNIX, preemptible, custom-20-20480) 2,190 hours $0.00
Another issue that I already spotted in my code is that I didn't multiplied the Core/Ram cost by the unities specified in the instance name (i.e 20 cpu and 20480 ram). And I'm not sure how I'll make this right now.
I'll get back to this issue some other time in the near future.crooked-daybreak-55253
09/07/2022, 4:36 PMBut not on the final pricingLooks like you have
ProductFamily: strPtr("Compute Instance"),
in the code, not ProductFamily: strPtr("Compute"),
Another issue that I already spotted in my code is that I didnβt multiplied the Core/Ram cost by the unities specified in the instance name (i.e 20 cpu and 20480 ram). And Iβm not sure how Iβll make this right now.Yeah youβll need to parse the number of cores and amount of ram from the machine type, then multiply the quantity by that. That will give the correct cost but unfortunately also multiply the number of hours reported as units. Itβs a little weried but I think you can get around this by setting the UnitMultiplier also equal to the number of cores (or ram). So something like this:
UnitMultiplier: decimal.NewFromInt(numberOfCores),
MonthlyQuantity: decimalPtr(qty.Mul(decimal.NewFromInt(instanceCount * numberOfCores))),
That should make it display the correct cost and hours.There is a limit of 6.5 GB per CPU unless you add extended memory. You must do this explicitly by adding the suffix -ext, e.g. custom-2-15360-ext for 2 vCPU and 15 GB of memory.
plain-potato-53219
11/20/2022, 3:59 PMlittle-author-61621
11/20/2022, 5:51 PMplain-potato-53219
11/21/2022, 10:07 AMlittle-author-61621
11/21/2022, 10:36 AMplain-potato-53219
11/21/2022, 11:19 AMlittle-author-61621
11/21/2022, 12:17 PMplain-potato-53219
11/21/2022, 12:44 PMlittle-author-61621
11/21/2022, 12:47 PMplain-potato-53219
11/21/2022, 5:50 PMgoogle_compute_instance.vm-dev-1
ββ Custom Instance CPU usage (Linux/UNIX, on-demand, custom-20-20480) 730 hours $583.90
ββ Custom Instance RAM usage (Linux/UNIX, on-demand, custom-20-20480) 730 gibibyte hour $170.97
google_compute_instance.vm-dev-2
ββ Custom Instance CPU usage (Linux/UNIX, on-demand, custom-20-20480-ext) 730 hours $583.90
ββ Custom Instance RAM usage (Linux/UNIX, on-demand, custom-20-20480-ext) 730 gibibyte hour $170.97
ββ Standard provisioned storage (pd-standard) 10 GB $0.48
google_compute_instance.vm-dev-3
ββ Custom Instance CPU usage (Linux/UNIX, on-demand, n2-custom-20-20480) 730 hours $434.58
ββ Custom Instance RAM usage (Linux/UNIX, on-demand, n2-custom-20-20480) 730 gibibyte hour $63.69
google_compute_instance.vm-dev-4
ββ Custom Instance CPU usage (Linux/UNIX, on-demand, n2-custom-20-20480-ext) 730 hours $434.58
ββ Custom Instance RAM usage (Linux/UNIX, on-demand, n2-custom-20-20480-ext) 730 gibibyte hour $119.00
ββ Standard provisioned storage (pd-standard) 10 GB $0.48
google_container_node_pool.dev-1
ββ Standard provisioned storage (pd-standard) 300 GB $14.40
ββ Custom Instance CPU usage (Linux/UNIX, on-demand, custom-20-20480) 2,190 hours $1,751.69
ββ Custom Instance RAM usage (Linux/UNIX, on-demand, custom-20-20480) 2,190 gibibyte hour $512.90
google_container_node_pool.dev-2
ββ Standard provisioned storage (pd-standard) 300 GB $14.40
ββ Custom Instance CPU usage (Linux/UNIX, on-demand, custom-20-20480-ext) 2,190 hours $1,751.69
ββ Custom Instance RAM usage (Linux/UNIX, on-demand, custom-20-20480-ext) 2,190 gibibyte hour $512.90
google_container_node_pool.dev-3
ββ Standard provisioned storage (pd-standard) 300 GB $14.40
ββ Custom Instance CPU usage (Linux/UNIX, on-demand, n2-custom-20-20480) 2,190 hours $1,303.73
ββ Custom Instance RAM usage (Linux/UNIX, on-demand, n2-custom-20-20480) 2,190 gibibyte hour $191.07
google_container_node_pool.dev-4
ββ Standard provisioned storage (pd-standard) 300 GB $14.40
ββ Custom Instance CPU usage (Linux/UNIX, on-demand, n2-custom-20-20480-ext) 2,190 hours $1,303.73
ββ Custom Instance RAM usage (Linux/UNIX, on-demand, n2-custom-20-20480-ext) 2,190 gibibyte hour $356.99
A quick troubleshoot lead me to this https://github.com/7onn/infracost/blob/master/internal/providers/terraform/google/container_node_pool.go#L64-L74
In fact, there are three possible zones.. but this doesn't mean that three nodes will be provisioned. If the autoscaling.min_count is 1 and the cluster is cool, we'll have a single machine in some of the AZs of the selected region and not three π€
I believe this is wrongly multiplying the resource consumption for GKE node pools π€ Please, correct me If I'm wrong.little-author-61621
11/21/2022, 5:58 PMlocation
is set to. If itβs set to a region (us-central1) then it creates 3 nodes. If itβs set to a AZ (us-cental1-a) then it creates 1.plain-potato-53219
11/21/2022, 6:03 PMeurope-central2-c
. Therefore 1 node would be provisioned, right? I'll see how I can handle this and avoid multiplying this result by 3.
But don't worry. I won't end up πͺπ shaving the yak hahahalittle-author-61621
11/21/2022, 6:04 PMplain-potato-53219
11/21/2022, 6:06 PMlittle-author-61621
11/22/2022, 3:27 PMplain-potato-53219
12/01/2022, 3:36 PMlittle-author-61621
12/01/2022, 3:53 PM