Skip to content

Commit cb54d8c

Browse files
authored
Set periodic analytics (#623)
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 248a53a commit cb54d8c

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

backup.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"time"
77

88
"github.com/appscode/go/log"
9+
v "github.com/appscode/go/version"
910
"github.com/appscode/kutil/meta"
11+
"github.com/appscode/kutil/tools/cli"
1012
api "github.com/appscode/stash/apis/stash/v1alpha1"
1113
cs "github.com/appscode/stash/client/clientset/versioned"
1214
"github.com/appscode/stash/pkg/backup"
@@ -39,6 +41,9 @@ func NewCmdBackup() *cobra.Command {
3941
Use: "backup",
4042
Short: "Run Stash Backup",
4143
DisableAutoGenTag: true,
44+
PreRun: func(c *cobra.Command, args []string) {
45+
cli.SendAnalytics(c, v.Version.Version)
46+
},
4247
Run: func(cmd *cobra.Command, args []string) {
4348
config, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigPath)
4449
if err != nil {

root.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import (
44
"flag"
55
"log"
66
"os"
7-
"strings"
87

98
"github.com/appscode/go/log/golog"
109
v "github.com/appscode/go/version"
11-
"github.com/appscode/kutil/tools/analytics"
10+
"github.com/appscode/kutil/tools/cli"
1211
api "github.com/appscode/stash/apis/stash/v1alpha1"
1312
"github.com/appscode/stash/client/clientset/versioned/scheme"
1413
"github.com/appscode/stash/pkg/util"
15-
"github.com/jpillora/go-ogle-analytics"
1614
"github.com/spf13/cobra"
1715
"github.com/spf13/pflag"
1816
genericapiserver "k8s.io/apiserver/pkg/server"
@@ -34,24 +32,18 @@ func NewRootCmd() *cobra.Command {
3432
c.Flags().VisitAll(func(flag *pflag.Flag) {
3533
log.Printf("FLAG: --%s=%q", flag.Name, flag.Value)
3634
})
37-
if util.EnableAnalytics && gaTrackingCode != "" {
38-
if client, err := ga.NewClient(gaTrackingCode); err == nil {
39-
util.AnalyticsClientID = analytics.ClientID()
40-
client.ClientID(util.AnalyticsClientID)
41-
parts := strings.Split(c.CommandPath(), " ")
42-
client.Send(ga.NewEvent(parts[0], strings.Join(parts[1:], "/")).Label(v.Version.Version))
43-
}
44-
}
35+
cli.SendAnalytics(c, v.Version.Version)
36+
4537
scheme.AddToScheme(clientsetscheme.Scheme)
4638
scheme.AddToScheme(legacyscheme.Scheme)
47-
util.LoggerOptions = golog.ParseFlags(c.Flags())
39+
cli.LoggerOptions = golog.ParseFlags(c.Flags())
4840
},
4941
}
5042
rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
5143
// ref: https://github.com/kubernetes/kubernetes/issues/17162#issuecomment-225596212
5244
flag.CommandLine.Parse([]string{})
5345
rootCmd.PersistentFlags().StringVar(&util.ServiceName, "service-name", "stash-operator", "Stash service name.")
54-
rootCmd.PersistentFlags().BoolVar(&util.EnableAnalytics, "enable-analytics", util.EnableAnalytics, "Send analytical events to Google Analytics")
46+
rootCmd.PersistentFlags().BoolVar(&cli.EnableAnalytics, "enable-analytics", cli.EnableAnalytics, "Send analytical events to Google Analytics")
5547
rootCmd.PersistentFlags().BoolVar(&api.EnableStatusSubresource, "enable-status-subresource", api.EnableStatusSubresource, "If true, uses sub resource for crds.")
5648

5749
rootCmd.AddCommand(v.NewCmdVersion())

run.go

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

66
"github.com/appscode/go/log"
77
v "github.com/appscode/go/version"
8+
"github.com/appscode/kutil/tools/cli"
89
"github.com/appscode/stash/pkg/cmds/server"
910
"github.com/spf13/cobra"
1011
)
@@ -17,6 +18,9 @@ func NewCmdRun(out, errOut io.Writer, stopCh <-chan struct{}) *cobra.Command {
1718
Short: "Launch Stash Controller",
1819
Long: "Launch Stash Controller",
1920
DisableAutoGenTag: true,
21+
PreRun: func(c *cobra.Command, args []string) {
22+
cli.SendAnalytics(c, v.Version.Version)
23+
},
2024
RunE: func(cmd *cobra.Command, args []string) error {
2125
log.Infof("Starting operator version %s+%s ...", v.Version.Version, v.Version.CommitHash)
2226

0 commit comments

Comments
 (0)