Skip to content
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

refactor: remove flags from analytics #3803

Merged
merged 7 commits into from
Dec 5, 2023
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
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:])
ilgooz marked this conversation as resolved.
Show resolved Hide resolved
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
Loading