Skip to content
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
16 changes: 11 additions & 5 deletions internal/core/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type BootstrapConfig struct {
// If provided this client will be passed to all commands.
// If not a client will be automatically created by the CLI using Config, Env and flags see createClient().
Client *scw.Client

// DisableTelemetry, if set to true this will disable telemetry report no matter what the config send_telemetry is set to.
// This is useful when running test to avoid sending meaningless telemetries.
DisableTelemetry bool
}

// Bootstrap is the main entry point. It is directly called from main.
Expand Down Expand Up @@ -62,12 +66,14 @@ func Bootstrap(config *BootstrapConfig) (exitCode int, result interface{}, err e
start := time.Now()
defer func() {
// skip telemetry report when at least one of the following criteria matches:
// - version is not a release
// - telemetry is disabled on the current command
// - telemetry is explicitly disable in bootstrap config
// - no command was executed
// - telemetry is disabled on the ran command
// - telemetry is disabled from the config (user must consent)
if (!matomo.ForceTelemetry && !config.BuildInfo.IsRelease()) ||
(meta.command == nil || meta.command.DisableTelemetry) ||
!matomo.IsTelemetryEnabled() {
if config.DisableTelemetry ||
meta.command == nil ||
meta.command.DisableTelemetry ||
matomo.IsTelemetryDisabled() {
logger.Debugf("skipping telemetry report")
return
}
Expand Down
26 changes: 14 additions & 12 deletions internal/core/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,13 @@ func Test(config *TestConfig) func(t *testing.T) {
stderrBuffer := &bytes.Buffer{}
logger.Debugf("command: %s", cmdTemplate(cmd))
_, result, err := Bootstrap(&BootstrapConfig{
Args: strings.Split(cmdTemplate(cmd), " "),
Commands: config.Commands,
BuildInfo: &config.BuildInfo,
Stdout: stdoutBuffer,
Stderr: stderrBuffer,
Client: client,
Args: strings.Split(cmdTemplate(cmd), " "),
Commands: config.Commands,
BuildInfo: &config.BuildInfo,
Stdout: stdoutBuffer,
Stderr: stderrBuffer,
Client: client,
DisableTelemetry: true,
})
require.NoError(t, err, "stdout: %s\nstderr: %s", stdoutBuffer.String(), stderrBuffer.String())

Expand All @@ -200,12 +201,13 @@ func Test(config *TestConfig) func(t *testing.T) {
stderr := &bytes.Buffer{}
logger.Debugf("command: %s", cmdTemplate(config.Cmd))
exitCode, result, err = Bootstrap(&BootstrapConfig{
Args: strings.Split(cmdTemplate(config.Cmd), " "),
Commands: config.Commands,
BuildInfo: &config.BuildInfo,
Stdout: stdout,
Stderr: stderr,
Client: client,
Args: strings.Split(cmdTemplate(config.Cmd), " "),
Commands: config.Commands,
BuildInfo: &config.BuildInfo,
Stdout: stdout,
Stderr: stderr,
Client: client,
DisableTelemetry: true,
})

config.Check(t, &CheckFuncCtx{
Expand Down
6 changes: 3 additions & 3 deletions internal/matomo/matomo.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ func generateRandNumber() string {
return bigRand.String()
}

// IsTelemetryEnabled returns true when the Opt-In send_telemetry attribute in the config is set.
func IsTelemetryEnabled() bool {
// IsTelemetryDisabled returns true when the Opt-In send_telemetry attribute in the config is set.
func IsTelemetryDisabled() bool {
config, err := scw.LoadConfig()
if err != nil {
return false
}
return config.SendUsage
return !config.SendUsage
}