Skip to content

fix(cli): add backwards compat for old telemetry env and tests #15476

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
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cli/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,39 @@ func TestServer_Production(t *testing.T) {
require.NoError(t, err)
}

//nolint:tparallel,paralleltest // This test sets environment variables.
func TestServer_TelemetryDisable(t *testing.T) {
// Set the default telemetry to true (normally disabled in tests).
t.Setenv("CODER_TEST_TELEMETRY_DEFAULT_ENABLE", "true")

//nolint:paralleltest // No need to reinitialise the variable tt (Go version).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we should fix our linter.

Suggested change
//nolint:paralleltest // No need to reinitialise the variable tt (Go version).
//nolint:paralleltest // No need to reinitialise the variable tt (as of go v1.22).

for _, tt := range []struct {
key string
val string
want bool
}{
{"", "", true},
{"CODER_TELEMETRY_ENABLE", "true", true},
{"CODER_TELEMETRY_ENABLE", "false", false},
{"CODER_TELEMETRY", "true", true},
{"CODER_TELEMETRY", "false", false},
} {
t.Run(fmt.Sprintf("%s=%s", tt.key, tt.val), func(t *testing.T) {
t.Parallel()
var b bytes.Buffer
inv, _ := clitest.New(t, "server", "--write-config")
inv.Stdout = &b
inv.Environ.Set(tt.key, tt.val)
clitest.Run(t, inv)

var dv codersdk.DeploymentValues
err := yaml.Unmarshal(b.Bytes(), &dv)
require.NoError(t, err)
assert.Equal(t, tt.want, dv.Telemetry.Enable.Value())
})
}
}

//nolint:tparallel,paralleltest // This test cannot be run in parallel due to signal handling.
func TestServer_InterruptShutdown(t *testing.T) {
t.Skip("This test issues an interrupt signal which will propagate to the test runner.")
Expand Down
30 changes: 22 additions & 8 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,16 @@ when required by your organization's security policy.`,
Group: &deploymentGroupEmailTLS,
YAML: "certKeyFile",
}
telemetryEnable := serpent.Option{
Name: "Telemetry Enable",
Description: "Whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product.",
Flag: "telemetry",
Env: "CODER_TELEMETRY_ENABLE",
Default: strconv.FormatBool(flag.Lookup("test.v") == nil || os.Getenv("CODER_TEST_TELEMETRY_DEFAULT_ENABLE") == "true"),
Value: &c.Telemetry.Enable,
Group: &deploymentGroupTelemetry,
YAML: "enable",
}
opts := serpent.OptionSet{
{
Name: "Access URL",
Expand Down Expand Up @@ -1903,15 +1913,19 @@ when required by your organization's security policy.`,
YAML: "dangerousSkipIssuerChecks",
},
// Telemetry settings
telemetryEnable,
{
Name: "Telemetry Enable",
Description: "Whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product.",
Flag: "telemetry",
Env: "CODER_TELEMETRY_ENABLE",
Default: strconv.FormatBool(flag.Lookup("test.v") == nil),
Value: &c.Telemetry.Enable,
Group: &deploymentGroupTelemetry,
YAML: "enable",
Hidden: true,
Name: "Telemetry (backwards compatibility)",
// Note the flip-flop of flag and env to maintain backwards
// compatibility and consistency. Inconsistently, the env
// was renamed to CODER_TELEMETRY_ENABLE in the past, but
// the flag was not renamed -enable.
Flag: "telemetry-enable",
Env: "CODER_TELEMETRY",
Value: &c.Telemetry.Enable,
Group: &deploymentGroupTelemetry,
UseInstead: []serpent.Option{telemetryEnable},
},
{
Name: "Telemetry URL",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ require (
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.1.0
github.com/charmbracelet/lipgloss v1.0.0
github.com/coder/serpent v0.8.0
github.com/coder/serpent v0.8.1-0.20241113110052-e053fdac0b0d
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21
github.com/emersion/go-smtp v0.21.2
github.com/go-jose/go-jose/v4 v4.0.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ github.com/coder/quartz v0.1.2 h1:PVhc9sJimTdKd3VbygXtS4826EOCpB1fXoRlLnCrE+s=
github.com/coder/quartz v0.1.2/go.mod h1:vsiCc+AHViMKH2CQpGIpFgdHIEQsxwm8yCscqKmzbRA=
github.com/coder/retry v1.5.1 h1:iWu8YnD8YqHs3XwqrqsjoBTAVqT9ml6z9ViJ2wlMiqc=
github.com/coder/retry v1.5.1/go.mod h1:blHMk9vs6LkoRT9ZHyuZo360cufXEhrxqvEzeMtRGoY=
github.com/coder/serpent v0.8.0 h1:6OR+k6fekhSeEDmwwzBgnSjaa7FfGGrMlc3GoAEH9dg=
github.com/coder/serpent v0.8.0/go.mod h1:cZFW6/fP+kE9nd/oRkEHJpG6sXCtQ+AX7WMMEHv0Y3Q=
github.com/coder/serpent v0.8.1-0.20241113110052-e053fdac0b0d h1:wqbB0DI0F3LAHg5waDnuepn8/BNl9jPcBs7JHEc6b1Q=
github.com/coder/serpent v0.8.1-0.20241113110052-e053fdac0b0d/go.mod h1:cZFW6/fP+kE9nd/oRkEHJpG6sXCtQ+AX7WMMEHv0Y3Q=
github.com/coder/ssh v0.0.0-20231128192721-70855dedb788 h1:YoUSJ19E8AtuUFVYBpXuOD6a/zVP3rcxezNsoDseTUw=
github.com/coder/ssh v0.0.0-20231128192721-70855dedb788/go.mod h1:aGQbuCLyhRLMzZF067xc84Lh7JDs1FKwCmF1Crl9dxQ=
github.com/coder/tailscale v1.1.1-0.20241003034647-02286e537fc2 h1:mBbPFyJ2i9o490IwWGvWgtG0qmvIk45R7GWJpoaXotI=
Expand Down
Loading