Skip to content

Commit 4e29b70

Browse files
authored
Simplify clientID generation for analytics (#247)
1 parent a45937f commit 4e29b70

File tree

5 files changed

+10
-39
lines changed

5 files changed

+10
-39
lines changed

backup.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/appscode/go/log"
1010
"github.com/appscode/kutil/meta"
11-
"github.com/appscode/kutil/tools/analytics"
1211
cs "github.com/appscode/stash/client/typed/stash/v1alpha1"
1312
"github.com/appscode/stash/pkg/backup"
1413
"github.com/appscode/stash/pkg/util"
@@ -43,10 +42,6 @@ func NewCmdBackup() *cobra.Command {
4342
kubeClient := kubernetes.NewForConfigOrDie(config)
4443
stashClient := cs.NewForConfigOrDie(config)
4544

46-
if meta.PossiblyInCluster() {
47-
sendAnalytics(cmd, analytics.ClientID(kubeClient.CoreV1().Nodes()))
48-
}
49-
5045
opt.NodeName = os.Getenv("NODE_NAME")
5146
if opt.NodeName == "" {
5247
log.Fatalln(`Missing ENV var "NODE_NAME"`)

check.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmds
33
import (
44
"github.com/appscode/go/log"
55
"github.com/appscode/kutil/meta"
6-
"github.com/appscode/kutil/tools/analytics"
76
cs "github.com/appscode/stash/client/typed/stash/v1alpha1"
87
"github.com/appscode/stash/pkg/check"
98
"github.com/spf13/cobra"
@@ -32,10 +31,6 @@ func NewCmdCheck() *cobra.Command {
3231
kubeClient := kubernetes.NewForConfigOrDie(config)
3332
stashClient := cs.NewForConfigOrDie(config)
3433

35-
if meta.PossiblyInCluster() {
36-
sendAnalytics(cmd, analytics.ClientID(kubeClient.CoreV1().Nodes()))
37-
}
38-
3934
c := check.New(kubeClient, stashClient, opt)
4035
if err = c.Run(); err != nil {
4136
log.Fatal(err)

recover.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmds
33
import (
44
"github.com/appscode/go/log"
55
"github.com/appscode/kutil/meta"
6-
"github.com/appscode/kutil/tools/analytics"
76
cs "github.com/appscode/stash/client/typed/stash/v1alpha1"
87
"github.com/appscode/stash/pkg/recovery"
98
"github.com/spf13/cobra"
@@ -30,10 +29,6 @@ func NewCmdRecover() *cobra.Command {
3029
kubeClient := kubernetes.NewForConfigOrDie(config)
3130
stashClient := cs.NewForConfigOrDie(config)
3231

33-
if meta.PossiblyInCluster() {
34-
sendAnalytics(cmd, analytics.ClientID(kubeClient.CoreV1().Nodes()))
35-
}
36-
3732
c := recovery.New(kubeClient, stashClient, meta.Namespace(), recoveryName)
3833
c.Run()
3934
},

root.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import (
55
"log"
66
"strings"
77

8-
"github.com/appscode/go/analytics"
98
v "github.com/appscode/go/version"
10-
"github.com/appscode/kutil/meta"
9+
"github.com/appscode/kutil/tools/analytics"
1110
"github.com/appscode/stash/client/scheme"
1211
"github.com/jpillora/go-ogle-analytics"
1312
"github.com/spf13/cobra"
@@ -20,6 +19,9 @@ const (
2019
)
2120

2221
func NewRootCmd() *cobra.Command {
22+
var (
23+
enableAnalytics = true
24+
)
2325
var rootCmd = &cobra.Command{
2426
Use: "stash",
2527
Short: `Stash by AppsCode - Backup your Kubernetes Volumes`,
@@ -29,8 +31,12 @@ func NewRootCmd() *cobra.Command {
2931
c.Flags().VisitAll(func(flag *pflag.Flag) {
3032
log.Printf("FLAG: --%s=%q", flag.Name, flag.Value)
3133
})
32-
if !meta.PossiblyInCluster() {
33-
sendAnalytics(c, analytics.ClientID())
34+
if enableAnalytics && gaTrackingCode != "" {
35+
if client, err := ga.NewClient(gaTrackingCode); err == nil {
36+
client.ClientID(analytics.ClientID())
37+
parts := strings.Split(c.CommandPath(), " ")
38+
client.Send(ga.NewEvent(parts[0], strings.Join(parts[1:], "/")).Label(v.Version.Version))
39+
}
3440
}
3541
scheme.AddToScheme(clientsetscheme.Scheme)
3642
},
@@ -47,17 +53,3 @@ func NewRootCmd() *cobra.Command {
4753
rootCmd.AddCommand(NewCmdCheck())
4854
return rootCmd
4955
}
50-
51-
var (
52-
enableAnalytics = true
53-
)
54-
55-
func sendAnalytics(c *cobra.Command, clientID string) {
56-
if enableAnalytics && gaTrackingCode != "" {
57-
if client, err := ga.NewClient(gaTrackingCode); err == nil {
58-
client.ClientID(clientID)
59-
parts := strings.Split(c.CommandPath(), " ")
60-
client.Send(ga.NewEvent(parts[0], strings.Join(parts[1:], "/")).Label(v.Version.Version))
61-
}
62-
}
63-
}

run.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"github.com/appscode/go/log"
99
stringz "github.com/appscode/go/strings"
1010
v "github.com/appscode/go/version"
11-
"github.com/appscode/kutil/meta"
12-
"github.com/appscode/kutil/tools/analytics"
1311
"github.com/appscode/pat"
1412
api "github.com/appscode/stash/apis/stash"
1513
cs "github.com/appscode/stash/client/typed/stash/v1alpha1"
@@ -53,10 +51,6 @@ func NewCmdRun() *cobra.Command {
5351
stashClient := cs.NewForConfigOrDie(config)
5452
crdClient := crd_cs.NewForConfigOrDie(config)
5553

56-
if meta.PossiblyInCluster() {
57-
sendAnalytics(cmd, analytics.ClientID(kubeClient.CoreV1().Nodes()))
58-
}
59-
6054
// get kube api server version
6155
version, err := kubeClient.Discovery().ServerVersion()
6256
if err != nil {

0 commit comments

Comments
 (0)