Skip to content

Commit

Permalink
Set periodic analytics (#623)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Dec 2, 2018
1 parent 248a53a commit cb54d8c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
5 changes: 5 additions & 0 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"time"

"github.com/appscode/go/log"
v "github.com/appscode/go/version"
"github.com/appscode/kutil/meta"
"github.com/appscode/kutil/tools/cli"
api "github.com/appscode/stash/apis/stash/v1alpha1"
cs "github.com/appscode/stash/client/clientset/versioned"
"github.com/appscode/stash/pkg/backup"
Expand Down Expand Up @@ -39,6 +41,9 @@ func NewCmdBackup() *cobra.Command {
Use: "backup",
Short: "Run Stash Backup",
DisableAutoGenTag: true,
PreRun: func(c *cobra.Command, args []string) {
cli.SendAnalytics(c, v.Version.Version)
},
Run: func(cmd *cobra.Command, args []string) {
config, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigPath)
if err != nil {
Expand Down
18 changes: 5 additions & 13 deletions root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import (
"flag"
"log"
"os"
"strings"

"github.com/appscode/go/log/golog"
v "github.com/appscode/go/version"
"github.com/appscode/kutil/tools/analytics"
"github.com/appscode/kutil/tools/cli"
api "github.com/appscode/stash/apis/stash/v1alpha1"
"github.com/appscode/stash/client/clientset/versioned/scheme"
"github.com/appscode/stash/pkg/util"
"github.com/jpillora/go-ogle-analytics"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
genericapiserver "k8s.io/apiserver/pkg/server"
Expand All @@ -34,24 +32,18 @@ func NewRootCmd() *cobra.Command {
c.Flags().VisitAll(func(flag *pflag.Flag) {
log.Printf("FLAG: --%s=%q", flag.Name, flag.Value)
})
if util.EnableAnalytics && gaTrackingCode != "" {
if client, err := ga.NewClient(gaTrackingCode); err == nil {
util.AnalyticsClientID = analytics.ClientID()
client.ClientID(util.AnalyticsClientID)
parts := strings.Split(c.CommandPath(), " ")
client.Send(ga.NewEvent(parts[0], strings.Join(parts[1:], "/")).Label(v.Version.Version))
}
}
cli.SendAnalytics(c, v.Version.Version)

scheme.AddToScheme(clientsetscheme.Scheme)
scheme.AddToScheme(legacyscheme.Scheme)
util.LoggerOptions = golog.ParseFlags(c.Flags())
cli.LoggerOptions = golog.ParseFlags(c.Flags())
},
}
rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
// ref: https://github.com/kubernetes/kubernetes/issues/17162#issuecomment-225596212
flag.CommandLine.Parse([]string{})
rootCmd.PersistentFlags().StringVar(&util.ServiceName, "service-name", "stash-operator", "Stash service name.")
rootCmd.PersistentFlags().BoolVar(&util.EnableAnalytics, "enable-analytics", util.EnableAnalytics, "Send analytical events to Google Analytics")
rootCmd.PersistentFlags().BoolVar(&cli.EnableAnalytics, "enable-analytics", cli.EnableAnalytics, "Send analytical events to Google Analytics")
rootCmd.PersistentFlags().BoolVar(&api.EnableStatusSubresource, "enable-status-subresource", api.EnableStatusSubresource, "If true, uses sub resource for crds.")

rootCmd.AddCommand(v.NewCmdVersion())
Expand Down
4 changes: 4 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

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

Expand Down

0 comments on commit cb54d8c

Please sign in to comment.