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

fix(cli): remove cli analytics #2716

Merged
merged 4 commits into from
Jun 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version-file: 'go.work'
go-version-file: "go.work"
cache: true
cache-dependency-path: go.work
- name: install graph tool
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version-file: 'go.work'
go-version-file: "go.work"
cache: true
cache-dependency-path: go.work
- name: Run unit tests
Expand All @@ -75,7 +75,7 @@ jobs:
name: API Server unit tests
runs-on: ubuntu-latest

# git log --pretty=tformat:"%H" -n1 web
# git log --pretty=tformat:"%H" -n1 web
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -84,7 +84,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version-file: 'go.work'
go-version-file: "go.work"
cache: true
cache-dependency-path: go.work
- name: Run unit tests
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
if: steps.cache-docker-build.outputs.cache-hit != 'true'
uses: actions/setup-go@v3
with:
go-version-file: 'go.work'
go-version-file: "go.work"
cache: true
cache-dependency-path: go.work
- uses: goreleaser/goreleaser-action@v4
Expand All @@ -208,7 +208,7 @@ jobs:

test-examples:
name: Test examples
needs: [build-docker]
needs: [build-docker]
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -242,12 +242,12 @@ jobs:

./scripts/wait-for-port.sh 11633

./dist/tracetest configure -g --endpoint http://localhost:11633 --analytics=false
./dist/tracetest configure -g --endpoint http://localhost:11633
./dist/tracetest test run -d examples/${{ matrix.example_dir }}/tests/list-tests.yaml --wait-for-result || (cat /tmp/docker-log; exit 1)

smoke-test-cli:
name: CLI smoke tests
needs: [build-docker]
needs: [build-docker]
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -314,7 +314,7 @@ jobs:

e2e-cli:
name: CLI e2e tests
needs: [build-docker]
needs: [build-docker]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
16 changes: 3 additions & 13 deletions cli/actions/configure_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ type ConfigureConfig struct {
}

type ConfigureConfigSetValues struct {
Endpoint *string
AnalyticsEnabled *bool
Endpoint *string
}

type configureAction struct {
Expand Down Expand Up @@ -55,23 +54,14 @@ func (a configureAction) Run(ctx context.Context, args ConfigureConfig) error {
return err
}

var analyticsEnabled bool

if args.SetValues.AnalyticsEnabled != nil {
analyticsEnabled = *args.SetValues.AnalyticsEnabled
} else {
analyticsEnabled = ui.Confirm("Enable analytics?", true)
}

scheme, endpoint, err := config.ParseServerURL(serverURL)
if err != nil {
return err
}

config := config.Config{
Scheme: scheme,
Endpoint: endpoint,
AnalyticsEnabled: analyticsEnabled,
Scheme: scheme,
Endpoint: endpoint,
}

err = a.saveConfiguration(ctx, config, args)
Expand Down
70 changes: 2 additions & 68 deletions cli/analytics/analytics.go
Original file line number Diff line number Diff line change
@@ -1,88 +1,22 @@
package analytics

import (
"os"

"github.com/denisbrodbeck/machineid"
"github.com/kubeshop/tracetest/cli/config"
segment "github.com/segmentio/analytics-go/v3"
)

var (
SecretKey = ""
client segment.Client
mid string
mid string
)

func ClientID() string {
return mid
}

func Init(conf config.Config) {
if !conf.AnalyticsEnabled || os.Getenv("TRACETEST_DEV") != "" {
// non-empty TRACETEST_DEV variable means it's running by a dev,
// and we should totally ignore analytics
return
}

client, _ = segment.NewWithConfig(SecretKey, segment.Config{
BatchSize: 1,
})

func Init() {
id, err := machineid.ProtectedID("tracetest")
if err == nil {
// only use id if available.
mid = id
} // ignore errors and continue with an empty ID if necessary

client.Enqueue(segment.Identify{
UserId: mid,
Traits: segment.NewTraits().
Set("source", "cli").
Set("clientID", mid).
Set("env", config.Env).
Set("appVersion", config.Version),
Context: &segment.Context{
Direct: true,
},
})
}

func Track(name, category string, props map[string]string) error {
if client == nil {
return nil
}

p := segment.NewProperties().
Set("source", "cli").
Set("clientID", mid).
Set("env", config.Env).
Set("appVersion", config.Version).
Set("category", category)

for k, v := range props {
p = p.Set(k, v)
}

err := client.Enqueue(segment.Track{
Event: name,
UserId: mid,
Properties: p,
Context: &segment.Context{
Direct: true,
},
})

return err
}

func Close() {
if client == nil {
return
}

err := client.Close()
if err != nil {
panic(err)
}
}
5 changes: 0 additions & 5 deletions cli/cmd/apply_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/kubeshop/tracetest/cli/actions"
"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/formatters"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/spf13/cobra"
Expand All @@ -24,10 +23,6 @@ var applyCmd = &cobra.Command{
resourceType := args[0]
ctx := context.Background()

analytics.Track("Resource Apply", "cmd", map[string]string{
resourceType: resourceType,
})

resourceActions, err := resourceRegistry.Get(resourceType)

if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cli/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func setupCommand(options ...setupOption) func(cmd *cobra.Command, args []string
validateVersionMismatch()
}

analytics.Init(cliConfig)
analytics.Init()
}
}

Expand Down Expand Up @@ -201,7 +201,6 @@ func setupLogger(cmd *cobra.Command, args []string) {

func teardownCommand(cmd *cobra.Command, args []string) {
cliLogger.Sync()
analytics.Close()
}

func setupVersion() {
Expand Down
8 changes: 0 additions & 8 deletions cli/cmd/configure_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"github.com/kubeshop/tracetest/cli/actions"
"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/kubeshop/tracetest/cli/utils"
"github.com/spf13/cobra"
Expand All @@ -19,8 +18,6 @@ var configureCmd = &cobra.Command{
Long: "Configure your tracetest CLI",
PreRun: setupLogger,
Run: WithResultHandler(WithParamsHandler(configParams)(func(cmd *cobra.Command, _ []string) (string, error) {
analytics.Track("Configure", "cmd", map[string]string{})

ctx := context.Background()
client := utils.GetAPIClient(cliConfig)
action := actions.NewConfigureAction(cliConfig, cliLogger, client)
Expand All @@ -34,10 +31,6 @@ var configureCmd = &cobra.Command{
actionConfig.SetValues.Endpoint = &configParams.Endpoint
}

if flagProvided(cmd, "analytics") {
actionConfig.SetValues.AnalyticsEnabled = &configParams.AnalyticsEnabled
}

err := action.Run(ctx, actionConfig)
return "", err
})),
Expand All @@ -51,6 +44,5 @@ func flagProvided(cmd *cobra.Command, name string) bool {
func init() {
configureCmd.PersistentFlags().BoolVarP(&configParams.Global, "global", "g", false, "configuration will be saved in your home dir")
configureCmd.PersistentFlags().StringVarP(&configParams.Endpoint, "endpoint", "e", "", "set the value for the endpoint, so the CLI won't ask for this value")
configureCmd.PersistentFlags().BoolVarP(&configParams.AnalyticsEnabled, "analytics", "a", true, "configure the analytic state, so the CLI won't ask for this value")
rootCmd.AddCommand(configureCmd)
}
3 changes: 0 additions & 3 deletions cli/cmd/dashboard_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"

"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/utils"
"github.com/spf13/cobra"
)
Expand All @@ -15,8 +14,6 @@ var dashboardCmd = &cobra.Command{
Long: "Opens the Tracetest Dashboard URL",
PreRun: setupCommand(),
Run: WithResultHandler(func(_ *cobra.Command, _ []string) (string, error) {
analytics.Track("Dashboard", "cmd", map[string]string{})

if cliConfig.IsEmpty() {
return "", fmt.Errorf("missing Tracetest endpoint configuration")
}
Expand Down
5 changes: 0 additions & 5 deletions cli/cmd/delete_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"strings"

"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/spf13/cobra"
)
Expand All @@ -22,10 +21,6 @@ var deleteCmd = &cobra.Command{
resourceType := args[0]
ctx := context.Background()

analytics.Track("Resource Delete", "cmd", map[string]string{
resourceType: resourceType,
})

resourceActions, err := resourceRegistry.Get(resourceType)
if err != nil {
return "", err
Expand Down
5 changes: 0 additions & 5 deletions cli/cmd/export_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"strings"

"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/spf13/cobra"
)
Expand All @@ -25,10 +24,6 @@ var exportCmd = &cobra.Command{
resourceType := args[0]
ctx := context.Background()

analytics.Track("Resource Export", "cmd", map[string]string{
resourceType: resourceType,
})

resourceActions, err := resourceRegistry.Get(resourceType)
if err != nil {
return "", err
Expand Down
5 changes: 0 additions & 5 deletions cli/cmd/get_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"strings"

"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/formatters"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/kubeshop/tracetest/cli/utils"
Expand All @@ -25,10 +24,6 @@ var getCmd = &cobra.Command{
resourceType := args[0]
ctx := context.Background()

analytics.Track("Resource Get", "cmd", map[string]string{
resourceType: resourceType,
})

resourceActions, err := resourceRegistry.Get(resourceType)
if err != nil {
return "", err
Expand Down
5 changes: 0 additions & 5 deletions cli/cmd/list_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"strings"

"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/formatters"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/kubeshop/tracetest/cli/utils"
Expand All @@ -24,10 +23,6 @@ var listCmd = &cobra.Command{
resourceType := args[0]
ctx := context.Background()

analytics.Track("Resource List", "cmd", map[string]string{
resourceType: resourceType,
})

resourceActions, err := resourceRegistry.Get(resourceType)
if err != nil {
return "", err
Expand Down
2 changes: 0 additions & 2 deletions cli/cmd/server_install_cmd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/installer"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/spf13/cobra"
Expand All @@ -25,7 +24,6 @@ var serverInstallCmd = &cobra.Command{
installer.InstallationMode = installerParams.InstallationMode
installer.KubernetesContext = installerParams.KubernetesContext

analytics.Track("Server Install", "cmd", map[string]string{})
installer.Start()
},
PostRun: teardownCommand,
Expand Down