- Notifications
You must be signed in to change notification settings - Fork928
feat(coderd): add enabled experiments to telemetry#12656
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -85,7 +85,7 @@ func TestTelemetry(t *testing.T) { | ||
assert.NoError(t, err) | ||
_, _ = dbgen.WorkspaceProxy(t, db, database.WorkspaceProxy{}) | ||
_, snapshot := collectSnapshot(t, db, nil) | ||
require.Len(t, snapshot.ProvisionerJobs, 1) | ||
require.Len(t, snapshot.Licenses, 1) | ||
require.Len(t, snapshot.Templates, 1) | ||
@@ -110,21 +110,32 @@ func TestTelemetry(t *testing.T) { | ||
_ = dbgen.User(t, db, database.User{ | ||
Email: "kyle@coder.com", | ||
}) | ||
_, snapshot := collectSnapshot(t, db, nil) | ||
require.Len(t, snapshot.Users, 1) | ||
require.Equal(t, snapshot.Users[0].EmailHashed, "bb44bf07cf9a2db0554bba63a03d822c927deae77df101874496df5a6a3e896d@coder.com") | ||
}) | ||
t.Run("Experiments", func(t *testing.T) { | ||
t.Parallel() | ||
const expName = "my-experiment" | ||
exps := []string{expName} | ||
_, snapshot := collectSnapshot(t, dbmem.New(), func(opts telemetry.Options) telemetry.Options { | ||
opts.Experiments = exps | ||
return opts | ||
}) | ||
require.Equal(t, []telemetry.Experiment{{Name: expName}}, snapshot.Experiments) | ||
}) | ||
} | ||
// nolint:paralleltest | ||
func TestTelemetryInstallSource(t *testing.T) { | ||
t.Setenv("CODER_TELEMETRY_INSTALL_SOURCE", "aws_marketplace") | ||
db := dbmem.New() | ||
deployment, _ := collectSnapshot(t, db, nil) | ||
require.Equal(t, "aws_marketplace", deployment.InstallSource) | ||
} | ||
func collectSnapshot(t *testing.T, db database.Store, addOptionsFn func(opts telemetry.Options) telemetry.Options) (*telemetry.Deployment, *telemetry.Snapshot) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. suggestion, nonblocking: if you make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. It's an interesting idea, but I think it'd change the semantics a bit. | ||
t.Helper() | ||
deployment := make(chan *telemetry.Deployment, 64) | ||
snapshot := make(chan *telemetry.Snapshot, 64) | ||
@@ -149,12 +160,17 @@ func collectSnapshot(t *testing.T, db database.Store) (*telemetry.Deployment, *t | ||
t.Cleanup(server.Close) | ||
serverURL, err := url.Parse(server.URL) | ||
require.NoError(t, err) | ||
options:= telemetry.Options{ | ||
Database: db, | ||
Logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug), | ||
URL: serverURL, | ||
DeploymentID: uuid.NewString(), | ||
} | ||
if addOptionsFn != nil { | ||
options = addOptionsFn(options) | ||
} | ||
reporter, err := telemetry.New(options) | ||
require.NoError(t, err) | ||
t.Cleanup(reporter.Close) | ||
return <-deployment, <-snapshot | ||