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

fix: Disable telemetry in CI #1116

Merged
merged 1 commit into from
Oct 31, 2022
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
12 changes: 12 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
skip-pkg-cache: true
test:
name: test
env:
# Disable telemetry.
ENVD_ANALYTICS: false
strategy:
matrix:
os: [ubuntu-latest]
Expand Down Expand Up @@ -84,6 +87,9 @@ jobs:
path: coverage.out
e2e-cli:
name: e2e-cli
env:
# Disable telemetry.
ENVD_ANALYTICS: false
strategy:
matrix:
os: [ubuntu-latest]
Expand Down Expand Up @@ -117,6 +123,9 @@ jobs:
path: e2e-cli-coverage.out
e2e-lang:
name: e2e-lang
env:
# Disable telemetry.
ENVD_ANALYTICS: false
strategy:
matrix:
os: [ubuntu-latest]
Expand Down Expand Up @@ -150,6 +159,9 @@ jobs:
path: e2e-lang-coverage.out
build:
name: build
env:
# Disable telemetry.
ENVD_ANALYTICS: false
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
skip-pkg-cache: true
test:
name: test
env:
# Disable telemetry.
ENVD_ANALYTICS: false
strategy:
matrix:
os: [ ubuntu-latest ]
Expand Down Expand Up @@ -74,6 +77,9 @@ jobs:
path: coverage.out
e2e-cli:
name: e2e-cli
env:
# Disable telemetry.
ENVD_ANALYTICS: false
strategy:
matrix:
os: [ ubuntu-latest ]
Expand Down Expand Up @@ -107,6 +113,9 @@ jobs:
path: e2e-cli-coverage.out
e2e-lang:
name: e2e-lang
env:
# Disable telemetry.
ENVD_ANALYTICS: false
strategy:
matrix:
os: [ ubuntu-latest ]
Expand Down Expand Up @@ -203,6 +212,9 @@ jobs:
run: make
e2e-doc:
name: e2e-doc
env:
# Disable telemetry.
ENVD_ANALYTICS: false
strategy:
matrix:
os: [ubuntu-latest]
Expand Down
7 changes: 3 additions & 4 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@ func New() EnvdApp {
}

analytics := context.Bool(flag.FlagAnalytics)
if analytics {
if err := telemetry.Initialize(context.String("analytics-token")); err != nil {
return errors.Wrap(err, "failed to create telemetry client")
}
if err := telemetry.Initialize(analytics,
context.String("analytics-token")); err != nil {
return errors.Wrap(err, "failed to create telemetry client")
}

// TODO(gaocegege): Add a config struct to keep them.
Expand Down
74 changes: 40 additions & 34 deletions pkg/app/telemetry/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Reporter interface {
type defaultReporter struct {
client segmentio.Client
telemetryFile string
enabled bool

UID string
}
Expand All @@ -46,10 +47,11 @@ var (
once sync.Once
)

func Initialize(token string) error {
func Initialize(enabled bool, token string) error {
once.Do(func() {
reporter = &defaultReporter{
client: segmentio.New(token),
enabled: enabled,
client: segmentio.New(token),
}
})
return reporter.init()
Expand Down Expand Up @@ -103,25 +105,27 @@ func (r *defaultReporter) init() error {
r.UID = string(uid)

logrus.WithField("UID", r.UID).Debug("telemetry initialization")
v := version.GetVersion()
logrus.Debug("sending telemetry")
if err := r.client.Enqueue(segmentio.Identify{
UserId: r.UID,
Context: &segmentio.Context{
OS: segmentio.OSInfo{
Name: runtime.GOOS,
Version: runtime.GOARCH,
if r.enabled {
logrus.Debug("sending telemetry")
v := version.GetVersion()
if err := r.client.Enqueue(segmentio.Identify{
UserId: r.UID,
Context: &segmentio.Context{
OS: segmentio.OSInfo{
Name: runtime.GOOS,
Version: runtime.GOARCH,
},
App: segmentio.AppInfo{
Name: "envd-cli",
Version: v.Version,
},
},
App: segmentio.AppInfo{
Name: "envd-cli",
Version: v.Version,
},
},
Timestamp: time.Now(),
Traits: segmentio.NewTraits(),
}); err != nil {
logrus.Warn("telemetry failed")
return nil
Timestamp: time.Now(),
Traits: segmentio.NewTraits(),
}); err != nil {
logrus.Warn("telemetry failed")
return nil
}
}
return nil
}
Expand All @@ -139,19 +143,21 @@ func (r *defaultReporter) dumpTelemetry() error {
}

func (r *defaultReporter) Telemetry(command string, runner *string) {
logrus.WithFields(logrus.Fields{
"UID": r.UID,
"command": command,
}).Debug("sending telemetry track event")
t := segmentio.Track{
UserId: r.UID,
Event: command,
Properties: segmentio.NewProperties(),
}
if runner != nil {
t.Properties = t.Properties.Set("runner", runner)
}
if err := r.client.Enqueue(t); err != nil {
logrus.Warn(err)
if r.enabled {
logrus.WithFields(logrus.Fields{
"UID": r.UID,
"command": command,
}).Debug("sending telemetry track event")
t := segmentio.Track{
UserId: r.UID,
Event: command,
Properties: segmentio.NewProperties(),
}
if runner != nil {
t.Properties = t.Properties.Set("runner", runner)
}
if err := r.client.Enqueue(t); err != nil {
logrus.Warn(err)
}
}
}