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

Clean up analytics leftovers #938

Merged
merged 3 commits into from
Apr 11, 2024
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
14 changes: 0 additions & 14 deletions analytics/state_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ import (
)

const (
// DisabledEnvKey controls both the old (analytics plugin) and new (v2) implementations
DisabledEnvKey = "BITRISE_ANALYTICS_DISABLED"
// V2DisabledEnvKey controls only the new (v2) implementation
V2DisabledEnvKey = "BITRISE_ANALYTICS_V2_DISABLED"
// V2AsyncDisabledEnvKey can be used to disable the default async queries
V2AsyncDisabledEnvKey = "BITRISE_ANALYTICS_V2_ASYNC_DISABLED"

trueEnv = "true"
)

type StateChecker interface {
Enabled() bool
UseAsync() bool
}

type stateChecker struct {
Expand All @@ -29,13 +23,5 @@ func NewStateChecker(repository env.Repository) StateChecker {
}

func (s stateChecker) Enabled() bool {
if s.envRepository.Get(V2DisabledEnvKey) == trueEnv {
return false
}

return s.envRepository.Get(DisabledEnvKey) != trueEnv
}

func (s stateChecker) UseAsync() bool {
return s.envRepository.Get(V2AsyncDisabledEnvKey) != trueEnv
}
8 changes: 5 additions & 3 deletions analytics/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type Tracker interface {
SendStepFinishedEvent(properties analytics.Properties, result StepResult)
SendCLIWarning(message string)
SendToolVersionSnapshot(toolVersions, snapshotType string)
IsTracking() bool
Wait()
}

Expand All @@ -128,9 +129,6 @@ func NewDefaultTracker() Tracker {

logger := log.NewUtilsLogAdapter()
tracker := analytics.NewDefaultTracker(&logger)
if stateChecker.UseAsync() {
tracker = analytics.NewDefaultTracker(&logger)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


return NewTracker(tracker, envRepository, stateChecker, &logger)
}
Expand Down Expand Up @@ -278,6 +276,10 @@ func (t tracker) Wait() {
t.tracker.Wait()
}

func (t tracker) IsTracking() bool {
return t.stateChecker.Enabled()
}

func prepareStartProperties(info StepInfo) analytics.Properties {
properties := analytics.Properties{}
properties.AppendIfNotEmpty(stepIDProperty, info.StepID)
Expand Down
8 changes: 8 additions & 0 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ func (r WorkflowRunner) runWorkflows(tracker analytics.Tracker) (models.BuildRun

log.PrintBitriseStartedEvent(plan)

if tracker.IsTracking() {
log.Print()
log.Print("Bitrise collects anonymous usage stats to improve the product, detect and respond to Step error conditions.")
env := fmt.Sprintf("%s=%s", analytics.DisabledEnvKey, "true")
log.Printf("If you want to opt out, define the env var %s", colorstring.Cyan(env))
log.Print()
}

// Run workflows
for i, workflowRunPlan := range plan.ExecutionPlan {
isLastWorkflow := i == len(plan.ExecutionPlan)-1
Expand Down
1 change: 1 addition & 0 deletions cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1732,3 +1732,4 @@ func (n noOpTracker) SendWorkflowStarted(analytics.Properties, string, string)
func (n noOpTracker) SendWorkflowFinished(analytics.Properties, bool) {}
func (n noOpTracker) SendToolVersionSnapshot(string, string) {}
func (n noOpTracker) Wait() {}
func (n noOpTracker) IsTracking() bool { return false }