@@ -3,6 +3,7 @@ package advise
33import (
44 "context"
55 "fmt"
6+ "time"
67
78 "github.com/sourcegraph/sourcegraph/lib/errors"
89 "github.com/sourcegraph/src-cli/internal/scout"
@@ -24,6 +25,7 @@ func K8s(
2425 Namespace : "default" ,
2526 Pod : "" ,
2627 Output : "" ,
28+ Warnings : false ,
2729 RestConfig : restConfig ,
2830 K8sClient : k8sClient ,
2931 MetricsClient : metricsClient ,
@@ -51,6 +53,10 @@ func K8s(
5153 return nil
5254 }
5355
56+ if cfg .Output != "" {
57+ fmt .Printf ("writing to %s. This can take a few minutes..." , cfg .Output )
58+ }
59+
5460 for _ , pod := range pods {
5561 err = Advise (ctx , cfg , pod )
5662 if err != nil {
@@ -67,29 +73,42 @@ func K8s(
6773// of a resource is needed. Advice is generated and either printed to the console
6874// or output to a file depending on the cfg.Output field.
6975func Advise (ctx context.Context , cfg * scout.Config , pod v1.Pod ) error {
70- var advice []string
76+ var advice []scout. Advice
7177 usageMetrics , err := getUsageMetrics (ctx , cfg , pod )
7278 if err != nil {
7379 return errors .Wrap (err , "could not get usage metrics" )
7480 }
75-
7681 for _ , metrics := range usageMetrics {
7782 cpuAdvice := CheckUsage (metrics .CpuUsage , "CPU" , metrics .ContainerName )
78- advice = append (advice , cpuAdvice )
83+ if cfg .Warnings {
84+ advice = append (advice , cpuAdvice )
85+ } else if ! cfg .Warnings && cpuAdvice .Kind != scout .WARNING {
86+ advice = append (advice , cpuAdvice )
87+ }
7988
8089 memoryAdvice := CheckUsage (metrics .MemoryUsage , "memory" , metrics .ContainerName )
81- advice = append (advice , memoryAdvice )
90+ if cfg .Warnings {
91+ advice = append (advice , memoryAdvice )
92+ } else if ! cfg .Warnings && memoryAdvice .Kind != scout .WARNING {
93+ advice = append (advice , memoryAdvice )
94+ }
8295
8396 if metrics .Storage != nil {
8497 storageAdvice := CheckUsage (metrics .StorageUsage , "storage" , metrics .ContainerName )
85- advice = append (advice , storageAdvice )
98+ if cfg .Warnings {
99+ advice = append (advice , storageAdvice )
100+ } else if ! cfg .Warnings && storageAdvice .Kind != scout .WARNING {
101+ advice = append (advice , storageAdvice )
102+ }
86103 }
87104
88105 if cfg .Output != "" {
89106 OutputToFile (ctx , cfg , pod .Name , advice )
90107 } else {
91- for _ , msg := range advice {
92- fmt .Println (msg )
108+ fmt .Printf ("%s %s: advising...\n " , scout .EmojiFingerPointRight , pod .Name )
109+ time .Sleep (time .Millisecond * 300 )
110+ for _ , adv := range advice {
111+ fmt .Printf ("\t %s\n " , adv .Msg )
93112 }
94113 }
95114 }
0 commit comments