Skip to content

Commit b7b0833

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

File tree

8 files changed

+28
-21
lines changed

8 files changed

+28
-21
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

+13-6
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
}
@@ -475,10 +482,10 @@ type Snapshot struct {
475482

476483
// Deployment contains information about the host running Coder.
477484
type Deployment struct {
478-
ID string `json:"id" validate:"required"`
485+
ID string `json:"id"`
479486
Architecture string `json:"architecture"`
480487
Containerized bool `json:"containerized"`
481-
DevMode bool `json:"dev_mode" validate:"required"`
488+
DevMode bool `json:"dev_mode"`
482489
OSType string `json:"os_type"`
483490
OSFamily string `json:"os_family"`
484491
OSPlatform string `json:"os_platform"`
@@ -487,7 +494,7 @@ type Deployment struct {
487494
CPUCores int `json:"cpu_cores"`
488495
MemoryTotal uint64 `json:"memory_total"`
489496
MachineID string `json:"machine_id"`
490-
Version string `json:"version" validate:"required"`
497+
Version string `json:"version"`
491498
StartedAt time.Time `json:"started_at"`
492499
ShutdownAt *time.Time `json:"shutdown_at"`
493500
}
@@ -578,7 +585,7 @@ type ProvisionerJob struct {
578585
}
579586

580587
type ParameterSchema struct {
581-
ID uuid.UUID `json:"parameter_schema"`
588+
ID uuid.UUID `json:"id"`
582589
JobID uuid.UUID `json:"job_id"`
583590
Name string `json:"name"`
584591
ValidationCondition string `json:"validation_condition"`

0 commit comments

Comments
 (0)