@@ -24,6 +24,7 @@ import (
24
24
"github.com/cortexlabs/cortex/pkg/consts"
25
25
"github.com/cortexlabs/cortex/pkg/lib/k8s"
26
26
s "github.com/cortexlabs/cortex/pkg/lib/strings"
27
+ "github.com/cortexlabs/cortex/pkg/lib/urls"
27
28
"github.com/cortexlabs/cortex/pkg/types"
28
29
"github.com/cortexlabs/yaml"
29
30
kmeta "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -567,3 +568,145 @@ func ZeroCompute() Compute {
567
568
GPU : 0 ,
568
569
}
569
570
}
571
+
572
+ func (api * API ) TelemetryEvent (provider types.ProviderType ) map [string ]interface {} {
573
+ event := map [string ]interface {}{
574
+ "provider" : provider ,
575
+ "kind" : api .Kind ,
576
+ }
577
+
578
+ if len (api .APIs ) > 0 {
579
+ event ["apis._is_defined" ] = true
580
+ event ["apis._len" ] = len (api .APIs )
581
+ }
582
+
583
+ if api .Monitoring != nil {
584
+ event ["monitoring._is_defined" ] = true
585
+ event ["monitoring.model_type" ] = api .Monitoring .ModelType
586
+ if api .Monitoring .Key != nil {
587
+ event ["monitoring.key._is_defined" ] = true
588
+ }
589
+ }
590
+
591
+ if api .Networking != nil {
592
+ event ["networking._is_defined" ] = true
593
+ event ["networking.api_gateway" ] = api .Networking .APIGateway
594
+ if api .Networking .Endpoint != nil {
595
+ event ["networking.endpoint._is_defined" ] = true
596
+ if urls .CanonicalizeEndpoint (api .Name ) != * api .Networking .Endpoint {
597
+ event ["networking.endpoint._is_custom" ] = true
598
+ }
599
+ }
600
+ if api .Networking .LocalPort != nil {
601
+ event ["networking.local_port._is_defined" ] = true
602
+ event ["networking.local_port" ] = * api .Networking .LocalPort
603
+ }
604
+ }
605
+
606
+ if api .Compute != nil {
607
+ event ["compute._is_defined" ] = true
608
+ if api .Compute .CPU != nil {
609
+ event ["compute.cpu._is_defined" ] = true
610
+ event ["compute.cpu" ] = float64 (api .Compute .CPU .MilliValue ()) / 1000
611
+ }
612
+ if api .Compute .Mem != nil {
613
+ event ["compute.mem._is_defined" ] = true
614
+ event ["compute.mem" ] = api .Compute .Mem .Value ()
615
+ }
616
+ event ["compute.gpu" ] = api .Compute .GPU
617
+ event ["compute.inf" ] = api .Compute .Inf
618
+ }
619
+
620
+ if api .Predictor != nil {
621
+ event ["predictor._is_defined" ] = true
622
+ event ["predictor.type" ] = api .Predictor .Type
623
+ event ["predictor.processes_per_replica" ] = api .Predictor .ProcessesPerReplica
624
+ event ["predictor.threads_per_process" ] = api .Predictor .ThreadsPerProcess
625
+
626
+ if api .Predictor .ModelPath != nil {
627
+ event ["predictor.model_path._is_defined" ] = true
628
+ }
629
+ if api .Predictor .SignatureKey != nil {
630
+ event ["predictor.signature_key._is_defined" ] = true
631
+ }
632
+ if api .Predictor .PythonPath != nil {
633
+ event ["predictor.python_path._is_defined" ] = true
634
+ }
635
+ if ! strings .HasPrefix (api .Predictor .Image , "cortexlabs/" ) {
636
+ event ["predictor.image._is_custom" ] = true
637
+ }
638
+ if ! strings .HasPrefix (api .Predictor .TensorFlowServingImage , "cortexlabs/" ) {
639
+ event ["predictor.tensorflow_serving_image._is_custom" ] = true
640
+ }
641
+ if len (api .Predictor .Config ) > 0 {
642
+ event ["predictor.config._is_defined" ] = true
643
+ event ["predictor.config._len" ] = len (api .Predictor .Config )
644
+ }
645
+ if len (api .Predictor .Env ) > 0 {
646
+ event ["predictor.env._is_defined" ] = true
647
+ event ["predictor.env._len" ] = len (api .Predictor .Env )
648
+ }
649
+
650
+ if api .Predictor .Models != nil {
651
+ event ["predictor.models._is_defined" ] = true
652
+ if len (api .Predictor .Models .Paths ) > 0 {
653
+ event ["predictor.models.paths._is_defined" ] = true
654
+ event ["predictor.models.paths._len" ] = len (api .Predictor .Models .Paths )
655
+ var numSignatureKeysDefined int
656
+ for _ , mmPath := range api .Predictor .Models .Paths {
657
+ if mmPath .SignatureKey != nil {
658
+ numSignatureKeysDefined ++
659
+ }
660
+ }
661
+ event ["predictor.models.paths._num_signature_keys_defined" ] = numSignatureKeysDefined
662
+ }
663
+ if api .Predictor .Models .Dir != nil {
664
+ event ["predictor.models.dir._is_defined" ] = true
665
+ }
666
+ if api .Predictor .Models .CacheSize != nil {
667
+ event ["predictor.models.cache_size._is_defined" ] = true
668
+ event ["predictor.models.cache_size" ] = * api .Predictor .Models .CacheSize
669
+ }
670
+ if api .Predictor .Models .DiskCacheSize != nil {
671
+ event ["predictor.models.disk_cache_size._is_defined" ] = true
672
+ event ["predictor.models.disk_cache_size" ] = * api .Predictor .Models .DiskCacheSize
673
+ }
674
+ if api .Predictor .Models .SignatureKey != nil {
675
+ event ["predictor.models.signature_key._is_defined" ] = true
676
+ }
677
+ }
678
+
679
+ if api .Predictor .ServerSideBatching != nil {
680
+ event ["predictor.server_side_batching._is_defined" ] = true
681
+ event ["predictor.server_side_batching.max_batch_size" ] = api .Predictor .ServerSideBatching .MaxBatchSize
682
+ event ["predictor.server_side_batching.batch_interval" ] = api .Predictor .ServerSideBatching .BatchInterval .Seconds ()
683
+ }
684
+ }
685
+
686
+ if api .UpdateStrategy != nil {
687
+ event ["update_strategy._is_defined" ] = true
688
+ event ["update_strategy.max_surge" ] = api .UpdateStrategy .MaxSurge
689
+ event ["update_strategy.max_unavailable" ] = api .UpdateStrategy .MaxUnavailable
690
+ }
691
+
692
+ if api .Autoscaling != nil {
693
+ event ["autoscaling._is_defined" ] = true
694
+ event ["autoscaling.min_replicas" ] = api .Autoscaling .MinReplicas
695
+ event ["autoscaling.max_replicas" ] = api .Autoscaling .MaxReplicas
696
+ event ["autoscaling.init_replicas" ] = api .Autoscaling .InitReplicas
697
+ if api .Autoscaling .TargetReplicaConcurrency != nil {
698
+ event ["autoscaling.target_replica_concurrency._is_defined" ] = true
699
+ event ["autoscaling.target_replica_concurrency" ] = * api .Autoscaling .TargetReplicaConcurrency
700
+ }
701
+ event ["autoscaling.max_replica_concurrency" ] = api .Autoscaling .MaxReplicaConcurrency
702
+ event ["autoscaling.window" ] = api .Autoscaling .Window .Seconds ()
703
+ event ["autoscaling.downscale_stabilization_period" ] = api .Autoscaling .DownscaleStabilizationPeriod .Seconds ()
704
+ event ["autoscaling.upscale_stabilization_period" ] = api .Autoscaling .UpscaleStabilizationPeriod .Seconds ()
705
+ event ["autoscaling.max_downscale_factor" ] = api .Autoscaling .MaxDownscaleFactor
706
+ event ["autoscaling.max_upscale_factor" ] = api .Autoscaling .MaxUpscaleFactor
707
+ event ["autoscaling.downscale_tolerance" ] = api .Autoscaling .DownscaleTolerance
708
+ event ["autoscaling.upscale_tolerance" ] = api .Autoscaling .UpscaleTolerance
709
+ }
710
+
711
+ return event
712
+ }
0 commit comments