MCPcopy
hub / github.com/cortexlabs/cortex / printInfoPricing

Function printInfoPricing

cli/cmd/cluster.go:993–1084  ·  view source on GitHub ↗
(infoResponse *schema.InfoResponse, clusterConfig clusterconfig.Config)

Source from the content-addressed store, hash-verified

991}
992
993func printInfoPricing(infoResponse *schema.InfoResponse, clusterConfig clusterconfig.Config) {
994 eksPrice := awslib.EKSPrices[clusterConfig.Region]
995 operatorInstancePrice := awslib.InstanceMetadatas[clusterConfig.Region]["t3.medium"].Price
996 operatorEBSPrice := awslib.EBSMetadatas[clusterConfig.Region]["gp3"].PriceGB * 20 / 30 / 24
997 prometheusInstancePrice := awslib.InstanceMetadatas[clusterConfig.Region][clusterConfig.PrometheusInstanceType].Price
998 prometheusEBSPrice := awslib.EBSMetadatas[clusterConfig.Region]["gp3"].PriceGB * 20 / 30 / 24
999 metricsEBSPrice := awslib.EBSMetadatas[clusterConfig.Region]["gp2"].PriceGB * (40 + 2) / 30 / 24
1000 nlbPrice := awslib.NLBMetadatas[clusterConfig.Region].Price
1001 elbPrice := awslib.ELBMetadatas[clusterConfig.Region].Price
1002 natUnitPrice := awslib.NATMetadatas[clusterConfig.Region].Price
1003
1004 var loadBalancersPrice float64
1005 usesELBForAPILoadBalancer := clusterConfig.APILoadBalancerType == clusterconfig.ELBLoadBalancerType
1006 if usesELBForAPILoadBalancer {
1007 loadBalancersPrice = nlbPrice + elbPrice
1008 } else {
1009 loadBalancersPrice = 2 * nlbPrice
1010 }
1011
1012 headers := []table.Header{
1013 {Title: "aws resource"},
1014 {Title: "cost per hour"},
1015 }
1016
1017 var rows [][]interface{}
1018 rows = append(rows, []interface{}{"1 eks cluster", s.DollarsMaxPrecision(eksPrice)})
1019
1020 var totalNodeGroupsPrice float64
1021 for _, ng := range clusterConfig.NodeGroups {
1022 var ngNamePrefix string
1023 if ng.Spot {
1024 ngNamePrefix = "cx-ws-"
1025 } else {
1026 ngNamePrefix = "cx-wd-"
1027 }
1028 nodesInfo := infoResponse.GetNodesWithNodeGroupName(ngNamePrefix + ng.Name)
1029 numInstances := len(nodesInfo)
1030
1031 ebsPrice := awslib.EBSMetadatas[clusterConfig.Region][ng.InstanceVolumeType.String()].PriceGB * float64(ng.InstanceVolumeSize) / 30 / 24
1032 if ng.InstanceVolumeType == clusterconfig.IO1VolumeType && ng.InstanceVolumeIOPS != nil {
1033 ebsPrice += awslib.EBSMetadatas[clusterConfig.Region][ng.InstanceVolumeType.String()].PriceIOPS * float64(*ng.InstanceVolumeIOPS) / 30 / 24
1034 }
1035 if ng.InstanceVolumeType == clusterconfig.GP3VolumeType && ng.InstanceVolumeIOPS != nil && ng.InstanceVolumeThroughput != nil {
1036 ebsPrice += libmath.MaxFloat64(0, (awslib.EBSMetadatas[clusterConfig.Region][ng.InstanceVolumeType.String()].PriceIOPS-3000)*float64(*ng.InstanceVolumeIOPS)/30/24)
1037 ebsPrice += libmath.MaxFloat64(0, (awslib.EBSMetadatas[clusterConfig.Region][ng.InstanceVolumeType.String()].PriceThroughput-125)*float64(*ng.InstanceVolumeThroughput)/30/24)
1038 }
1039 totalEBSPrice := ebsPrice * float64(numInstances)
1040
1041 totalInstancePrice := float64(0)
1042 for _, nodeInfo := range nodesInfo {
1043 totalInstancePrice += nodeInfo.Price
1044 }
1045
1046 rows = append(rows, []interface{}{fmt.Sprintf("nodegroup %s: %d (out of %d) %s", ng.Name, numInstances, ng.MaxInstances, s.PluralS("instance", numInstances)), s.DollarsAndTenthsOfCents(totalInstancePrice+totalEBSPrice) + " total"})
1047
1048 totalNodeGroupsPrice += totalEBSPrice + totalInstancePrice
1049 }
1050

Callers 1

Calls 5

MustPrintMethod · 0.95
BoldFunction · 0.92
BoolFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected