Skip to content

Commit

Permalink
Fix watson ml missing cost components for standard plan instance and …
Browse files Browse the repository at this point in the history
…additional CUH (#165)

* add missing cost component for wml instance

* update usage examples for watson

* Merge branch 'feat/watsonx' of https://github.ibm.com/dataops/infracost-cli into fix/roks-estimates

* sync test usage
  • Loading branch information
hiltol authored Apr 23, 2024
1 parent 752e0b8 commit 3c4eda8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
8 changes: 6 additions & 2 deletions infracost-usage-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ resource_type_default_usage:
wml_class3_ru: 20
wa_instance: 1
wa_monthly_active_users: 1001
wa_voice_users: 101
wa_monthly_voice_users: 101
wd_instance: 1
wd_documents: 11000
wd_queries: 11000
Expand Down Expand Up @@ -1299,11 +1299,15 @@ resource_usage:
monitoring_api_call: 1000 # Additional API calls above the base 1M/instance
monitoring_timeseries_hour: 1000 # Additional time-series cost above the base 1000/host
continuousdelivery_authorized_users: 10 # Number of authorized users to the CD instance and its managed toolchains

ibm_resource_instance.watson_machine_learning_standard:
wml_capacity_unit_hour: 20 # Amount of Capacity Unit-Hours used in a month
wml_instance: 1 # The number of instances used per month where each instance includes 2500 CUHs
wml_instance: 1 # The number of instances per month where each instance includes 2500 CUHs
wml_class1_ru: 20 # The number of resource units used for inferencing with class 1 type models where each ru is 1000 tokens
wml_class2_ru: 20 # The number of resource units used for inferencing with class 2 type models where each ru is 1000 tokens
wml_class3_ru: 20 # The number of resource units used for inferencing with class 3 type models where each ru is 1000 tokens

ibm_resource_instance.watson_assistant_plus:
wa_instance: 1 # The number of instances used per month where each instance includes 1000 monthly active users
wa_monthly_active_users: 1100 # The number of monthly active users
wa_monthly_voice_users: 100 # The number of monthly active voice users
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@
└─ Active Secrets 400 Secrets $86.00

ibm_resource_instance.wa_instance_enterprise
├─ Instance 1 Instance $6,000.00
├─ Instance (50000 MAU included) 1 Instance $6,000.00
├─ Additional Monthly Active Users 1 1K MAU $120.00
└─ Monthly Active Users using voice 1 1K MAU $90.00

ibm_resource_instance.wa_instance_lite
└─ Lite plan 1 $0.00

ibm_resource_instance.wa_instance_plus
├─ Instance 1 Instance $140.00
├─ Instance (1000 MAU included) 1 Instance $140.00
├─ Additional Monthly Active Users 10 100 MAU $140.00
└─ Monthly Active Users using voice 1 100 MAU $9.00

Expand Down Expand Up @@ -112,12 +112,13 @@
└─ Lite plan 1 $0.00

ibm_resource_instance.wml_instance_standard
├─ Capacity Unit-Hours 2,500 CUH $1,050.00
├─ Instance (2500 CUH included) 1 Instance $1,050.00
├─ Additional Capacity Unit-Hours Monthly cost depends on usage: $0.42 per CUH
├─ Class 1 Resource Units 50 RU $0.03
├─ Class 2 Resource Units 50 RU $0.09
└─ Class 3 Resource Units 50 RU $0.25

OVERALL TOTAL $15,460.14
──────────────────────────────────
25 cloud resources were detected:
∙ 25 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
∙ 25 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ resource_usage:
ibm_resource_instance.wa_instance_plus:
wa_instance: 1
wa_monthly_active_users: 2000
wa_voice_users: 100
wa_monthly_voice_users: 100
ibm_resource_instance.wa_instance_enterprise:
wa_instance: 1
wa_monthly_active_users: 51000
wa_voice_users: 1000
wa_monthly_voice_users: 1000

ibm_resource_instance.watson_discovery_plus:
wd_instance: 1 # Number of instances used per month
Expand All @@ -67,4 +67,4 @@ resource_usage:
wd_documents: 101000 # Number of monthly documents created; 100,000 included in the Enterprise plan; $5 for every additional 1,000 documents.
wd_queries: 101000 # Number of queries documents created; 100,000 included in the Enterprise plan; $5 for every additional 1,000 queries.
wd_custom_models: 4 # Number of monthly custom models created; 3 included in the Enterprise plan; $500 for every additional custom model.
wd_collections: 301 # Number of monthly collections created; 300 included in the Enterprise plan. $500 for every additional 100 collections.
wd_collections: 301 # Number of monthly collections created; 300 included in the Enterprise plan. $500 for every additional 100 collections.
8 changes: 7 additions & 1 deletion internal/resources/ibm/resource_instance_conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ func GetWACostComponents(r *ResourceInstance) []*schema.CostComponent {

func WAInstanceCostComponent(r *ResourceInstance) *schema.CostComponent {
var q *decimal.Decimal
var name string
if r.WA_Instance != nil {
q = decimalPtr(decimal.NewFromFloat(*r.WA_Instance))
} else {
q = decimalPtr(decimal.NewFromInt(1))
}
if r.Plan == "enterprise" {
name = "Instance (50000 MAU included)"
} else {
name = "Instance (1000 MAU included)"
}
return &schema.CostComponent{
Name: "Instance",
Name: name,
Unit: "Instance",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: q,
Expand Down
40 changes: 31 additions & 9 deletions internal/resources/ibm/resource_instance_pm20.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const CUH_PER_INSTANCE = 2500
func GetWMLCostComponents(r *ResourceInstance) []*schema.CostComponent {
if r.Plan == "v2-professional" {
return []*schema.CostComponent{
WMLInstanceCostComponent(r),
WMLStandardCapacityUnitHoursCostComponent(r),
WMLClass1ResourceUnitsCostComponent(r),
WMLClass2ResourceUnitsCostComponent(r),
Expand Down Expand Up @@ -52,6 +53,32 @@ func GetWMLCostComponents(r *ResourceInstance) []*schema.CostComponent {
}
}

func WMLInstanceCostComponent(r *ResourceInstance) *schema.CostComponent {
var q *decimal.Decimal
if r.WML_Instance != nil {
q = decimalPtr(decimal.NewFromFloat(*r.WML_Instance))
} else {
q = decimalPtr(decimal.NewFromInt(1))
}
return &schema.CostComponent{
Name: "Instance (2500 CUH included)",
Unit: "Instance",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: q,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("ibm"),
Region: strPtr(r.Location),
Service: &r.Service,
AttributeFilters: []*schema.AttributeFilter{
{Key: "planName", Value: &r.Plan},
},
},
PriceFilter: &schema.PriceFilter{
Unit: strPtr("INSTANCES"),
},
}
}

func WMLEssentialsCapacityUnitHoursCostComponent(r *ResourceInstance) *schema.CostComponent {
var q *decimal.Decimal
if r.WML_CUH != nil {
Expand All @@ -78,30 +105,25 @@ func WMLEssentialsCapacityUnitHoursCostComponent(r *ResourceInstance) *schema.Co

func WMLStandardCapacityUnitHoursCostComponent(r *ResourceInstance) *schema.CostComponent {
var q *decimal.Decimal
var cuh float64
var instance float64
var included_cuh float64

if r.WML_Instance != nil {
instance = *r.WML_Instance
} else {
instance = 1
}
if r.WML_CUH != nil {
cuh = *r.WML_CUH

// standard plan is billed a fixed amount for each instance, which includes 2500 CUH's per instance.
// if the used CUH exceeds the included quantity, the overage is charged at a flat rate.
included_cuh = instance * CUH_PER_INSTANCE
if cuh > included_cuh {
q = decimalPtr(decimal.NewFromFloat(cuh))
} else {
q = decimalPtr(decimal.NewFromFloat(included_cuh))
additional_cuh := *r.WML_CUH - (CUH_PER_INSTANCE * instance)
if additional_cuh > 0 {
q = decimalPtr(decimal.NewFromFloat(additional_cuh))
}
}

return &schema.CostComponent{
Name: "Capacity Unit-Hours",
Name: "Additional Capacity Unit-Hours",
Unit: "CUH",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: q,
Expand Down

0 comments on commit 3c4eda8

Please sign in to comment.