From 69db6cccce51be209d91cd0b8ee45460a03b4491 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Mon, 4 Dec 2023 17:54:24 +0100 Subject: [PATCH] refactor: remove error from analytics (#3802) * remove error from analytics * remove unused recover function * remove status parameter * remove unused struct --------- Co-authored-by: Pantani --- ignite/cmd/ignite/main.go | 9 ----- ignite/internal/analytics/analytics.go | 48 +++++--------------------- ignite/pkg/gacli/gacli.go | 2 -- 3 files changed, 8 insertions(+), 51 deletions(-) diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index f61a3f611b..ec55e86435 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -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) } diff --git a/ignite/internal/analytics/analytics.go b/ignite/internal/analytics/analytics.go index 6bc8367caa..55338c279b 100644 --- a/ignite/internal/analytics/analytics.go +++ b/ignite/internal/analytics/analytics.go @@ -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 } @@ -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) diff --git a/ignite/pkg/gacli/gacli.go b/ignite/pkg/gacli/gacli.go index 7237bcd50b..310cf139f2 100644 --- a/ignite/pkg/gacli/gacli.go +++ b/ignite/pkg/gacli/gacli.go @@ -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"`