From 2ba538aec000e5e836d36c250f288f4f140aaa7b Mon Sep 17 00:00:00 2001 From: kylecarbs Date: Fri, 17 Jun 2022 13:46:32 +0000 Subject: [PATCH 1/2] fix: Add flag to toggle telemetry This allows users to entirely disable tracking from Coder! Telemetry is enabled by default, so this is opt-out. --- cli/server.go | 8 +++++++- cli/server_test.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/server.go b/cli/server.go index 2696dd4616117..133ab9bd63fd9 100644 --- a/cli/server.go +++ b/cli/server.go @@ -83,6 +83,7 @@ func server() *cobra.Command { oauth2GithubClientSecret string oauth2GithubAllowedOrganizations []string oauth2GithubAllowSignups bool + telemetryEnable bool telemetryURL string tlsCertFile string tlsClientCAFile string @@ -311,7 +312,11 @@ func server() *cobra.Command { if err != nil { return xerrors.Errorf("parse telemetry url: %w", err) } - if !inMemoryDatabase || cmd.Flags().Changed("telemetry-url") { + // Disable telemetry if the in-memory database is used unless explicitly defined! + if inMemoryDatabase && !cmd.Flags().Changed("telemetry") { + telemetryEnable = false + } + if telemetryEnable { options.Telemetry, err = telemetry.New(telemetry.Options{ BuiltinPostgres: builtinPostgres, DeploymentID: deploymentID, @@ -531,6 +536,7 @@ func server() *cobra.Command { "Specifies organizations the user must be a member of to authenticate with GitHub.") cliflag.BoolVarP(root.Flags(), &oauth2GithubAllowSignups, "oauth2-github-allow-signups", "", "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS", false, "Specifies whether new users can sign up with GitHub.") + cliflag.BoolVarP(root.Flags(), &telemetryEnable, "telemetry", "", "CODER_TELEMETRY", true, "Specifies whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product!") cliflag.StringVarP(root.Flags(), &telemetryURL, "telemetry-url", "", "CODER_TELEMETRY_URL", "https://telemetry.coder.com", "Specifies a URL to send telemetry to.") _ = root.Flags().MarkHidden("telemetry-url") cliflag.BoolVarP(root.Flags(), &tlsEnable, "tls-enable", "", "CODER_TLS_ENABLE", false, "Specifies if TLS will be enabled") diff --git a/cli/server_test.go b/cli/server_test.go index a7be6b7d021e8..1532793caa321 100644 --- a/cli/server_test.go +++ b/cli/server_test.go @@ -259,7 +259,7 @@ func TestServer(t *testing.T) { server := httptest.NewServer(r) t.Cleanup(server.Close) - root, _ := clitest.New(t, "server", "--in-memory", "--address", ":0", "--telemetry-url", server.URL) + root, _ := clitest.New(t, "server", "--in-memory", "--address", ":0", "--telemetry", "--telemetry-url", server.URL) errC := make(chan error) go func() { errC <- root.ExecuteContext(ctx) From 1f971f14ed3ae695d222b29f6c2937697e832375 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Fri, 17 Jun 2022 08:51:30 -0500 Subject: [PATCH 2/2] Update cli/server.go Co-authored-by: Mathias Fredriksson --- cli/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/server.go b/cli/server.go index 133ab9bd63fd9..4e021a6b4ffb8 100644 --- a/cli/server.go +++ b/cli/server.go @@ -536,7 +536,7 @@ func server() *cobra.Command { "Specifies organizations the user must be a member of to authenticate with GitHub.") cliflag.BoolVarP(root.Flags(), &oauth2GithubAllowSignups, "oauth2-github-allow-signups", "", "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS", false, "Specifies whether new users can sign up with GitHub.") - cliflag.BoolVarP(root.Flags(), &telemetryEnable, "telemetry", "", "CODER_TELEMETRY", true, "Specifies whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product!") + cliflag.BoolVarP(root.Flags(), &telemetryEnable, "telemetry", "", "CODER_TELEMETRY", true, "Specifies whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product.") cliflag.StringVarP(root.Flags(), &telemetryURL, "telemetry-url", "", "CODER_TELEMETRY_URL", "https://telemetry.coder.com", "Specifies a URL to send telemetry to.") _ = root.Flags().MarkHidden("telemetry-url") cliflag.BoolVarP(root.Flags(), &tlsEnable, "tls-enable", "", "CODER_TLS_ENABLE", false, "Specifies if TLS will be enabled")