Skip to content

chore: add install_source to telemetry #6008

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

Merged
merged 2 commits into from
Feb 3, 2023
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
9 changes: 9 additions & 0 deletions coderd/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ func (r *remoteReporter) deployment() error {
if sysInfo.Containerized != nil {
containerized = *sysInfo.Containerized
}

// Tracks where Coder was installed from!
installSource := os.Getenv("CODER_TELEMETRY_INSTALL_SOURCE")
if installSource != "" && installSource != "aws_marketplace" {
return xerrors.Errorf("invalid installce source: %s", installSource)
}

data, err := json.Marshal(&Deployment{
ID: r.options.DeploymentID,
Architecture: sysInfo.Architecture,
Expand All @@ -243,6 +250,7 @@ func (r *remoteReporter) deployment() error {
OIDCAuth: r.options.OIDCAuth,
OIDCIssuerURL: r.options.OIDCIssuerURL,
Prometheus: r.options.Prometheus,
InstallSource: installSource,
STUN: r.options.STUN,
Tunnel: r.options.Tunnel,
OSType: sysInfo.OS.Type,
Expand Down Expand Up @@ -677,6 +685,7 @@ type Deployment struct {
OIDCAuth bool `json:"oidc_auth"`
OIDCIssuerURL string `json:"oidc_issuer_url"`
Prometheus bool `json:"prometheus"`
InstallSource string `json:"install_source"`
STUN bool `json:"stun"`
OSType string `json:"os_type"`
OSFamily string `json:"os_family"`
Expand Down
24 changes: 17 additions & 7 deletions coderd/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestTelemetry(t *testing.T) {
},
})
assert.NoError(t, err)
snapshot := collectSnapshot(t, db)
_, snapshot := collectSnapshot(t, db)
require.Len(t, snapshot.ParameterSchemas, 1)
require.Len(t, snapshot.ProvisionerJobs, 1)
require.Len(t, snapshot.Licenses, 1)
Expand All @@ -140,21 +140,32 @@ func TestTelemetry(t *testing.T) {
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)
snapshot := collectSnapshot(t, db)
_, snapshot := collectSnapshot(t, db)
require.Len(t, snapshot.Users, 1)
require.Equal(t, snapshot.Users[0].EmailHashed, "bb44bf07cf9a2db0554bba63a03d822c927deae77df101874496df5a6a3e896d@coder.com")
})
}

func collectSnapshot(t *testing.T, db database.Store) *telemetry.Snapshot {
// nolint:paralleltest
func TestTelemetryInstallSource(t *testing.T) {
t.Setenv("CODER_TELEMETRY_INSTALL_SOURCE", "aws_marketplace")
db := databasefake.New()
deployment, _ := collectSnapshot(t, db)
require.Equal(t, "aws_marketplace", deployment.InstallSource)
}

func collectSnapshot(t *testing.T, db database.Store) (*telemetry.Deployment, *telemetry.Snapshot) {
t.Helper()
deployment := make(chan struct{}, 64)
deployment := make(chan *telemetry.Deployment, 64)
snapshot := make(chan *telemetry.Snapshot, 64)
r := chi.NewRouter()
r.Post("/deployment", func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, buildinfo.Version(), r.Header.Get(telemetry.VersionHeader))
w.WriteHeader(http.StatusAccepted)
deployment <- struct{}{}
dd := &telemetry.Deployment{}
err := json.NewDecoder(r.Body).Decode(dd)
require.NoError(t, err)
deployment <- dd
})
r.Post("/snapshot", func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, buildinfo.Version(), r.Header.Get(telemetry.VersionHeader))
Expand All @@ -176,6 +187,5 @@ func collectSnapshot(t *testing.T, db database.Store) *telemetry.Snapshot {
})
require.NoError(t, err)
t.Cleanup(reporter.Close)
<-deployment
return <-snapshot
return <-deployment, <-snapshot
}