@@ -28,7 +28,8 @@ import (
28
28
type Options struct {
29
29
Database database.Store
30
30
Logger slog.Logger
31
- URL * url.URL
31
+ // URL is an endpoint to direct telemetry towards!
32
+ URL * url.URL
32
33
33
34
DeploymentID string
34
35
DevMode bool
@@ -155,9 +156,13 @@ func (r *Reporter) runSnapshotter() {
155
156
case <- ticker .C :
156
157
}
157
158
// Skip the ticker on the first run to report instantly!
158
- first = false
159
159
}
160
+ first = false
160
161
r .closeMutex .Lock ()
162
+ if r .isClosed () {
163
+ r .closeMutex .Unlock ()
164
+ return
165
+ }
161
166
r .report ()
162
167
r .closeMutex .Unlock ()
163
168
}
@@ -345,6 +350,8 @@ func (r *Reporter) createSnapshot() (*Snapshot, error) {
345
350
emailHashed := ""
346
351
atSymbol := strings .LastIndex (dbUser .Email , "@" )
347
352
if atSymbol >= 0 {
353
+ // We hash the beginning of the user to allow for indexing users
354
+ // by email between deployments.
348
355
hash := sha256 .Sum256 ([]byte (dbUser .Email [:atSymbol ]))
349
356
emailHashed = fmt .Sprintf ("%x%s" , hash [:], dbUser .Email [atSymbol :])
350
357
}
@@ -459,127 +466,127 @@ func (r *Reporter) createSnapshot() (*Snapshot, error) {
459
466
// Data is aggregated by latest on the server-side, so partial data
460
467
// can be sent without issue.
461
468
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" `
474
481
}
475
482
476
483
// Deployment contains information about the host running Coder.
477
484
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" `
493
500
}
494
501
495
502
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" `
501
508
}
502
509
503
510
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" `
508
515
}
509
516
510
517
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" `
520
527
}
521
528
522
529
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" `
528
535
}
529
536
530
537
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" `
537
544
}
538
545
539
546
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" `
545
552
}
546
553
547
554
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" `
557
564
}
558
565
559
566
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" `
565
572
}
566
573
567
574
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" `
578
585
}
579
586
580
587
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" `
585
592
}
0 commit comments