Skip to content

Commit

Permalink
Make ODO_TRACKING_CONSENT env var take precedence over the ConsentTel…
Browse files Browse the repository at this point in the history
  • Loading branch information
rm3l committed Oct 27, 2022
1 parent e34d0cc commit cfc6464
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/segment/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,18 @@ func IsTelemetryEnabled(cfg preference.Client) bool {
klog.V(4).Info("Sending telemetry disabled by env variable\n")
return false
}

if trackingConsent == "yes" {
klog.V(4).Info("Sending telemetry enabled by env variable\n")
return true
}

isEnabled := cfg.GetConsentTelemetry()
s := "Telemetry is disabled"
s := "Sending telemetry disabled by preference"
if isEnabled {
s = "Telemetry is disabled"
s = "Sending telemetry enabled by preference"
}
klog.V(4).Infof("%s!\n", s)
klog.V(4).Infof("%s\n", s)
return isEnabled
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/segment/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ func TestIsTelemetryEnabled(t *testing.T) {
if odoDisableTelemetry == "true" || odoTrackingConsent == "no" {
return false
}
if odoTrackingConsent == "yes" {
return true
}
return consentTelemetry
},
name: fmt.Sprintf("ODO_DISABLE_TELEMETRY=%q,ODO_TRACKING_CONSENT=%q,ConsentTelemetry=%v",
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/cmd_devfile_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"

"github.com/redhat-developer/odo/pkg/odo/cli/messages"
"github.com/redhat-developer/odo/pkg/preference"
"github.com/redhat-developer/odo/pkg/segment"
segmentContext "github.com/redhat-developer/odo/pkg/segment/context"

Expand Down Expand Up @@ -402,6 +403,7 @@ var _ = Describe("odo devfile init command tests", func() {
type telemetryTest struct {
title string
env map[string]string
setupFunc func(cfg preference.Client)
callerChecker func(stdout, stderr string, data segment.TelemetryData)
}
allowedTelemetryCallers := []string{segmentContext.VSCode, segmentContext.IntelliJ, segmentContext.JBoss}
Expand Down Expand Up @@ -441,6 +443,19 @@ var _ = Describe("odo devfile init command tests", func() {
})
},
},
{
title: "ODO_TRACKING_CONSENT=yes env var should take precedence over ConsentTelemetry preference",
env: map[string]string{segment.TrackingConsentEnv: "yes"},
callerChecker: func(_, _ string, td segment.TelemetryData) {
cmdProperties := td.Properties.CmdProperties
Expect(cmdProperties).Should(HaveKey(segmentContext.Caller))
Expect(cmdProperties[segmentContext.Caller]).To(BeEmpty())
},
setupFunc: func(cfg preference.Client) {
err := cfg.SetConfiguration(preference.ConsentTelemetrySetting, "false")
Expect(err).ShouldNot(HaveOccurred())
},
},
}
for _, c := range allowedTelemetryCallers {
c := c
Expand All @@ -461,6 +476,13 @@ var _ = Describe("odo devfile init command tests", func() {
var stderr string
BeforeEach(func() {
helper.EnableTelemetryDebug()

cfg, err := preference.NewClient()
Expect(err).ShouldNot(HaveOccurred())
if tt.setupFunc != nil {
tt.setupFunc(cfg)
}

cmd := helper.Cmd("odo", "init", "--name", "aname", "--devfile", "go")
for k, v := range tt.env {
cmd = cmd.AddEnv(fmt.Sprintf("%s=%s", k, v))
Expand Down

0 comments on commit cfc6464

Please sign in to comment.