From 61e840b59d4e837fe1de348f3333ab1e0890df5b Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Mon, 6 Dec 2021 21:55:57 +0200 Subject: [PATCH 1/3] Fix spot NG cost calculation at cluster-up --- cli/cmd/lib_cluster_config.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cli/cmd/lib_cluster_config.go b/cli/cmd/lib_cluster_config.go index 48d7a444f3..6e18a7d1d8 100644 --- a/cli/cmd/lib_cluster_config.go +++ b/cli/cmd/lib_cluster_config.go @@ -187,7 +187,7 @@ func confirmInstallClusterConfig(clusterConfig *clusterconfig.Config, awsClient rows = append(rows, []interface{}{"1 eks cluster", s.DollarsMaxPrecision(eksPrice)}) ngNameToSpotInstancesUsed := map[string]int{} - fixedPrice := eksPrice + operatorInstancePrice + operatorEBSPrice + prometheusInstancePrice + prometheusEBSPrice + metricsEBSPrice + 2*nlbPrice + natTotalPrice + fixedPrice := eksPrice + 2*(operatorInstancePrice+operatorEBSPrice) + prometheusInstancePrice + prometheusEBSPrice + metricsEBSPrice + 2*nlbPrice + natTotalPrice totalMinPrice := fixedPrice totalMaxPrice := fixedPrice for _, ng := range clusterConfig.NodeGroups { @@ -215,7 +215,11 @@ func confirmInstallClusterConfig(clusterConfig *clusterconfig.Config, awsClient workerPriceStr += " (spot pricing unavailable)" if err == nil && spotPrice != 0 { workerPriceStr = fmt.Sprintf("%s - %s each (varies based on spot price)", s.DollarsAndTenthsOfCents(spotPrice+apiEBSPrice), s.DollarsAndTenthsOfCents(apiInstancePrice+apiEBSPrice)) - totalMinPrice += float64(ng.MinInstances) * (spotPrice + apiEBSPrice) + if float64(ng.MinInstances) > float64(*ng.SpotConfig.OnDemandBaseCapacity) { + totalMinPrice += float64(ng.MinInstances-*ng.SpotConfig.OnDemandBaseCapacity)*(spotPrice+apiEBSPrice) + float64(*ng.SpotConfig.OnDemandBaseCapacity)*(apiInstancePrice+apiEBSPrice) + } else { + totalMinPrice += float64(ng.MinInstances) * (apiInstancePrice + apiEBSPrice) + } } else { totalMinPrice += float64(ng.MinInstances) * (apiInstancePrice + apiEBSPrice) } From 032b465fd64c0554ed486d6a9cebf34aaa6d482f Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Tue, 7 Dec 2021 01:00:51 +0200 Subject: [PATCH 2/3] Fix cortex cluster info and grafana dashboard pricing --- pkg/operator/endpoints/info.go | 3 +-- pkg/operator/operator/cron.go | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/operator/endpoints/info.go b/pkg/operator/endpoints/info.go index 53ee80a3d7..c3dbfbc680 100644 --- a/pkg/operator/endpoints/info.go +++ b/pkg/operator/endpoints/info.go @@ -19,7 +19,6 @@ package endpoints import ( "net/http" "sort" - "strings" "github.com/cortexlabs/cortex/pkg/config" "github.com/cortexlabs/cortex/pkg/lib/aws" @@ -76,7 +75,7 @@ func getWorkerNodeInfos() ([]schema.WorkerNodeInfo, int, error) { instanceType := node.Labels["beta.kubernetes.io/instance-type"] nodeGroupName := node.Labels["alpha.eksctl.io/nodegroup-name"] - isSpot := strings.Contains(strings.ToLower(node.Labels["lifecycle"]), "spot") + isSpot := node.Labels["node-lifecycle"] == "spot" price := aws.InstanceMetadatas[config.ClusterConfig.Region][instanceType].Price if isSpot { diff --git a/pkg/operator/operator/cron.go b/pkg/operator/operator/cron.go index 6153f685fb..89d78b6852 100644 --- a/pkg/operator/operator/cron.go +++ b/pkg/operator/operator/cron.go @@ -18,7 +18,6 @@ package operator import ( "context" - "strings" "github.com/cortexlabs/cortex/pkg/config" "github.com/cortexlabs/cortex/pkg/consts" @@ -128,7 +127,7 @@ func clusterTelemetryProperties() (map[string]interface{}, error) { } isSpot := false - if strings.Contains(strings.ToLower(node.Labels["lifecycle"]), "spot") { + if node.Labels["node-lifecycle"] == "spot" { isSpot = true } @@ -304,7 +303,7 @@ func CostBreakdown() error { } isSpot := false - if strings.Contains(strings.ToLower(node.Labels["lifecycle"]), "spot") { + if node.Labels["node-lifecycle"] == "spot" { isSpot = true } From 6f5d8a445b25fdeb7d3a1338295cb8bf9e74f4b4 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Tue, 7 Dec 2021 01:23:35 +0200 Subject: [PATCH 3/3] Fix pricing for on_demand_percentage_above_base_capacity --- cli/cmd/lib_cluster_config.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/cmd/lib_cluster_config.go b/cli/cmd/lib_cluster_config.go index 6e18a7d1d8..ac45306865 100644 --- a/cli/cmd/lib_cluster_config.go +++ b/cli/cmd/lib_cluster_config.go @@ -215,8 +215,10 @@ func confirmInstallClusterConfig(clusterConfig *clusterconfig.Config, awsClient workerPriceStr += " (spot pricing unavailable)" if err == nil && spotPrice != 0 { workerPriceStr = fmt.Sprintf("%s - %s each (varies based on spot price)", s.DollarsAndTenthsOfCents(spotPrice+apiEBSPrice), s.DollarsAndTenthsOfCents(apiInstancePrice+apiEBSPrice)) - if float64(ng.MinInstances) > float64(*ng.SpotConfig.OnDemandBaseCapacity) { - totalMinPrice += float64(ng.MinInstances-*ng.SpotConfig.OnDemandBaseCapacity)*(spotPrice+apiEBSPrice) + float64(*ng.SpotConfig.OnDemandBaseCapacity)*(apiInstancePrice+apiEBSPrice) + if ng.MinInstances > *ng.SpotConfig.OnDemandBaseCapacity { + totalMinPrice += float64(ng.MinInstances-*ng.SpotConfig.OnDemandBaseCapacity)*(spotPrice+apiEBSPrice)*float64(100-*ng.SpotConfig.OnDemandPercentageAboveBaseCapacity)/100 + + float64(ng.MinInstances-*ng.SpotConfig.OnDemandBaseCapacity)*(apiInstancePrice+apiEBSPrice)*float64(*ng.SpotConfig.OnDemandPercentageAboveBaseCapacity)/100 + + float64(*ng.SpotConfig.OnDemandBaseCapacity)*(apiInstancePrice+apiEBSPrice) } else { totalMinPrice += float64(ng.MinInstances) * (apiInstancePrice + apiEBSPrice) }