Skip to content

Commit

Permalink
Do not send userId to registry when ODO_DEBUG_TELEMETRY_FILE is set (#…
Browse files Browse the repository at this point in the history
…6031)

* Do not send userId to registry when ODO_DEBUG_TELEMETRY_FILE is set

* Unit tests
  • Loading branch information
feloy authored Aug 23, 2022
1 parent 83ad3ee commit eb3320b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
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() != "" {
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 @@ -20,18 +20,31 @@ func TestGetRegistryOptions(t *testing.T) {
t.Setenv(preference.GlobalConfigEnvName, tempConfigFile.Name())

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 @@ -46,25 +59,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

0 comments on commit eb3320b

Please sign in to comment.