Skip to content

Commit

Permalink
telemetry: add config properties network mode, proxy, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumerose committed Feb 1, 2021
1 parent 8e2d1be commit 074faf7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 13 additions & 1 deletion pkg/crc/segment/segment.go
Expand Up @@ -68,7 +68,7 @@ func (c *Client) Upload(ctx context.Context, action string, duration time.Durati

if err := c.segmentClient.Enqueue(analytics.Identify{
AnonymousId: anonymousID,
Traits: traits(),
Traits: addConfigTraits(c.config, traits()),
}); err != nil {
return err
}
Expand All @@ -92,6 +92,18 @@ func (c *Client) Upload(ctx context.Context, action string, duration time.Durati
})
}

func addConfigTraits(c *crcConfig.Config, in analytics.Traits) analytics.Traits {
return in.
Set("proxy", isProxyUsed(c)).
Set(config.NetworkMode, c.Get(config.NetworkMode).AsString()).
Set(config.EnableClusterMonitoring, c.Get(config.EnableClusterMonitoring).AsBool()).
Set(config.ExperimentalFeatures, c.Get(config.ExperimentalFeatures).AsBool())
}

func isProxyUsed(c *crcConfig.Config) bool {
return c.Get(config.HTTPProxy).AsString() != "" || c.Get(config.HTTPSProxy).AsString() != ""
}

func getUserIdentity(telemetryFilePath string) (string, error) {
var id []byte
if err := os.MkdirAll(filepath.Dir(telemetryFilePath), 0750); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion pkg/crc/segment/segment_test.go
Expand Up @@ -26,7 +26,8 @@ type segmentResponse struct {
AnonymousID string `json:"anonymousId"`
MessageID string `json:"messageId"`
Traits struct {
OS string `json:"os"`
OS string `json:"os"`
ExperimentalFeatures bool `json:"enable-experimental-features"`
} `json:"traits"`
Properties struct {
Error string `json:"error"`
Expand Down Expand Up @@ -62,6 +63,9 @@ func newTestConfig(value string) (*crcConfig.Config, error) {
if _, err := config.Set(cmdConfig.ConsentTelemetry, value); err != nil {
return nil, err
}
if _, err := config.Set(cmdConfig.ExperimentalFeatures, true); err != nil {
return nil, err
}
return config, nil
}

Expand Down Expand Up @@ -89,6 +93,7 @@ func TestClientUploadWithConsent(t *testing.T) {
require.NoError(t, json.Unmarshal(x, &s))
require.Equal(t, s.Batch[0].Type, "identify")
require.Equal(t, s.Batch[0].Traits.OS, runtime.GOOS)
require.Equal(t, s.Batch[0].Traits.ExperimentalFeatures, true)
require.Equal(t, s.Batch[1].Type, "track")
require.Equal(t, s.Batch[1].Properties.Error, "an error occurred")
require.Equal(t, s.Batch[1].Properties.Version, version.GetCRCVersion())
Expand Down

0 comments on commit 074faf7

Please sign in to comment.