diff --git a/cli/cmd/fetch.go b/cli/cmd/fetch.go index 62caaf4e6..9700b73ec 100644 --- a/cli/cmd/fetch.go +++ b/cli/cmd/fetch.go @@ -18,6 +18,7 @@ var fetchCmd = &cobra.Command{ Use: "fetch", Short: "Download recorded traffic to files", RunE: func(cmd *cobra.Command, args []string) error { + go mizu.ReportRun("tap", mizuTapOptions) if isCompatible, err := mizu.CheckVersionCompatibility(mizuFetchOptions.MizuPort); err != nil { return err } else if !isCompatible { diff --git a/cli/cmd/tap.go b/cli/cmd/tap.go index 245b3d7df..2262076af 100644 --- a/cli/cmd/tap.go +++ b/cli/cmd/tap.go @@ -31,8 +31,8 @@ var mizuTapOptions = &MizuTapOptions{} var direction string var humanMaxEntriesDBSize string var regex *regexp.Regexp -const maxEntriesDBSizeFlagName = "max-entries-db-size" +const maxEntriesDBSizeFlagName = "max-entries-db-size" const analysisMessageToConfirm = `NOTE: running mizu with --analysis flag will upload recorded traffic to UP9 cloud for further analysis and enriched presentation options. @@ -44,6 +44,7 @@ var tapCmd = &cobra.Command{ Long: `Record the ingoing traffic of a kubernetes pod. Supported protocols are HTTP and gRPC.`, RunE: func(cmd *cobra.Command, args []string) error { + go mizu.ReportRun("tap", mizuTapOptions) RunMizuTap(regex, mizuTapOptions) return nil }, diff --git a/cli/cmd/version.go b/cli/cmd/version.go index 366b05da2..4fd4b8bf1 100644 --- a/cli/cmd/version.go +++ b/cli/cmd/version.go @@ -10,20 +10,20 @@ import ( ) type MizuVersionOptions struct { - DebugInfo bool + DebugInfo bool } - var mizuVersionOptions = &MizuVersionOptions{} var versionCmd = &cobra.Command{ Use: "version", Short: "Print version info", RunE: func(cmd *cobra.Command, args []string) error { + go mizu.ReportRun("version", mizuVersionOptions) if mizuVersionOptions.DebugInfo { timeStampInt, _ := strconv.ParseInt(mizu.BuildTimestamp, 10, 0) fmt.Printf("Version: %s \nBranch: %s (%s) \n", mizu.SemVer, mizu.Branch, mizu.GitCommitHash) - fmt.Printf("Build Time: %s (%s)\n", mizu.BuildTimestamp, time.Unix(timeStampInt, 0)) + fmt.Printf("Build Time: %s (%s)\n", mizu.BuildTimestamp, time.Unix(timeStampInt, 0)) } else { fmt.Printf("Version: %s (%s)\n", mizu.SemVer, mizu.Branch) diff --git a/cli/cmd/view.go b/cli/cmd/view.go index a49ebde75..6733418c1 100644 --- a/cli/cmd/view.go +++ b/cli/cmd/view.go @@ -6,7 +6,7 @@ import ( ) type MizuViewOptions struct { - GuiPort uint16 + GuiPort uint16 } var mizuViewOptions = &MizuViewOptions{} @@ -15,6 +15,7 @@ var viewCmd = &cobra.Command{ Use: "view", Short: "Open GUI in browser", RunE: func(cmd *cobra.Command, args []string) error { + go mizu.ReportRun("view", mizuFetchOptions) if isCompatible, err := mizu.CheckVersionCompatibility(mizuFetchOptions.MizuPort); err != nil { return err } else if !isCompatible { @@ -23,7 +24,6 @@ var viewCmd = &cobra.Command{ runMizuView(mizuViewOptions) return nil }, - } func init() { diff --git a/cli/mizu/telemetry.go b/cli/mizu/telemetry.go new file mode 100644 index 000000000..b3dff01d8 --- /dev/null +++ b/cli/mizu/telemetry.go @@ -0,0 +1,29 @@ +package mizu + +import ( + "bytes" + "encoding/json" + "fmt" + "github.com/romana/rlog" + "net/http" +) + +func ReportRun(cmd string, args interface{}) { + if Branch != "main" { + rlog.Debugf("reporting only on main branch") + return + } + url := "https://us-east4-up9-prod.cloudfunctions.net/mizu-telemetry" + + argsBytes, _ := json.Marshal(args) + argsMap := map[string]string{"telemetry_type": "mizu_execution", "cmd": cmd, "args": string(argsBytes), "component": "mizu_cli"} + argsMap["message"] = fmt.Sprintf("mizu %v - %v", argsMap["cmd"], string(argsBytes)) + + jsonValue, _ := json.Marshal(argsMap) + + if resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonValue)); err != nil { + rlog.Debugf("error sending telemtry err: %v, response %v", err, resp) + } else { + rlog.Debugf("Successfully reported telemetry") + } +}