Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move analytics collector to root command #212

Merged
merged 1 commit into from
Sep 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/reference/hostfacts/hostfacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Hostfacts by AppsCode - Expose node metrics
```
--allow_verification_with_non_compliant_keys Allow a SignatureVerifier to use keys which are technically non-compliant with RFC6962.
--alsologtostderr log to standard error as well as files
--analytics Send analytical events to Google Analytics (default true)
-h, --help help for hostfacts
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
Expand Down
1 change: 1 addition & 0 deletions docs/reference/hostfacts/hostfacts_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ hostfacts run [flags]
```
--allow_verification_with_non_compliant_keys Allow a SignatureVerifier to use keys which are technically non-compliant with RFC6962.
--alsologtostderr log to standard error as well as files
--analytics Send analytical events to Google Analytics (default true)
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files (default true)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/hostfacts/hostfacts_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ hostfacts version [flags]
```
--allow_verification_with_non_compliant_keys Allow a SignatureVerifier to use keys which are technically non-compliant with RFC6962.
--alsologtostderr log to standard error as well as files
--analytics Send analytical events to Google Analytics (default true)
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files (default true)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/searchlight/searchlight.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Searchlight by AppsCode - Alerts for Kubernetes
```
--allow_verification_with_non_compliant_keys Allow a SignatureVerifier to use keys which are technically non-compliant with RFC6962.
--alsologtostderr log to standard error as well as files
--analytics Send analytical events to Google Analytics (default true)
-h, --help help for searchlight
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
Expand Down
1 change: 1 addition & 0 deletions docs/reference/searchlight/searchlight_configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ searchlight configure [flags]
```
--allow_verification_with_non_compliant_keys Allow a SignatureVerifier to use keys which are technically non-compliant with RFC6962.
--alsologtostderr log to standard error as well as files
--analytics Send analytical events to Google Analytics (default true)
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files (default true)
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/searchlight/searchlight_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ searchlight run [flags]
### Options

```
--analytics Send analytical event to Google Analytics (default true)
--api.address string The address of the Searchlight API Server (default ":8080")
--config-dir string Path to directory containing icinga2 config. This should be an emptyDir inside Kubernetes. (default "/srv")
--config-secret-name string Name of Kubernetes secret used to pass icinga credentials. (default "searchlight-operator")
Expand All @@ -29,6 +28,7 @@ searchlight run [flags]
```
--allow_verification_with_non_compliant_keys Allow a SignatureVerifier to use keys which are technically non-compliant with RFC6962.
--alsologtostderr log to standard error as well as files
--analytics Send analytical events to Google Analytics (default true)
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files (default true)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/searchlight/searchlight_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ searchlight version [flags]
```
--allow_verification_with_non_compliant_keys Allow a SignatureVerifier to use keys which are technically non-compliant with RFC6962.
--alsologtostderr log to standard error as well as files
--analytics Send analytical events to Google Analytics (default true)
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files (default true)
Expand Down
28 changes: 17 additions & 11 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 0 additions & 56 deletions pkg/analytics/analytics.go

This file was deleted.

14 changes: 13 additions & 1 deletion pkg/cmds/hostfacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@ package cmds
import (
"flag"
"log"
"strings"

v "github.com/appscode/go/version"
"github.com/jpillora/go-ogle-analytics"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

func NewCmdHostfacts(version string) *cobra.Command {
var (
enableAnalytics = true
)
cmd := &cobra.Command{
Use: "hostfacts [command]",
Short: `Hostfacts by AppsCode - Expose node metrics`,
PersistentPreRun: func(c *cobra.Command, args []string) {
c.Flags().VisitAll(func(flag *pflag.Flag) {
log.Printf("FLAG: --%s=%q", flag.Name, flag.Value)
})
if enableAnalytics && gaTrackingCode != "" {
if client, err := ga.NewClient(gaTrackingCode); err == nil {
parts := strings.Split(c.CommandPath(), " ")
client.Send(ga.NewEvent(parts[0], strings.Join(parts[1:], "/")).Label(version))
}
}
},
}
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
// ref: https://github.com/kubernetes/kubernetes/issues/17162#issuecomment-225596212
flag.CommandLine.Parse([]string{})
cmd.PersistentFlags().BoolVar(&enableAnalytics, "analytics", enableAnalytics, "Send analytical events to Google Analytics")

cmd.AddCommand(NewCmdServer(version))
cmd.AddCommand(NewCmdServer())
cmd.AddCommand(v.NewCmdVersion())
return cmd
}
14 changes: 1 addition & 13 deletions pkg/cmds/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
_ "github.com/appscode/searchlight/api/install"
tcs "github.com/appscode/searchlight/client/clientset"
_ "github.com/appscode/searchlight/client/clientset/fake"
"github.com/appscode/searchlight/pkg/analytics"
"github.com/appscode/searchlight/pkg/icinga"
"github.com/appscode/searchlight/pkg/migrator"
"github.com/appscode/searchlight/pkg/operator"
Expand All @@ -20,26 +19,16 @@ import (
"k8s.io/client-go/tools/clientcmd"
)

func NewCmdOperator(version string) *cobra.Command {
func NewCmdOperator() *cobra.Command {
opt := operator.Options{
ConfigRoot: "/srv",
ConfigSecretName: "searchlight-operator",
APIAddress: ":8080",
WebAddress: ":56790",
EnableAnalytics: true,
}
cmd := &cobra.Command{
Use: "run",
Short: "Run operator",
PreRun: func(cmd *cobra.Command, args []string) {
if opt.EnableAnalytics {
analytics.Enable()
}
analytics.SendEvent("operator", "started", version)
},
PostRun: func(cmd *cobra.Command, args []string) {
analytics.SendEvent("operator", "stopped", version)
},
Run: func(cmd *cobra.Command, args []string) {
run(opt)
},
Expand All @@ -51,7 +40,6 @@ func NewCmdOperator(version string) *cobra.Command {
cmd.Flags().StringVar(&opt.ConfigSecretName, "config-secret-name", opt.ConfigSecretName, "Name of Kubernetes secret used to pass icinga credentials.")
cmd.Flags().StringVar(&opt.APIAddress, "api.address", opt.APIAddress, "The address of the Searchlight API Server")
cmd.Flags().StringVar(&opt.WebAddress, "web.address", opt.WebAddress, "Address to listen on for web interface and telemetry.")
cmd.Flags().BoolVar(&opt.EnableAnalytics, "analytics", opt.EnableAnalytics, "Send analytical event to Google Analytics")

return cmd
}
Expand Down
14 changes: 13 additions & 1 deletion pkg/cmds/searchlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@ package cmds
import (
"flag"
"log"
"strings"

v "github.com/appscode/go/version"
"github.com/jpillora/go-ogle-analytics"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

func NewCmdSearchlight(version string) *cobra.Command {
var (
enableAnalytics = true
)
cmd := &cobra.Command{
Use: "searchlight [command]",
Short: `Searchlight by AppsCode - Alerts for Kubernetes`,
PersistentPreRun: func(c *cobra.Command, args []string) {
c.Flags().VisitAll(func(flag *pflag.Flag) {
log.Printf("FLAG: --%s=%q", flag.Name, flag.Value)
})
if enableAnalytics && gaTrackingCode != "" {
if client, err := ga.NewClient(gaTrackingCode); err == nil {
parts := strings.Split(c.CommandPath(), " ")
client.Send(ga.NewEvent(parts[0], strings.Join(parts[1:], "/")).Label(version))
}
}
},
}
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
// ref: https://github.com/kubernetes/kubernetes/issues/17162#issuecomment-225596212
flag.CommandLine.Parse([]string{})
cmd.PersistentFlags().BoolVar(&enableAnalytics, "analytics", enableAnalytics, "Send analytical events to Google Analytics")

cmd.AddCommand(NewCmdOperator(version))
cmd.AddCommand(NewCmdOperator())
cmd.AddCommand(NewCmdConfigure())
cmd.AddCommand(v.NewCmdVersion())
return cmd
Expand Down
13 changes: 1 addition & 12 deletions pkg/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@ package cmds
import (
"fmt"

"github.com/appscode/searchlight/pkg/analytics"
"github.com/appscode/searchlight/pkg/hostfacts"
"github.com/spf13/cobra"
)

func NewCmdServer(version string) *cobra.Command {
func NewCmdServer() *cobra.Command {
srv := hostfacts.Server{
Address: fmt.Sprintf(":%d", 56977),
}
cmd := &cobra.Command{
Use: "run",
Short: "Run server",
PreRun: func(cmd *cobra.Command, args []string) {
//if opt.EnableAnalytics {
// analytics.Enable()
//}
analytics.SendEvent("operator", "started", version)
},
PostRun: func(cmd *cobra.Command, args []string) {
analytics.SendEvent("operator", "stopped", version)
},
Run: func(cmd *cobra.Command, args []string) {
srv.ListenAndServe()
},
Expand All @@ -37,6 +27,5 @@ func NewCmdServer(version string) *cobra.Command {
cmd.Flags().StringVar(&srv.Username, "username", srv.Username, "Username used for basic authentication")
cmd.Flags().StringVar(&srv.Password, "password", srv.Password, "Password used for basic authentication")
cmd.Flags().StringVar(&srv.Token, "token", srv.Token, "Token used for bearer authentication")
// cmd.Flags().BoolVar(&opt.EnableAnalytics, "analytics", opt.EnableAnalytics, "Send analytical event to Google Analytics")
return cmd
}
5 changes: 5 additions & 0 deletions pkg/cmds/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cmds

const (
gaTrackingCode = "UA-62096468-20"
)
Loading