Skip to content

Commit a331e14

Browse files
Josef Karasekpkosiec
Josef Karasek
andauthored
Add segment analytics to CLI (#1271)
* Add segment analytics to CLI Co-authored-by: Pawel Kosiec <[email protected]> * Update internal/cli/analytics/reporter.go Co-authored-by: Pawel Kosiec <[email protected]> * Update internal/cli/analytics/reporter.go Co-authored-by: Pawel Kosiec <[email protected]> * Update internal/cli/analytics/reporter.go Co-authored-by: Pawel Kosiec <[email protected]> --------- Co-authored-by: Pawel Kosiec <[email protected]>
1 parent 8b040ad commit a331e14

26 files changed

+485
-13
lines changed

.github/workflows/release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ jobs:
7979
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
8080
IMAGE_TAG: ${{ github.ref_name }}
8181
ANALYTICS_API_KEY: ${{ secrets.ANALYTICS_API_KEY }}
82+
CLI_ANALYTICS_API_KEY: ${{ secrets.CLI_ANALYTICS_API_KEY }}
8283
run: |
8384
goreleaser release --clean --release-notes=CHANGELOG.md

.goreleaser.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ env:
55
- IMAGE_TAG={{ if index .Env "IMAGE_TAG" }}{{ .Env.IMAGE_TAG }}{{ else }}{{ .Tag }}{{ end }}
66
- CFG_EXPORTER_IMAGE_REPOSITORY={{ if index .Env "CFG_EXPORTER_IMAGE_REPOSITORY" }}{{ .Env.CFG_EXPORTER_IMAGE_REPOSITORY }}{{ else }}kubeshop/botkube-config-exporter{{ end }}
77
- ANALYTICS_API_KEY={{ if index .Env "ANALYTICS_API_KEY" }}{{ .Env.ANALYTICS_API_KEY }}{{ else }}{{ end }}
8+
- CLI_ANALYTICS_API_KEY={{ if index .Env "CLI_ANALYTICS_API_KEY" }}{{ .Env.CLI_ANALYTICS_API_KEY }}{{ else }}{{ end }}
89
- HOMEBREW_REPO_OWNER={{ if index .Env "HOMEBREW_REPO_OWNER" }}{{ .Env.HOMEBREW_REPO_OWNER }}{{ else }}kubeshop{{ end }}
910
- HOMEBREW_REPO_NAME={{ if index .Env "HOMEBREW_REPO_NAME" }}{{ .Env.HOMEBREW_REPO_NAME }}{{ else }}homebrew-botkube{{ end }}
1011
before:
@@ -36,10 +37,11 @@ builds:
3637
ldflags:
3738
- -s -w
3839
-X github.com/kubeshop/botkube/cmd/cli/cmd/migrate.DefaultImageTag={{ .Env.IMAGE_TAG }}
40+
-X github.com/kubeshop/botkube/internal/cli/analytics.APIKey={{ .Env.CLI_ANALYTICS_API_KEY }}
3941
-X go.szostok.io/version.version={{.Version}}
4042
-X go.szostok.io/version.buildDate={{.Date}}
41-
- -X go.szostok.io/version.commit={{.FullCommit}}
42-
- -X go.szostok.io/version.commitDate={{.CommitDate}}
43+
-X go.szostok.io/version.commit={{.FullCommit}}
44+
-X go.szostok.io/version.commitDate={{.CommitDate}}
4345
-X go.szostok.io/version.name=botkube
4446
env:
4547
- CGO_ENABLED=0

cmd/cli/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bctl migrate --namespace botkube --labels app=botkube
4040
We tried to make the migration process as simple and automated as possible.
4141
The login workflow involves a locally served http server that listens for a callback from the browser
4242
after the user login. The callback contains the access token that is used to authenticate the user
43-
and is stored locally in `~/.botkube/cloud.json`.
43+
and is stored locally in `~/.botkube/config.json`.
4444
The server is stopped after the callback is received.
4545

4646
### Migration

cmd/cli/cmd/config/get.go

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"gopkg.in/yaml.v3"
1010

1111
"github.com/kubeshop/botkube/internal/cli"
12+
"github.com/kubeshop/botkube/internal/cli/analytics"
1213
"github.com/kubeshop/botkube/internal/cli/config"
1314
"github.com/kubeshop/botkube/internal/cli/heredoc"
1415
"github.com/kubeshop/botkube/internal/cli/printer"
@@ -83,6 +84,8 @@ func NewGet() *cobra.Command {
8384
},
8485
}
8586

87+
cmd = analytics.InjectAnalyticsReporting(*cmd, "config get")
88+
8689
flags := cmd.Flags()
8790

8891
flags.BoolVar(&opts.OmitEmpty, "omit-empty-values", true, "Omits empty keys from printed configuration")

cmd/cli/cmd/install.go

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/spf13/cobra"
99

1010
"github.com/kubeshop/botkube/internal/cli"
11+
"github.com/kubeshop/botkube/internal/cli/analytics"
1112
"github.com/kubeshop/botkube/internal/cli/heredoc"
1213
"github.com/kubeshop/botkube/internal/cli/install"
1314
"github.com/kubeshop/botkube/internal/cli/install/helm"
@@ -42,6 +43,8 @@ func NewInstall() *cobra.Command {
4243
},
4344
}
4445

46+
installCmd = analytics.InjectAnalyticsReporting(*installCmd, "install")
47+
4548
flags := installCmd.Flags()
4649

4750
kubex.RegisterKubeconfigFlag(flags)

cmd/cli/cmd/login.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/spf13/cobra"
77

88
"github.com/kubeshop/botkube/internal/cli"
9+
"github.com/kubeshop/botkube/internal/cli/analytics"
910
"github.com/kubeshop/botkube/internal/cli/heredoc"
1011
"github.com/kubeshop/botkube/internal/cli/login"
1112
)
@@ -26,6 +27,8 @@ func NewLogin() *cobra.Command {
2627
},
2728
}
2829

30+
login = analytics.InjectAnalyticsReporting(*login, "login")
31+
2932
flags := login.Flags()
3033
flags.StringVar(&opts.CloudDashboardURL, "cloud-dashboard-url", "https://app.botkube.io", "Botkube Cloud URL")
3134
flags.StringVar(&opts.LocalServerAddress, "local-server-addr", "localhost:8085", "Address of a local server which is used for the login flow")

cmd/cli/cmd/migrate.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"go.szostok.io/version"
1313

1414
"github.com/kubeshop/botkube/internal/cli"
15+
"github.com/kubeshop/botkube/internal/cli/analytics"
1516
"github.com/kubeshop/botkube/internal/cli/config"
1617
"github.com/kubeshop/botkube/internal/cli/heredoc"
1718
"github.com/kubeshop/botkube/internal/cli/migrate"
@@ -27,7 +28,7 @@ const (
2728
func NewMigrate() *cobra.Command {
2829
var opts migrate.Options
2930

30-
login := &cobra.Command{
31+
migrate := &cobra.Command{
3132
Use: "migrate [OPTIONS]",
3233
Short: "Automatically migrates Botkube installation into Botkube Cloud",
3334
Long: heredoc.WithCLIName(`
@@ -129,7 +130,9 @@ func NewMigrate() *cobra.Command {
129130
},
130131
}
131132

132-
flags := login.Flags()
133+
migrate = analytics.InjectAnalyticsReporting(*migrate, "migrate")
134+
135+
flags := migrate.Flags()
133136

134137
flags.DurationVar(&opts.Timeout, "timeout", 10*time.Minute, `Maximum time during which the Botkube installation is being watched, where "0" means "infinite". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".`)
135138
flags.StringVar(&opts.Token, "token", "", "Botkube Cloud authentication token")
@@ -145,5 +148,5 @@ func NewMigrate() *cobra.Command {
145148
opts.ConfigExporter.RegisterFlags(flags)
146149
kubex.RegisterKubeconfigFlag(flags)
147150

148-
return login
151+
return migrate
149152
}

cmd/cli/cmd/root.go

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"go.szostok.io/version/extension"
66

77
"github.com/kubeshop/botkube/cmd/cli/cmd/config"
8+
"github.com/kubeshop/botkube/cmd/cli/cmd/telemetry"
89
"github.com/kubeshop/botkube/internal/cli"
910
"github.com/kubeshop/botkube/internal/cli/heredoc"
1011
)
@@ -49,6 +50,7 @@ func NewRoot() *cobra.Command {
4950
NewInstall(),
5051
NewUninstall(),
5152
config.NewCmd(),
53+
telemetry.NewCmd(),
5254
extension.NewVersionCobraCmd(
5355
extension.WithUpgradeNotice(orgName, repoName),
5456
),

cmd/cli/cmd/telemetry/disable.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package telemetry
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/kubeshop/botkube/internal/cli"
7+
"github.com/kubeshop/botkube/internal/cli/heredoc"
8+
)
9+
10+
// NewEnable returns a new cobra.Command for disabling telemetry.
11+
func NewDisable() *cobra.Command {
12+
enable := &cobra.Command{
13+
Use: "disable",
14+
Short: "Disable Botkube telemetry",
15+
Example: heredoc.WithCLIName(`
16+
# To improve the user experience, Botkube collects anonymized data.
17+
# It does not collect any identifying information, and all analytics
18+
# are used only as aggregated collection of data to improve Botkube
19+
# and adjust its roadmap.
20+
# Read our privacy policy at https://docs.botkube.io/privacy
21+
22+
# The Botkube CLI tool collects anonymous usage analytics.
23+
# This data is only available to the Botkube authors and helps us improve the tool.
24+
25+
# Disable Botkube telemetry
26+
<cli> telemetry disable
27+
28+
29+
`, cli.Name),
30+
RunE: func(cmd *cobra.Command, args []string) (err error) {
31+
config := cli.NewConfig()
32+
config.Telemetry = cli.TelemetryDisabled
33+
err = config.Save()
34+
if err != nil {
35+
return err
36+
}
37+
cmd.Println("Telemetry disabled")
38+
return nil
39+
},
40+
}
41+
42+
return enable
43+
}

cmd/cli/cmd/telemetry/enable.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package telemetry
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/kubeshop/botkube/internal/cli"
7+
"github.com/kubeshop/botkube/internal/cli/heredoc"
8+
)
9+
10+
// NewEnable returns a new cobra.Command for enabling telemetry.
11+
func NewEnable() *cobra.Command {
12+
enable := &cobra.Command{
13+
Use: "enable",
14+
Short: "Enable Botkube telemetry",
15+
Example: heredoc.WithCLIName(`
16+
# To improve the user experience, Botkube collects anonymized data.
17+
# It does not collect any identifying information, and all analytics
18+
# are used only as aggregated collection of data to improve Botkube
19+
# and adjust its roadmap.
20+
# Read our privacy policy at https://docs.botkube.io/privacy
21+
22+
# Enable Botkube telemetry
23+
<cli> telemetry enable
24+
25+
26+
`, cli.Name),
27+
RunE: func(cmd *cobra.Command, args []string) (err error) {
28+
config := cli.NewConfig()
29+
config.Telemetry = cli.TelemetryEnabled
30+
err = config.Save()
31+
if err != nil {
32+
return err
33+
}
34+
cmd.Println("Telemetry enabled")
35+
return nil
36+
},
37+
}
38+
39+
return enable
40+
}

cmd/cli/cmd/telemetry/telemetry.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package telemetry
2+
3+
import "github.com/spf13/cobra"
4+
5+
// NewCmd returns a new cobra.Command subcommand for telemetry-related operations.
6+
func NewCmd() *cobra.Command {
7+
root := &cobra.Command{
8+
Use: "telemetry",
9+
Short: "Configure collection of anonymous analytics",
10+
}
11+
12+
root.AddCommand(
13+
NewEnable(),
14+
NewDisable(),
15+
)
16+
return root
17+
}

cmd/cli/cmd/uninstall.go

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/spf13/cobra"
99

1010
"github.com/kubeshop/botkube/internal/cli"
11+
"github.com/kubeshop/botkube/internal/cli/analytics"
1112
"github.com/kubeshop/botkube/internal/cli/heredoc"
1213
"github.com/kubeshop/botkube/internal/cli/install/helm"
1314
"github.com/kubeshop/botkube/internal/cli/uninstall"
@@ -42,6 +43,8 @@ func NewUninstall() *cobra.Command {
4243
},
4344
}
4445

46+
uninstallCmd = analytics.InjectAnalyticsReporting(*uninstallCmd, "uninstall")
47+
4548
flags := uninstallCmd.Flags()
4649

4750
kubex.RegisterKubeconfigFlag(flags)

cmd/cli/docs/botkube.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ botkube [flags]
4040
* [botkube install](botkube_install.md) - install or upgrade Botkube in k8s cluster
4141
* [botkube login](botkube_login.md) - Login to a Botkube Cloud
4242
* [botkube migrate](botkube_migrate.md) - Automatically migrates Botkube installation into Botkube Cloud
43+
* [botkube telemetry](botkube_telemetry.md) - Configure collection of anonymous analytics
4344
* [botkube uninstall](botkube_uninstall.md) - uninstall Botkube from cluster
4445
* [botkube version](botkube_version.md) - Print the CLI version
4546

cmd/cli/docs/botkube_telemetry.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: botkube telemetry
3+
---
4+
5+
## botkube telemetry
6+
7+
Configure collection of anonymous analytics
8+
9+
### Options
10+
11+
```
12+
-h, --help help for telemetry
13+
```
14+
15+
### Options inherited from parent commands
16+
17+
```
18+
-v, --verbose int/string[=simple] Prints more verbose output. Allowed values: 0 - disable, 1 - simple, 2 - trace (default 0 - disable)
19+
```
20+
21+
### SEE ALSO
22+
23+
* [botkube](botkube.md) - Botkube CLI
24+
* [botkube telemetry disable](botkube_telemetry_disable.md) - Disable Botkube telemetry
25+
* [botkube telemetry enable](botkube_telemetry_enable.md) - Enable Botkube telemetry
26+
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: botkube telemetry disable
3+
---
4+
5+
## botkube telemetry disable
6+
7+
Disable Botkube telemetry
8+
9+
```
10+
botkube telemetry disable [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
# To improve the user experience, Botkube collects anonymized data.
17+
# It does not collect any identifying information, and all analytics
18+
# are used only as aggregated collection of data to improve Botkube
19+
# and adjust its roadmap.
20+
# Read our privacy policy at https://docs.botkube.io/privacy
21+
22+
# The Botkube CLI tool collects anonymous usage analytics.
23+
# This data is only available to the Botkube authors and helps us improve the tool.
24+
25+
# Disable Botkube telemetry
26+
botkube telemetry disable
27+
28+
29+
30+
```
31+
32+
### Options
33+
34+
```
35+
-h, --help help for disable
36+
```
37+
38+
### Options inherited from parent commands
39+
40+
```
41+
-v, --verbose int/string[=simple] Prints more verbose output. Allowed values: 0 - disable, 1 - simple, 2 - trace (default 0 - disable)
42+
```
43+
44+
### SEE ALSO
45+
46+
* [botkube telemetry](botkube_telemetry.md) - Configure collection of anonymous analytics
47+
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: botkube telemetry enable
3+
---
4+
5+
## botkube telemetry enable
6+
7+
Enable Botkube telemetry
8+
9+
```
10+
botkube telemetry enable [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
# To improve the user experience, Botkube collects anonymized data.
17+
# It does not collect any identifying information, and all analytics
18+
# are used only as aggregated collection of data to improve Botkube
19+
# and adjust its roadmap.
20+
# Read our privacy policy at https://docs.botkube.io/privacy
21+
22+
# Enable Botkube telemetry
23+
botkube telemetry enable
24+
25+
26+
27+
```
28+
29+
### Options
30+
31+
```
32+
-h, --help help for enable
33+
```
34+
35+
### Options inherited from parent commands
36+
37+
```
38+
-v, --verbose int/string[=simple] Prints more verbose output. Allowed values: 0 - disable, 1 - simple, 2 - trace (default 0 - disable)
39+
```
40+
41+
### SEE ALSO
42+
43+
* [botkube telemetry](botkube_telemetry.md) - Configure collection of anonymous analytics
44+

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/briandowns/spinner v1.23.0
1818
github.com/bwmarrin/discordgo v0.25.0
1919
github.com/charmbracelet/log v0.2.2
20+
github.com/denisbrodbeck/machineid v1.0.1
2021
github.com/dustin/go-humanize v1.0.1
2122
github.com/fatih/color v1.15.0
2223
github.com/fluxcd/kustomize-controller/api v1.0.1

0 commit comments

Comments
 (0)