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

Do not send userId to registry when ODO_DEBUG_TELEMETRY_FILE is set #6031

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
4 changes: 4 additions & 0 deletions pkg/segment/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func getTelemetryForDevfileRegistry() (registryLibrary.TelemetryData, error) {
Client: TelemetryClient,
}

if GetDebugTelemetryFile() != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a unit test for this well which might need enhancing, can you check?

return td, nil
}

// TODO(feloy) Get from DI
cfg, err := preference.NewClient()
if err != nil {
Expand Down
41 changes: 29 additions & 12 deletions pkg/segment/integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,31 @@ func TestGetRegistryOptions(t *testing.T) {
}

tests := []struct {
testName string
consent string
cfg preference.Client
testName string
consent string
telemetryFile bool
cfg preference.Client
}{
{
testName: "Registry options with telemetry consent",
consent: "true",
testName: "Registry options with telemetry consent and telemetry file",
consent: "true",
telemetryFile: true,
},
{
testName: "Registry options with telemetry consent and no telemetry file",
consent: "true",
telemetryFile: false,
},

{
testName: "Registry options without telemetry consent",
consent: "false",
testName: "Registry options without telemetry consent and telemetry file",
consent: "false",
telemetryFile: true,
},
{
testName: "Registry options without telemetry consent and no telemetry file",
consent: "false",
telemetryFile: false,
},
}

Expand All @@ -51,25 +64,29 @@ func TestGetRegistryOptions(t *testing.T) {
t.Error(err)
}

if tt.telemetryFile {
t.Setenv(DebugTelemetryFileEnv, "/a/telemetry/file")
}

ro := GetRegistryOptions()
err = verifyRegistryOptions(cfg.GetConsentTelemetry(), ro)
err = verifyRegistryOptions(cfg.GetConsentTelemetry(), tt.telemetryFile, ro)
if err != nil {
t.Error(err)
}
})
}
}

func verifyRegistryOptions(isSet bool, ro library.RegistryOptions) error {
func verifyRegistryOptions(isSet bool, telemetryFile bool, ro library.RegistryOptions) error {
if ro.SkipTLSVerify {
return errors.New("SkipTLSVerify should be set to false by default")
}

return verifyTelemetryData(isSet, ro.Telemetry)
return verifyTelemetryData(isSet, telemetryFile, ro.Telemetry)
}

func verifyTelemetryData(isSet bool, data library.TelemetryData) error {
if !isSet {
func verifyTelemetryData(isSet bool, telemetryFile bool, data library.TelemetryData) error {
if !isSet || telemetryFile {
if data.Locale == "" && data.User == "" {
return nil
}
Expand Down