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

This commit is contained in:
Mathias Fredriksson
2024-11-14 01:07:52 +02:00
committed by GitHub
parent 99dd13d4cd
commit e55e8ee1b2
4 changed files with 58 additions and 11 deletions
+33
View File
@@ -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).
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.")
+22 -8
View File
@@ -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",
@@ -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",
+1 -1
View File
@@ -204,7 +204,7 @@ require (
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.2.1
github.com/charmbracelet/lipgloss v1.0.0
github.com/coder/serpent v0.8.0
github.com/coder/serpent v0.9.0
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
+2 -2
View File
@@ -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.9.0 h1:gfoTNOUitVdO1ZeZKk8xHiFjBvjzCQXxcMpZ7Dg41Qg=
github.com/coder/serpent v0.9.0/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=