Skip to content

Commit 381d667

Browse files
authored
chore: add install_source to telemetry (#6008)
This will help determine the number of installs from marketplaces!
1 parent 8b424f0 commit 381d667

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

coderd/telemetry/telemetry.go

+9
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,13 @@ func (r *remoteReporter) deployment() error {
230230
if sysInfo.Containerized != nil {
231231
containerized = *sysInfo.Containerized
232232
}
233+
234+
// Tracks where Coder was installed from!
235+
installSource := os.Getenv("CODER_TELEMETRY_INSTALL_SOURCE")
236+
if installSource != "" && installSource != "aws_marketplace" {
237+
return xerrors.Errorf("invalid installce source: %s", installSource)
238+
}
239+
233240
data, err := json.Marshal(&Deployment{
234241
ID: r.options.DeploymentID,
235242
Architecture: sysInfo.Architecture,
@@ -243,6 +250,7 @@ func (r *remoteReporter) deployment() error {
243250
OIDCAuth: r.options.OIDCAuth,
244251
OIDCIssuerURL: r.options.OIDCIssuerURL,
245252
Prometheus: r.options.Prometheus,
253+
InstallSource: installSource,
246254
STUN: r.options.STUN,
247255
Tunnel: r.options.Tunnel,
248256
OSType: sysInfo.OS.Type,
@@ -677,6 +685,7 @@ type Deployment struct {
677685
OIDCAuth bool `json:"oidc_auth"`
678686
OIDCIssuerURL string `json:"oidc_issuer_url"`
679687
Prometheus bool `json:"prometheus"`
688+
InstallSource string `json:"install_source"`
680689
STUN bool `json:"stun"`
681690
OSType string `json:"os_type"`
682691
OSFamily string `json:"os_family"`

coderd/telemetry/telemetry_test.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestTelemetry(t *testing.T) {
117117
},
118118
})
119119
assert.NoError(t, err)
120-
snapshot := collectSnapshot(t, db)
120+
_, snapshot := collectSnapshot(t, db)
121121
require.Len(t, snapshot.ParameterSchemas, 1)
122122
require.Len(t, snapshot.ProvisionerJobs, 1)
123123
require.Len(t, snapshot.Licenses, 1)
@@ -140,21 +140,32 @@ func TestTelemetry(t *testing.T) {
140140
LoginType: database.LoginTypePassword,
141141
})
142142
require.NoError(t, err)
143-
snapshot := collectSnapshot(t, db)
143+
_, snapshot := collectSnapshot(t, db)
144144
require.Len(t, snapshot.Users, 1)
145145
require.Equal(t, snapshot.Users[0].EmailHashed, "bb44bf07cf9a2db0554bba63a03d822c927deae77df101874496df5a6a3e896d@coder.com")
146146
})
147147
}
148148

149-
func collectSnapshot(t *testing.T, db database.Store) *telemetry.Snapshot {
149+
// nolint:paralleltest
150+
func TestTelemetryInstallSource(t *testing.T) {
151+
t.Setenv("CODER_TELEMETRY_INSTALL_SOURCE", "aws_marketplace")
152+
db := databasefake.New()
153+
deployment, _ := collectSnapshot(t, db)
154+
require.Equal(t, "aws_marketplace", deployment.InstallSource)
155+
}
156+
157+
func collectSnapshot(t *testing.T, db database.Store) (*telemetry.Deployment, *telemetry.Snapshot) {
150158
t.Helper()
151-
deployment := make(chan struct{}, 64)
159+
deployment := make(chan *telemetry.Deployment, 64)
152160
snapshot := make(chan *telemetry.Snapshot, 64)
153161
r := chi.NewRouter()
154162
r.Post("/deployment", func(w http.ResponseWriter, r *http.Request) {
155163
require.Equal(t, buildinfo.Version(), r.Header.Get(telemetry.VersionHeader))
156164
w.WriteHeader(http.StatusAccepted)
157-
deployment <- struct{}{}
165+
dd := &telemetry.Deployment{}
166+
err := json.NewDecoder(r.Body).Decode(dd)
167+
require.NoError(t, err)
168+
deployment <- dd
158169
})
159170
r.Post("/snapshot", func(w http.ResponseWriter, r *http.Request) {
160171
require.Equal(t, buildinfo.Version(), r.Header.Get(telemetry.VersionHeader))
@@ -176,6 +187,5 @@ func collectSnapshot(t *testing.T, db database.Store) *telemetry.Snapshot {
176187
})
177188
require.NoError(t, err)
178189
t.Cleanup(reporter.Close)
179-
<-deployment
180-
return <-snapshot
190+
return <-deployment, <-snapshot
181191
}

0 commit comments

Comments
 (0)