Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions pkg/operator/operator/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package operator

import (
"strings"

"github.com/cortexlabs/cortex/pkg/lib/aws"
"github.com/cortexlabs/cortex/pkg/lib/errors"
"github.com/cortexlabs/cortex/pkg/lib/k8s"
"github.com/cortexlabs/cortex/pkg/lib/telemetry"
Expand Down Expand Up @@ -48,13 +51,20 @@ func deleteEvictedPods() error {
return nil
}

type instanceInfo struct {
InstanceType string `json:"instance_type" yaml:"instance_type"`
IsSpot bool `json:"is_spot" yaml:"is_spot"`
Price float64 `json:"price" yaml:"price"`
Count int32 `json:"count" yaml:"count"`
}

func operatorTelemetry() error {
nodes, err := config.K8s.ListNodes(nil)
if err != nil {
return err
}

instanceTypeCounts := make(map[string]int)
instanceInfos := make(map[string]*instanceInfo)
var totalInstances int

for _, node := range nodes {
Expand All @@ -67,13 +77,45 @@ func operatorTelemetry() error {
instanceType = "unknown"
}

instanceTypeCounts[instanceType]++
isSpot := false
if strings.Contains(strings.ToLower(node.Labels["lifecycle"]), "spot") {
isSpot = true
}

totalInstances++

instanceInfosKey := instanceType + "_ondemand"
if isSpot {
instanceInfosKey = instanceType + "_spot"
}

if info, ok := instanceInfos[instanceInfosKey]; ok {
info.Count++
continue
}

price := aws.InstanceMetadatas[*config.Cluster.Region][instanceType].Price
if isSpot {
spotPrice, err := config.AWS.SpotInstancePrice(*config.Cluster.Region, instanceType)
if err == nil && spotPrice != 0 {
price = spotPrice
}
}

info := instanceInfo{
InstanceType: instanceType,
IsSpot: isSpot,
Price: price,
Count: 1,
}

instanceInfos[instanceInfosKey] = &info
}

properties := map[string]interface{}{
"instanceTypes": instanceTypeCounts,
"region": *config.Cluster.Region,
"instanceCount": totalInstances,
"instances": instanceInfos,
}

telemetry.Event("operator.cron", properties)
Expand Down