8000 feat: Add anonymized telemetry to report product usage by kylecarbs · Pull Request #2273 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: Add anonymized telemetry to report product usage #2273

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 11 commits into from
Jun 17, 2022
Prev Previous commit
Next Next commit
Merge branch 'main' into telemetry
  • Loading branch information
kylecarbs committed Jun 16, 2022
commit 9a31eb350c5b018da5cb9255e50e0da08d2d781b
24 changes: 13 additions & 11 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func server() *cobra.Command {
}

config := createConfig(cmd)
builtinPostgres := false
// Only use built-in if PostgreSQL URL isn't specified!
if !inMemoryDatabase && postgresURL == "" {
var closeFunc func() error
Expand All @@ -145,6 +146,7 @@ func server() *cobra.Command {
if err != nil {
return err
}
builtinPostgres = true
defer func() {
// Gracefully shut PostgreSQL down!
_ = closeFunc()
Expand Down Expand Up @@ -310,20 +312,20 @@ func server() *cobra.Command {
}
// Disable telemetry if in dev-mode. If the telemetry flag
// is manually specified, override this behavior!
if buildModeDev && !cmd.Flags().Changed("telemetry-enable") {
if !cmd.Flags().Changed("telemetry-enable") {
telemetryEnable = false
}
reporter, err := telemetry.New(telemetry.Options{
DeploymentID: deploymentID,
Database: options.Database,
Logger: logger.Named("telemetry"),
URL: telemetryURL,
DevMode: dev,
Disabled: !telemetryEnable,
GitHubOAuth: oauth2GithubClientID != "",
Prometheus: promEnabled,
STUN: len(stunServers) != 0,
Tunnel: tunnel,
BuiltinPostgres: builtinPostgres,
DeploymentID: deploymentID,
Database: options.Database,
Logger: logger.Named("telemetry"),
URL: telemetryURL,
Disabled: !telemetryEnable,
GitHubOAuth: oauth2GithubClientID != "",
Prometheus: promEnabled,
STUN: len(stunServers) != 0,
Tunnel: tunnel,
})
if err != nil {
return xerrors.Errorf("create telemetry reporter: %w", err)
Expand Down
58 changes: 0 additions & 58 deletions coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,25 +675,6 @@ func (q *fakeQuerier) GetWorkspaceBuildsCreatedAfter(_ context.Context, after ti
return workspaceBuilds, nil
}

func (q *fakeQuerier) GetWorkspacesByOrganizationIDs(_ context.Context, req database.GetWorkspacesByOrganizationIDsParams) ([]database.Workspace, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

workspaces := make([]database.Workspace, 0)
for _, workspace := range q.workspaces {
for _, id := range req.Ids {
if workspace.OrganizationID != id {
continue
}
if workspace.Deleted != req.Deleted {
continue
}
workspaces = append(workspaces, workspace)
}
}
return workspaces, nil
}

func (q *fakeQuerier) GetOrganizations(_ context.Context) ([]database.Organization, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
Expand Down Expand Up @@ -1028,45 +1009,6 @@ func (q *fakeQuerier) GetTemplates(_ context.Context) ([]database.Template, erro
return q.templates[:], nil
}

func (q *fakeQuerier) GetTemplatesByOrganization(_ context.Context, arg database.GetTemplatesByOrganizationParams) ([]database.Template, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

templates := make([]database.Template, 0)
for _, template := range q.templates {
if template.Deleted != arg.Deleted {
continue
}
if template.OrganizationID != arg.OrganizationID {
continue
}
templates = append(templates, template)
}
if len(templates) == 0 {
return nil, sql.ErrNoRows
}
return templates, nil
}

func (q *fakeQuerier) GetTemplatesByIDs(_ context.Context, ids []uuid.UUID) ([]database.Template, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

templates := make([]database.Template, 0)
for _, template := range q.templates {
for _, id := range ids {
if template.ID.String() != id.String() {
continue
}
templates = append(templates, template)
}
}
if len(templates) == 0 {
return nil, sql.ErrNoRows
}
return templates, nil
}

func (q *fakeQuerier) GetOrganizationMemberByUserID(_ context.Context, arg database.GetOrganizationMemberByUserIDParams) (database.OrganizationMember, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
Expand Down
5 changes: 1 addition & 4 deletions coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

142 changes: 34 additions & 108 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions coderd/database/queries/templates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ WHERE
LIMIT
1;

-- name: GetTemplatesByOrganization :many
SELECT
*
FROM
templates
WHERE
organization_id = $1
AND deleted = $2;

-- name: GetTemplates :many
SELECT * FROM templates;

Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
0