Skip to content

Commit

Permalink
refactor: remove flags from analytics (#3803)
Browse files Browse the repository at this point in the history
* remove parameters and sensitive data

* remove unused set

* add changelog

* Apply suggestions from code review

* Apply suggestions from code review

---------

Co-authored-by: Pantani <Pantani>
Co-authored-by: İlker G. Öztürk <[email protected]>
  • Loading branch information
Pantani and ilgooz authored Dec 5, 2023
1 parent 70e787f commit 296e226
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
14 changes: 9 additions & 5 deletions ignite/cmd/ignite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ func main() {

func run() int {
const exitCodeOK, exitCodeError = 0, 1
var wg sync.WaitGroup
if len(os.Args) > 1 {
analytics.SendMetric(&wg, os.Args)
}

ctx := clictx.From(context.Background())
cmd, cleanUp, err := ignitecmd.New(ctx)
if err != nil {
Expand All @@ -36,6 +31,15 @@ func run() int {
}
defer cleanUp()

// find command and send to analytics
subCmd, _, err := cmd.Find(os.Args[1:])
if err != nil {
fmt.Printf("%v\n", err)
return exitCodeError
}
var wg sync.WaitGroup
analytics.SendMetric(&wg, subCmd)

err = cmd.ExecuteContext(ctx)
if errors.Is(ctx.Err(), context.Canceled) || errors.Is(err, context.Canceled) {
fmt.Println("aborted")
Expand Down
16 changes: 7 additions & 9 deletions ignite/internal/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"

"github.com/manifoldco/promptui"
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/gacli"
"github.com/ignite/cli/ignite/pkg/randstr"
Expand Down Expand Up @@ -37,13 +38,8 @@ func init() {
}

// SendMetric send command metrics to analytics.
func SendMetric(wg *sync.WaitGroup, args []string) {
// only the app name
if len(args) <= 1 {
return
}

if args[1] == "version" {
func SendMetric(wg *sync.WaitGroup, cmd *cobra.Command) {
if cmd.Name() == "version" {
return
}

Expand All @@ -52,14 +48,16 @@ func SendMetric(wg *sync.WaitGroup, args []string) {
return
}

path := cmd.CommandPath()
met := gacli.Metric{
Name: cmd.Name(),
Cmd: path,
Tag: strings.ReplaceAll(path, " ", "+"),
OS: runtime.GOOS,
Arch: runtime.GOARCH,
FullCmd: strings.Join(args[1:], " "),
SessionID: dntInfo.Name,
Version: version.Version,
}
met.Cmd = args[1]

wg.Add(1)
go func() {
Expand Down
5 changes: 3 additions & 2 deletions ignite/pkg/gacli/gacli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ type (
}
// Metric represents a data point.
Metric struct {
Name string `json:"name,omitempty"`
Cmd string `json:"command,omitempty"`
Tag string `json:"tag,omitempty"`
OS string `json:"os,omitempty"`
Arch string `json:"arch,omitempty"`
FullCmd string `json:"full_command,omitempty"`
Cmd string `json:"command,omitempty"`
Version string `json:"version,omitempty"`
SessionID string `json:"session_id,omitempty"`
EngagementTimeMsec string `json:"engagement_time_msec,omitempty"`
Expand Down

0 comments on commit 296e226

Please sign in to comment.