@@ -17,6 +17,9 @@ limitations under the License.
1717package operator
1818
1919import (
20+ "strings"
21+
22+ "github.com/cortexlabs/cortex/pkg/lib/aws"
2023 "github.com/cortexlabs/cortex/pkg/lib/errors"
2124 "github.com/cortexlabs/cortex/pkg/lib/k8s"
2225 "github.com/cortexlabs/cortex/pkg/lib/telemetry"
@@ -48,13 +51,20 @@ func deleteEvictedPods() error {
4851 return nil
4952}
5053
54+ type instanceInfo struct {
55+ InstanceType string `json:"instance_type" yaml:"instance_type"`
56+ IsSpot bool `json:"is_spot" yaml:"is_spot"`
57+ Price float64 `json:"price" yaml:"price"`
58+ Count int32 `json:"count" yaml:"count"`
59+ }
60+
5161func operatorTelemetry () error {
5262 nodes , err := config .K8s .ListNodes (nil )
5363 if err != nil {
5464 return err
5565 }
5666
57- instanceTypeCounts := make (map [string ]int )
67+ instanceInfos := make (map [string ]* instanceInfo )
5868 var totalInstances int
5969
6070 for _ , node := range nodes {
@@ -67,13 +77,45 @@ func operatorTelemetry() error {
6777 instanceType = "unknown"
6878 }
6979
70- instanceTypeCounts [instanceType ]++
80+ isSpot := false
81+ if strings .Contains (strings .ToLower (node .Labels ["lifecycle" ]), "spot" ) {
82+ isSpot = true
83+ }
84+
7185 totalInstances ++
86+
87+ instanceInfosKey := instanceType + "_ondemand"
88+ if isSpot {
89+ instanceInfosKey = instanceType + "_spot"
90+ }
91+
92+ if info , ok := instanceInfos [instanceInfosKey ]; ok {
93+ info .Count ++
94+ continue
95+ }
96+
97+ price := aws .InstanceMetadatas [* config .Cluster .Region ][instanceType ].Price
98+ if isSpot {
99+ spotPrice , err := config .AWS .SpotInstancePrice (* config .Cluster .Region , instanceType )
100+ if err == nil && spotPrice != 0 {
101+ price = spotPrice
102+ }
103+ }
104+
105+ info := instanceInfo {
106+ InstanceType : instanceType ,
107+ IsSpot : isSpot ,
108+ Price : price ,
109+ Count : 1 ,
110+ }
111+
112+ instanceInfos [instanceInfosKey ] = & info
72113 }
73114
74115 properties := map [string ]interface {}{
75- "instanceTypes " : instanceTypeCounts ,
116+ "region " : * config . Cluster . Region ,
76117 "instanceCount" : totalInstances ,
118+ "instances" : instanceInfos ,
77119 }
78120
79121 telemetry .Event ("operator.cron" , properties )
0 commit comments