chore: add install_source to telemetry (#6008)

This will help determine the number of installs from marketplaces!
This commit is contained in:
Kyle Carberry
2023-02-02 19:30:54 -06:00
committed by GitHub
parent 8b424f03c2
commit 381d6674ca
2 changed files with 26 additions and 7 deletions

View File

@ -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,
@ -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,
@ -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"`

View File

@ -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)
@ -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))
@ -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
}