Skip to content

Commit ad19dce

Browse files
committed
Fix flake and requested changes
1 parent 17e9900 commit ad19dce

File tree

8 files changed

+113
-106
lines changed

8 files changed

+113
-106
lines changed

cli/server.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func server() *cobra.Command {
8282
oauth2GithubClientSecret string
8383
oauth2GithubAllowedOrganizations []string
8484
oauth2GithubAllowSignups bool
85-
telemetryEnabled bool
85+
telemetryEnable bool
8686
telemetryURL string
8787
tlsCertFile string
8888
tlsClientCAFile string
@@ -327,16 +327,16 @@ func server() *cobra.Command {
327327
}
328328
// Disable telemetry if in dev-mode. If the telemetry flag
329329
// is manually specified, override this behavior!
330-
if buildModeDev && !cmd.Flags().Changed("telemetry") {
331-
telemetryEnabled = false
330+
if buildModeDev && !cmd.Flags().Changed("telemetry-enable") {
331+
telemetryEnable = false
332332
}
333333
reporter, err := telemetry.New(telemetry.Options{
334334
DeploymentID: deploymentID,
335335
Database: options.Database,
336336
Logger: logger.Named("telemetry"),
337337
URL: telemetryURL,
338338
DevMode: dev,
339-
Disabled: !telemetryEnabled,
339+
Disabled: !telemetryEnable,
340340
})
341341
if err != nil {
342342
return xerrors.Errorf("create telemetry reporter: %w", err)
@@ -580,7 +580,7 @@ func server() *cobra.Command {
580580
"Specifies organizations the user must be a member of to authenticate with GitHub.")
581581
cliflag.BoolVarP(root.Flags(), &oauth2GithubAllowSignups, "oauth2-github-allow-signups", "", "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS", false,
582582
"Specifies whether new users can sign up with GitHub.")
583-
cliflag.BoolVarP(root.Flags(), &telemetryEnabled, "telemetry", "", "CODER_TELEMETRY", true, "Specifies whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product!")
583+
cliflag.BoolVarP(root.Flags(), &telemetryEnable, "telemetry-enable", "", "CODER_TELEMETRY_ENABLE", true, "Specifies whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product!")
584584
cliflag.StringVarP(root.Flags(), &telemetryURL, "telemetry-url", "", "CODER_TELEMETRY_URL", "https://telemetry.coder.com", "Specifies a URL to send telemetry to.")
585585
_ = root.Flags().MarkHidden("telemetry-url")
586586
cliflag.BoolVarP(root.Flags(), &tlsEnable, "tls-enable", "", "CODER_TLS_ENABLE", false, "Specifies if TLS will be enabled")

cli/server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func TestServer(t *testing.T) {
348348
server := httptest.NewServer(r)
349349
t.Cleanup(server.Close)
350350

351-
root, _ := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0", "--telemetry", "true", "--telemetry-url", server.URL)
351+
root, _ := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0", "--telemetry-enable", "true", "--telemetry-url", server.URL)
352352
var buf strings.Builder
353353
errC := make(chan error)
354354
root.SetOutput(&buf)

coderd/database/databasefake/databasefake.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ func (q *fakeQuerier) GetTemplates(_ context.Context) ([]database.Template, erro
981981
q.mutex.RLock()
982982
defer q.mutex.RUnlock()
983983

984-
return q.templates, nil
984+
return q.templates[:], nil
985985
}
986986

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

coderd/database/dump.sql

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE TABLE IF NOT EXISTS site_config (
1+
CREATE TABLE IF NOT EXISTS site_configs (
22
key varchar(256) NOT NULL UNIQUE,
33
value varchar(8192) NOT NULL
44
);

coderd/database/queries.sql.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- name: InsertDeploymentID :exec
2-
INSERT INTO site_config (key, value) VALUES ('deployment_id', $1);
2+
INSERT INTO site_configs (key, value) VALUES ('deployment_id', $1);
33

44
-- name: GetDeploymentID :one
5-
SELECT value FROM site_config WHERE key = 'deployment_id';
5+
SELECT value FROM site_configs WHERE key = 'deployment_id';

coderd/telemetry/telemetry.go

+98-91
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import (
2828
type Options struct {
2929
Database database.Store
3030
Logger slog.Logger
31-
URL *url.URL
31+
// URL is an endpoint to direct telemetry towards!
32+
URL *url.URL
3233

3334
DeploymentID string
3435
DevMode bool
@@ -155,9 +156,13 @@ func (r *Reporter) runSnapshotter() {
155156
case <-ticker.C:
156157
}
157158
// Skip the ticker on the first run to report instantly!
158-
first = false
159159
}
160+
first = false
160161
r.closeMutex.Lock()
162+
if r.isClosed() {
163+
r.closeMutex.Unlock()
164+
return
165+
}
161166
r.report()
162167
r.closeMutex.Unlock()
163168
}
@@ -345,6 +350,8 @@ func (r *Reporter) createSnapshot() (*Snapshot, error) {
345350
emailHashed := ""
346351
atSymbol := strings.LastIndex(dbUser.Email, "@")
347352
if atSymbol >= 0 {
353+
// We hash the beginning of the user to allow for indexing users
354+
// by email between deployments.
348355
hash := sha256.Sum256([]byte(dbUser.Email[:atSymbol]))
349356
emailHashed = fmt.Sprintf("%x%s", hash[:], dbUser.Email[atSymbol:])
350357
}
@@ -459,127 +466,127 @@ func (r *Reporter) createSnapshot() (*Snapshot, error) {
459466
// Data is aggregated by latest on the server-side, so partial data
460467
// can be sent without issue.
461468
type Snapshot struct {
462-
DeploymentID string `json:"deployment_id"`
463-
464-
ParameterSchemas []ParameterSchema `json:"parameter_schemas"`
465-
ProvisionerJobs []ProvisionerJob `json:"provisioner_jobs"`
466-
Templates []Template `json:"templates"`
467-
TemplateVersions []TemplateVersion `json:"template_versions"`
468-
Users []User `json:"users"`
469-
Workspaces []Workspace `json:"workspaces"`
470-
WorkspaceApps []WorkspaceApp `json:"workspace_apps"`
471-
WorkspaceAgents []WorkspaceAgent `json:"workspace_agents"`
472-
WorkspaceBuilds []WorkspaceBuild `json:"workspace_build"`
473-
WorkspaceResources []WorkspaceResource `json:"workspace_resources"`
469+
DeploymentID string `json:"deployment_id" bigquery:"deployment_id"`
470+
471+
ParameterSchemas []ParameterSchema `json:"parameter_schemas" bigquery:"parameter_schemas"`
472+
ProvisionerJobs []ProvisionerJob `json:"provisioner_jobs" bigquery:"provisioner_jobs"`
473+
Templates []Template `json:"templates" bigquery:"templates"`
474+
TemplateVersions []TemplateVersion `json:"template_versions" bigquery:"template_versions"`
475+
Users []User `json:"users" bigquery:"users"`
476+
Workspaces []Workspace `json:"workspaces" bigquery:"workspaces"`
477+
WorkspaceApps []WorkspaceApp `json:"workspace_apps" bigquery:"workspace_apps"`
478+
WorkspaceAgents []WorkspaceAgent `json:"workspace_agents" bigquery:"workspace_agents"`
479+
WorkspaceBuilds []WorkspaceBuild `json:"workspace_build" bigquery:"workspace_build"`
480+
WorkspaceResources []WorkspaceResource `json:"workspace_resources" bigquery:"workspace_resources"`
474481
}
475482

476483
// Deployment contains information about the host running Coder.
477484
type Deployment struct {
478-
ID string `json:"id" validate:"required"`
479-
Architecture string `json:"architecture"`
480-
Containerized bool `json:"containerized"`
481-
DevMode bool `json:"dev_mode" validate:"required"`
482-
OSType string `json:"os_type"`
483-
OSFamily string `json:"os_family"`
484-
OSPlatform string `json:"os_platform"`
485-
OSName string `json:"os_name"`
486-
OSVersion string `json:"os_version"`
487-
CPUCores int `json:"cpu_cores"`
488-
MemoryTotal uint64 `json:"memory_total"`
489-
MachineID string `json:"machine_id"`
490-
Version string `json:"version" validate:"required"`
491-
StartedAt time.Time `json:"started_at"`
492-
ShutdownAt *time.Time `json:"shutdown_at"`
485+
ID string `json:"id" bigquery:"id"`
486+
Architecture string `json:"architecture" bigquery:"architecture"`
487+
Containerized bool `json:"containerized" bigquery:"containerized"`
488+
DevMode bool `json:"dev_mode" bigquery:"dev_mode"`
489+
OSType string `json:"os_type" bigquery:"os_type"`
490+
OSFamily string `json:"os_family" bigquery:"os_family"`
491+
OSPlatform string `json:"os_platform" bigquery:"os_platform"`
492+
OSName string `json:"os_name" bigquery:"os_name"`
493+
OSVersion string `json:"os_version" bigquery:"os_version"`
494+
CPUCores int `json:"cpu_cores" bigquery:"cpu_cores"`
495+
MemoryTotal uint64 `json:"memory_total" bigquery:"memory_total"`
496+
MachineID string `json:"machine_id" bigquery:"machine_id"`
497+
Version string `json:"version" bigquery:"version"`
498+
StartedAt time.Time `json:"started_at" bigquery:"started_at"`
499+
ShutdownAt *time.Time `json:"shutdown_at" bigquery:"shutdown_at"`
493500
}
494501

495502
type User struct {
496-
ID uuid.UUID `json:"uuid"`
497-
CreatedAt time.Time `json:"created_at"`
498-
EmailHashed string `json:"email_hashed"`
499-
RBACRoles []string `json:"rbac_roles"`
500-
Status database.UserStatus `json:"status"`
503+
ID uuid.UUID `json:"uuid" bigquery:"uuid"`
504+
CreatedAt time.Time `json:"created_at" bigquery:"created_at"`
505+
EmailHashed string `json:"email_hashed" bigquery:"email_hashed"`
506+
RBACRoles []string `json:"rbac_roles" bigquery:"rbac_roles"`
507+
Status database.UserStatus `json:"status" bigquery:"status"`
501508
}
502509

503510
type WorkspaceResource struct {
504-
ID uuid.UUID `json:"id"`
505-
JobID uuid.UUID `json:"job_id"`
506-
Transition database.WorkspaceTransition `json:"transition"`
507-
Type string `json:"type"`
511+
ID uuid.UUID `json:"id" bigquery:"id"`
512+
JobID uuid.UUID `json:"job_id" bigquery:"job_id"`
513+
Transition database.WorkspaceTransition `json:"transition" bigquery:"transition"`
514+
Type string `json:"type" bigquery:"type"`
508515
}
509516

510517
type WorkspaceAgent struct {
511-
ID uuid.UUID `json:"id"`
512-
CreatedAt time.Time `json:"created_at"`
513-
ResourceID uuid.UUID `json:"resource_id"`
514-
InstanceAuth bool `json:"instance_auth"`
515-
Architecture string `json:"architecture"`
516-
OperatingSystem string `json:"operating_system"`
517-
EnvironmentVariables bool `json:"environment_variables"`
518-
StartupScript bool `json:"startup_script"`
519-
Directory bool `json:"directory"`
518+
ID uuid.UUID `json:"id" bigquery:"id"`
519+
CreatedAt time.Time `json:"created_at" bigquery:"created_at"`
520+
ResourceID uuid.UUID `json:"resource_id" bigquery:"resource_id"`
521+
InstanceAuth bool `json:"instance_auth" bigquery:"instance_auth"`
522+
Architecture string `json:"architecture" bigquery:"architecture"`
523+
OperatingSystem string `json:"operating_system" bigquery:"operating_system"`
524+
EnvironmentVariables bool `json:"environment_variables" bigquery:"environment_variables"`
525+
StartupScript bool `json:"startup_script" bigquery:"startup_script"`
526+
Directory bool `json:"directory" bigquery:"directory"`
520527
}
521528

522529
type WorkspaceApp struct {
523-
ID uuid.UUID `json:"id"`
524-
CreatedAt time.Time `json:"created_at"`
525-
AgentID uuid.UUID `json:"agent_id"`
526-
Icon bool `json:"icon"`
527-
RelativePath bool `json:"relative_path"`
530+
ID uuid.UUID `json:"id" bigquery:"id"`
531+
CreatedAt time.Time `json:"created_at" bigquery:"created_at"`
532+
AgentID uuid.UUID `json:"agent_id" bigquery:"agent_id"`
533+
Icon bool `json:"icon" bigquery:"icon"`
534+
RelativePath bool `json:"relative_path" bigquery:"relative_path"`
528535
}
529536

530537
type WorkspaceBuild struct {
531-
ID uuid.UUID `json:"id"`
532-
CreatedAt time.Time `json:"created_at"`
533-
WorkspaceID uuid.UUID `json:"workspace_id"`
534-
TemplateVersionID uuid.UUID `json:"template_version_id"`
535-
JobID uuid.UUID `json:"job_id"`
536-
BuildNumber uint32 `json:"build_number"`
538+
ID uuid.UUID `json:"id" bigquery:"id"`
539+
CreatedAt time.Time `json:"created_at" bigquery:"created_at"`
540+
WorkspaceID uuid.UUID `json:"workspace_id" bigquery:"workspace_id"`
541+
TemplateVersionID uuid.UUID `json:"template_version_id" bigquery:"template_version_id"`
542+
JobID uuid.UUID `json:"job_id" bigquery:"job_id"`
543+
BuildNumber uint32 `json:"build_number" bigquery:"build_number"`
537544
}
538545

539546
type Workspace struct {
540-
OrganizationID uuid.UUID `json:"organization_id"`
541-
OwnerID uuid.UUID `json:"owner_id"`
542-
TemplateID uuid.UUID `json:"template_id"`
543-
CreatedAt time.Time `json:"created_at"`
544-
Deleted bool `json:"deleted"`
547+
OrganizationID uuid.UUID `json:"organization_id" bigquery:"organization_id"`
548+
OwnerID uuid.UUID `json:"owner_id" bigquery:"owner_id"`
549+
TemplateID uuid.UUID `json:"template_id" bigquery:"template_id"`
550+
CreatedAt time.Time `json:"created_at" bigquery:"created_at"`
551+
Deleted bool `json:"deleted" bigquery:"deleted"`
545552
}
546553

547554
type Template struct {
548-
ID uuid.UUID `json:"id"`
549-
CreatedBy uuid.UUID `json:"created_by"`
550-
CreatedAt time.Time `json:"created_at"`
551-
UpdatedAt time.Time `json:"updated_at"`
552-
OrganizationID uuid.UUID `json:"organization_id"`
553-
Deleted bool `json:"deleted"`
554-
ActiveVersionID uuid.UUID `json:"active_version_id"`
555-
Name string `json:"name"`
556-
Description bool `json:"description"`
555+
ID uuid.UUID `json:"id" bigquery:"id"`
556+
CreatedBy uuid.UUID `json:"created_by" bigquery:"created_by"`
557+
CreatedAt time.Time `json:"created_at" bigquery:"created_at"`
558+
UpdatedAt time.Time `json:"updated_at" bigquery:"updated_at"`
559+
OrganizationID uuid.UUID `json:"organization_id" bigquery:"organization_id"`
560+
Deleted bool `json:"deleted" bigquery:"deleted"`
561+
ActiveVersionID uuid.UUID `json:"active_version_id" bigquery:"active_version_id"`
562+
Name string `json:"name" bigquery:"name"`
563+
Description bool `json:"description" bigquery:"description"`
557564
}
558565

559566
type TemplateVersion struct {
560-
ID uuid.UUID `json:"id"`
561-
CreatedAt time.Time `json:"created_at"`
562-
TemplateID *uuid.UUID `json:"template_id,omitempty"`
563-
OrganizationID uuid.UUID `json:"organization_id"`
564-
JobID uuid.UUID `json:"job_id"`
567+
ID uuid.UUID `json:"id" bigquery:"id"`
568+
CreatedAt time.Time `json:"created_at" bigquery:"created_at"`
569+
TemplateID *uuid.UUID `json:"template_id,omitempty" bigquery:"template_id,omitempty"`
570+
OrganizationID uuid.UUID `json:"organization_id" bigquery:"organization_id"`
571+
JobID uuid.UUID `json:"job_id" bigquery:"job_id"`
565572
}
566573

567574
type ProvisionerJob struct {
568-
ID uuid.UUID `json:"id"`
569-
OrganizationID uuid.UUID `json:"organization_id"`
570-
InitiatorID uuid.UUID `json:"initiator_id"`
571-
CreatedAt time.Time `json:"created_at"`
572-
UpdatedAt time.Time `json:"updated_at"`
573-
StartedAt *time.Time `json:"started_at,omitempty"`
574-
CanceledAt *time.Time `json:"canceled_at,omitempty"`
575-
CompletedAt *time.Time `json:"completed_at,omitempty"`
576-
Error string `json:"error"`
577-
Type database.ProvisionerJobType `json:"type"`
575+
ID uuid.UUID `json:"id" bigquery:"id"`
576+
OrganizationID uuid.UUID `json:"organization_id" bigquery:"organization_id"`
577+
InitiatorID uuid.UUID `json:"initiator_id" bigquery:"initiator_id"`
578+
CreatedAt time.Time `json:"created_at" bigquery:"created_at"`
579+
UpdatedAt time.Time `json:"updated_at" bigquery:"updated_at"`
580+
StartedAt *time.Time `json:"started_at,omitempty" bigquery:"started_at,omitempty"`
581+
CanceledAt *time.Time `json:"canceled_at,omitempty" bigquery:"canceled_at,omitempty"`
582+
CompletedAt *time.Time `json:"completed_at,omitempty" bigquery:"completed_at,omitempty"`
583+
Error string `json:"error" bigquery:"error"`
584+
Type database.ProvisionerJobType `json:"type" bigquery:"type"`
578585
}
579586

580587
type ParameterSchema struct {
581-
ID uuid.UUID `json:"parameter_schema"`
582-
JobID uuid.UUID `json:"job_id"`
583-
Name string `json:"name"`
584-
ValidationCondition string `json:"validation_condition"`
588+
ID uuid.UUID `json:"parameter_schema" bigquery:"parameter_schema"`
589+
JobID uuid.UUID `json:"job_id" bigquery:"job_id"`
590+
Name string `json:"name" bigquery:"name"`
591+
ValidationCondition string `json:"validation_condition" bigquery:"validation_condition"`
585592
}

0 commit comments

Comments
 (0)