Skip to content

Commit

Permalink
refactor: remove error from analytics (#3802)
Browse files Browse the repository at this point in the history
* remove error from analytics

* remove unused recover function

* remove status parameter

* remove unused struct

---------

Co-authored-by: Pantani <Pantani>
  • Loading branch information
Pantani authored Dec 4, 2023
1 parent ab3f5c1 commit 69db6cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 51 deletions.
9 changes: 0 additions & 9 deletions ignite/cmd/ignite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ func main() {
func run() int {
const exitCodeOK, exitCodeError = 0, 1
var wg sync.WaitGroup

defer func() {
if r := recover(); r != nil {
analytics.SendMetric(&wg, os.Args, analytics.WithError(fmt.Errorf("%v", r)))
fmt.Println(r)
os.Exit(exitCodeError)
}
}()

if len(os.Args) > 1 {
analytics.SendMetric(&wg, os.Args)
}
Expand Down
48 changes: 8 additions & 40 deletions ignite/internal/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,25 @@ const (

var gaclient gacli.Client

type (
// metric represents an analytics metric.
options struct {
// err sets metrics type as an error metric.
err error
}

// anonIdentity represents an analytics identity file.
anonIdentity struct {
// name represents the username.
Name string `json:"name" yaml:"name"`
// doNotTrack represents the user track choice.
DoNotTrack bool `json:"doNotTrack" yaml:"doNotTrack"`
}
)
// anonIdentity represents an analytics identity file.
type anonIdentity struct {
// name represents the username.
Name string `json:"name" yaml:"name"`
// doNotTrack represents the user track choice.
DoNotTrack bool `json:"doNotTrack" yaml:"doNotTrack"`
}

func init() {
gaclient = gacli.New(telemetryEndpoint)
}

// Option configures ChainCmd.
type Option func(*options)

// WithError with application command error.
func WithError(error error) Option {
return func(m *options) {
m.err = error
}
}

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

// apply analytics options.
var opt options
for _, o := range opts {
o(&opt)
}

if args[1] == "version" {
return
}
Expand All @@ -83,14 +59,6 @@ func SendMetric(wg *sync.WaitGroup, args []string, opts ...Option) {
SessionID: dntInfo.Name,
Version: version.Version,
}

switch {
case opt.err == nil:
met.Status = "success"
case opt.err != nil:
met.Status = "error"
met.Error = opt.err.Error()
}
met.Cmd = args[1]

wg.Add(1)
Expand Down
2 changes: 0 additions & 2 deletions ignite/pkg/gacli/gacli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ type (
}
// Metric represents a data point.
Metric struct {
Status string `json:"status,omitempty"`
OS string `json:"os,omitempty"`
Arch string `json:"arch,omitempty"`
FullCmd string `json:"full_command,omitempty"`
Cmd string `json:"command,omitempty"`
Error string `json:"error,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 69db6cc

Please sign in to comment.