Skip to content

Add telemetry for deploy and operator init #1559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions cli/local/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ import (
"github.com/cortexlabs/cortex/pkg/lib/files"
"github.com/cortexlabs/cortex/pkg/lib/prompt"
"github.com/cortexlabs/cortex/pkg/lib/sets/strset"
"github.com/cortexlabs/cortex/pkg/lib/telemetry"
"github.com/cortexlabs/cortex/pkg/operator/schema"
"github.com/cortexlabs/cortex/pkg/types"
"github.com/cortexlabs/cortex/pkg/types/spec"
"github.com/cortexlabs/cortex/pkg/types/userconfig"
)

var _deploymentID = "local"

func UpdateAPI(apiConfig *userconfig.API, models []spec.CuratedModelResource, configPath string, projectID string, deployDisallowPrompt bool, awsClient *aws.Client) (*schema.APIResponse, string, error) {
telemetry.Event("operator.deploy", apiConfig.TelemetryEvent(types.LocalProviderType))

var incompatibleVersion string
encounteredVersionMismatch := false
prevAPISpec, err := FindAPISpec(apiConfig.Name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
exit.Error(err)
}

telemetry.Event("operator.init")
telemetry.Event("operator.init", config.Cluster.TelemetryEvent())

_, err := operator.UpdateMemoryCapacityConfigMap()
if err != nil {
Expand Down
16 changes: 9 additions & 7 deletions pkg/operator/operator/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,17 @@ func InstanceTelemetry() error {
fixedPrice := clusterFixedPrice()

properties := map[string]interface{}{
"region": *config.Cluster.Region,
"instance_count": totalInstances,
"instances": instanceInfos,
"fixed_price": fixedPrice,
"total_price": totalInstancePrice + fixedPrice,
"total_price_if_on_demand": totalInstancePriceIfOnDemand + fixedPrice,
"region": *config.Cluster.Region,
"instance_count": totalInstances,
"instances": instanceInfos,
"fixed_price": fixedPrice,
"workload_price": totalInstancePrice,
"workload_price_if_on_demand": totalInstancePriceIfOnDemand,
"total_price": totalInstancePrice + fixedPrice,
"total_price_if_on_demand": totalInstancePriceIfOnDemand + fixedPrice,
}

telemetry.Event("operator.cron", properties)
telemetry.Event("operator.cron", properties, config.Cluster.TelemetryEvent())

return nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func UpdateAPI(apiConfig *userconfig.API, models []spec.CuratedModelResource, pr
return nil, "", ErrorCannotChangeKindOfDeployedAPI(apiConfig.Name, apiConfig.Kind, deployedResource.Kind)
}

telemetry.Event("operator.deploy", apiConfig.TelemetryEvent(types.AWSProviderType))

var api *spec.API
var msg string
switch apiConfig.Kind {
Expand Down
129 changes: 129 additions & 0 deletions pkg/types/clusterconfig/clusterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/cortexlabs/cortex/pkg/lib/prompt"
s "github.com/cortexlabs/cortex/pkg/lib/strings"
"github.com/cortexlabs/cortex/pkg/lib/table"
"github.com/cortexlabs/cortex/pkg/types"
)

const (
Expand Down Expand Up @@ -1200,3 +1201,131 @@ func (cc *Config) UserTable() table.KeyValuePairs {
func (cc *Config) UserStr() string {
return cc.UserTable().String()
}

func (cc *Config) TelemetryEvent() map[string]interface{} {
event := map[string]interface{}{
"provider": types.AWSProviderType,
}

if cc.InstanceType != nil {
event["instance_type._is_defined"] = true
event["instance_type"] = *cc.InstanceType
}
if cc.MinInstances != nil {
event["min_instances._is_defined"] = true
event["min_instances"] = *cc.MinInstances
}
if cc.MaxInstances != nil {
event["max_instances._is_defined"] = true
event["max_instances"] = *cc.MaxInstances
}
event["instance_volume_size"] = cc.InstanceVolumeSize
event["instance_volume_type"] = cc.InstanceVolumeType
if cc.InstanceVolumeIOPS != nil {
event["instance_volume_iops._is_defined"] = true
event["instance_volume_iops"] = *cc.InstanceVolumeIOPS
}
if len(cc.Tags) > 0 {
event["tags._is_defined"] = true
event["tags._len"] = len(cc.Tags)
}
if cc.ClusterName != "cortex" {
event["cluster_name._is_custom"] = true
}
if cc.Region != nil {
event["region._is_defined"] = true
event["region"] = *cc.Region
}
if len(cc.AvailabilityZones) > 0 {
event["availability_zones._is_defined"] = true
event["availability_zones._len"] = len(cc.AvailabilityZones)
event["availability_zones"] = cc.AvailabilityZones
}
if cc.SSLCertificateARN != nil {
event["ssl_certificate_arn._is_defined"] = true
}
if !strings.HasPrefix(cc.Bucket, cc.ClusterName+"-") {
event["bucket._is_custom"] = true
}
event["subnet_visibility"] = cc.SubnetVisibility
event["nat_gateway"] = cc.NATGateway
event["api_load_balancer_scheme"] = cc.APILoadBalancerScheme
event["operator_load_balancer_scheme"] = cc.OperatorLoadBalancerScheme
event["api_gateway"] = cc.APIGatewaySetting
if cc.VPCCIDR != nil {
event["vpc_cidr._is_defined"] = true
}
if !strings.HasPrefix(cc.ImageOperator, "cortexlabs/") {
event["image_operator._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageManager, "cortexlabs/") {
event["image_manager._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageDownloader, "cortexlabs/") {
event["image_downloader._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageRequestMonitor, "cortexlabs/") {
event["image_request_monitor._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageClusterAutoscaler, "cortexlabs/") {
event["image_cluster_autoscaler._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageMetricsServer, "cortexlabs/") {
event["image_metrics_server._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageInferentia, "cortexlabs/") {
event["image_inferentia._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageNeuronRTD, "cortexlabs/") {
event["image_neuron_rtd._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageNvidia, "cortexlabs/") {
event["image_nvidia._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageFluentd, "cortexlabs/") {
event["image_fluentd._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageStatsd, "cortexlabs/") {
event["image_statsd._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageIstioProxy, "cortexlabs/") {
event["image_istio_proxy._is_custom"] = true
}
if !strings.HasPrefix(cc.ImageIstioPilot, "cortexlabs/") {
event["image_istio_pilot._is_custom"] = true
}
if cc.Spot != nil {
event["spot._is_defined"] = true
event["spot"] = *cc.Spot
}
if cc.SpotConfig != nil {
event["spot_config._is_defined"] = true
if len(cc.SpotConfig.InstanceDistribution) > 0 {
event["spot_config.instance_distribution._is_defined"] = true
event["spot_config.instance_distribution._len"] = len(cc.SpotConfig.InstanceDistribution)
event["spot_config.instance_distribution"] = cc.SpotConfig.InstanceDistribution
}
if cc.SpotConfig.OnDemandBaseCapacity != nil {
event["spot_config.on_demand_base_capacity._is_defined"] = true
event["spot_config.on_demand_base_capacity"] = *cc.SpotConfig.OnDemandBaseCapacity
}
if cc.SpotConfig.OnDemandPercentageAboveBaseCapacity != nil {
event["spot_config.on_demand_percentage_above_base_capacity._is_defined"] = true
event["spot_config.on_demand_percentage_above_base_capacity"] = *cc.SpotConfig.OnDemandPercentageAboveBaseCapacity
}
if cc.SpotConfig.MaxPrice != nil {
event["spot_config.max_price._is_defined"] = true
event["spot_config.max_price"] = *cc.SpotConfig.MaxPrice
}
if cc.SpotConfig.InstancePools != nil {
event["spot_config.instance_pools._is_defined"] = true
event["spot_config.instance_pools"] = *cc.SpotConfig.InstancePools
}
if cc.SpotConfig.OnDemandBackup != nil {
event["spot_config.on_demand_backup._is_defined"] = true
event["spot_config.on_demand_backup"] = *cc.SpotConfig.OnDemandBackup
}
}

return event
}
143 changes: 143 additions & 0 deletions pkg/types/userconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cortexlabs/cortex/pkg/consts"
"github.com/cortexlabs/cortex/pkg/lib/k8s"
s "github.com/cortexlabs/cortex/pkg/lib/strings"
"github.com/cortexlabs/cortex/pkg/lib/urls"
"github.com/cortexlabs/cortex/pkg/types"
"github.com/cortexlabs/yaml"
kmeta "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -567,3 +568,145 @@ func ZeroCompute() Compute {
GPU: 0,
}
}

func (api *API) TelemetryEvent(provider types.ProviderType) map[string]interface{} {
event := map[string]interface{}{
"provider": provider,
"kind": api.Kind,
}

if len(api.APIs) > 0 {
event["apis._is_defined"] = true
event["apis._len"] = len(api.APIs)
}

if api.Monitoring != nil {
event["monitoring._is_defined"] = true
event["monitoring.model_type"] = api.Monitoring.ModelType
if api.Monitoring.Key != nil {
event["monitoring.key._is_defined"] = true
}
}

if api.Networking != nil {
event["networking._is_defined"] = true
event["networking.api_gateway"] = api.Networking.APIGateway
if api.Networking.Endpoint != nil {
event["networking.endpoint._is_defined"] = true
if urls.CanonicalizeEndpoint(api.Name) != *api.Networking.Endpoint {
event["networking.endpoint._is_custom"] = true
}
}
if api.Networking.LocalPort != nil {
event["networking.local_port._is_defined"] = true
event["networking.local_port"] = *api.Networking.LocalPort
}
}

if api.Compute != nil {
event["compute._is_defined"] = true
if api.Compute.CPU != nil {
event["compute.cpu._is_defined"] = true
event["compute.cpu"] = float64(api.Compute.CPU.MilliValue()) / 1000
}
if api.Compute.Mem != nil {
event["compute.mem._is_defined"] = true
event["compute.mem"] = api.Compute.Mem.Value()
}
event["compute.gpu"] = api.Compute.GPU
event["compute.inf"] = api.Compute.Inf
}

if api.Predictor != nil {
event["predictor._is_defined"] = true
event["predictor.type"] = api.Predictor.Type
event["predictor.processes_per_replica"] = api.Predictor.ProcessesPerReplica
event["predictor.threads_per_process"] = api.Predictor.ThreadsPerProcess

if api.Predictor.ModelPath != nil {
event["predictor.model_path._is_defined"] = true
}
if api.Predictor.SignatureKey != nil {
event["predictor.signature_key._is_defined"] = true
}
if api.Predictor.PythonPath != nil {
event["predictor.python_path._is_defined"] = true
}
if !strings.HasPrefix(api.Predictor.Image, "cortexlabs/") {
event["predictor.image._is_custom"] = true
}
if !strings.HasPrefix(api.Predictor.TensorFlowServingImage, "cortexlabs/") {
event["predictor.tensorflow_serving_image._is_custom"] = true
}
if len(api.Predictor.Config) > 0 {
event["predictor.config._is_defined"] = true
event["predictor.config._len"] = len(api.Predictor.Config)
}
if len(api.Predictor.Env) > 0 {
event["predictor.env._is_defined"] = true
event["predictor.env._len"] = len(api.Predictor.Env)
}

if api.Predictor.Models != nil {
event["predictor.models._is_defined"] = true
if len(api.Predictor.Models.Paths) > 0 {
event["predictor.models.paths._is_defined"] = true
event["predictor.models.paths._len"] = len(api.Predictor.Models.Paths)
var numSignatureKeysDefined int
for _, mmPath := range api.Predictor.Models.Paths {
if mmPath.SignatureKey != nil {
numSignatureKeysDefined++
}
}
event["predictor.models.paths._num_signature_keys_defined"] = numSignatureKeysDefined
}
if api.Predictor.Models.Dir != nil {
event["predictor.models.dir._is_defined"] = true
}
if api.Predictor.Models.CacheSize != nil {
event["predictor.models.cache_size._is_defined"] = true
event["predictor.models.cache_size"] = *api.Predictor.Models.CacheSize
}
if api.Predictor.Models.DiskCacheSize != nil {
event["predictor.models.disk_cache_size._is_defined"] = true
event["predictor.models.disk_cache_size"] = *api.Predictor.Models.DiskCacheSize
}
if api.Predictor.Models.SignatureKey != nil {
event["predictor.models.signature_key._is_defined"] = true
}
}

if api.Predictor.ServerSideBatching != nil {
event["predictor.server_side_batching._is_defined"] = true
event["predictor.server_side_batching.max_batch_size"] = api.Predictor.ServerSideBatching.MaxBatchSize
event["predictor.server_side_batching.batch_interval"] = api.Predictor.ServerSideBatching.BatchInterval.Seconds()
}
}

if api.UpdateStrategy != nil {
event["update_strategy._is_defined"] = true
event["update_strategy.max_surge"] = api.UpdateStrategy.MaxSurge
event["update_strategy.max_unavailable"] = api.UpdateStrategy.MaxUnavailable
}

if api.Autoscaling != nil {
event["autoscaling._is_defined"] = true
event["autoscaling.min_replicas"] = api.Autoscaling.MinReplicas
event["autoscaling.max_replicas"] = api.Autoscaling.MaxReplicas
event["autoscaling.init_replicas"] = api.Autoscaling.InitReplicas
if api.Autoscaling.TargetReplicaConcurrency != nil {
event["autoscaling.target_replica_concurrency._is_defined"] = true
event["autoscaling.target_replica_concurrency"] = *api.Autoscaling.TargetReplicaConcurrency
}
event["autoscaling.max_replica_concurrency"] = api.Autoscaling.MaxReplicaConcurrency
event["autoscaling.window"] = api.Autoscaling.Window.Seconds()
event["autoscaling.downscale_stabilization_period"] = api.Autoscaling.DownscaleStabilizationPeriod.Seconds()
event["autoscaling.upscale_stabilization_period"] = api.Autoscaling.UpscaleStabilizationPeriod.Seconds()
event["autoscaling.max_downscale_factor"] = api.Autoscaling.MaxDownscaleFactor
event["autoscaling.max_upscale_factor"] = api.Autoscaling.MaxUpscaleFactor
event["autoscaling.downscale_tolerance"] = api.Autoscaling.DownscaleTolerance
event["autoscaling.upscale_tolerance"] = api.Autoscaling.UpscaleTolerance
}

return event
}