From 8afab0092e20f9e3f86f3d535116b8ea4ea4a1c9 Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Tue, 25 Feb 2020 12:05:17 -0800 Subject: [PATCH 1/2] Update telemetry --- pkg/operator/operator/cron.go | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkg/operator/operator/cron.go b/pkg/operator/operator/cron.go index d83db35cd0..4acb2c49ef 100644 --- a/pkg/operator/operator/cron.go +++ b/pkg/operator/operator/cron.go @@ -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" @@ -48,6 +51,13 @@ 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 { @@ -55,6 +65,7 @@ func operatorTelemetry() error { } instanceTypeCounts := make(map[string]int) + instanceInfos := make(map[string]*instanceInfo) var totalInstances int for _, node := range nodes { @@ -67,13 +78,47 @@ func operatorTelemetry() error { instanceType = "unknown" } + isSpot := false + if strings.Contains(strings.ToLower(node.Labels["lifecycle"]), "spot") { + isSpot = true + } + instanceTypeCounts[instanceType]++ 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{}{ + "region": *config.Cluster.Region, "instanceTypes": instanceTypeCounts, "instanceCount": totalInstances, + "instances": instanceInfos, } telemetry.Event("operator.cron", properties) From afb325457a9ef355e0214ef71e0e8f5b1b06e805 Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Tue, 25 Feb 2020 12:13:51 -0800 Subject: [PATCH 2/2] Remove instanceTypes map --- pkg/operator/operator/cron.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/operator/operator/cron.go b/pkg/operator/operator/cron.go index 4acb2c49ef..5c871d9b3c 100644 --- a/pkg/operator/operator/cron.go +++ b/pkg/operator/operator/cron.go @@ -64,7 +64,6 @@ func operatorTelemetry() error { return err } - instanceTypeCounts := make(map[string]int) instanceInfos := make(map[string]*instanceInfo) var totalInstances int @@ -83,7 +82,6 @@ func operatorTelemetry() error { isSpot = true } - instanceTypeCounts[instanceType]++ totalInstances++ instanceInfosKey := instanceType + "_ondemand" @@ -116,7 +114,6 @@ func operatorTelemetry() error { properties := map[string]interface{}{ "region": *config.Cluster.Region, - "instanceTypes": instanceTypeCounts, "instanceCount": totalInstances, "instances": instanceInfos, }