Skip to content

Commit 3a1fa04

Browse files
authored
fix: write server config to telemetry (coder#13590)
* fix: add external auth configs to telemetry * Refactor telemetry to send the entire config * gen * Fix linting
1 parent d0b2f61 commit 3a1fa04

File tree

10 files changed

+54
-142
lines changed

10 files changed

+54
-142
lines changed

cli/server.go

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -796,31 +796,18 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
796796
cliui.Infof(inv.Stdout, "\n==> Logs will stream in below (press ctrl+c to gracefully exit):")
797797

798798
if vals.Telemetry.Enable {
799-
gitAuth := make([]telemetry.GitAuth, 0)
800-
// TODO:
801-
gitAuthConfigs := make([]codersdk.ExternalAuthConfig, 0)
802-
for _, cfg := range gitAuthConfigs {
803-
gitAuth = append(gitAuth, telemetry.GitAuth{
804-
Type: cfg.Type,
805-
})
799+
vals, err := vals.WithoutSecrets()
800+
if err != nil {
801+
return xerrors.Errorf("remove secrets from deployment values: %w", err)
806802
}
807-
808803
options.Telemetry, err = telemetry.New(telemetry.Options{
809-
BuiltinPostgres: builtinPostgres,
810-
DeploymentID: deploymentID,
811-
Database: options.Database,
812-
Logger: logger.Named("telemetry"),
813-
URL: vals.Telemetry.URL.Value(),
814-
Wildcard: vals.WildcardAccessURL.String() != "",
815-
DERPServerRelayURL: vals.DERP.Server.RelayURL.String(),
816-
GitAuth: gitAuth,
817-
GitHubOAuth: vals.OAuth2.Github.ClientID != "",
818-
OIDCAuth: vals.OIDC.ClientID != "",
819-
OIDCIssuerURL: vals.OIDC.IssuerURL.String(),
820-
Prometheus: vals.Prometheus.Enable.Value(),
821-
STUN: len(vals.DERP.Server.STUNAddresses) != 0,
822-
Tunnel: tunnel != nil,
823-
Experiments: vals.Experiments.Value(),
804+
BuiltinPostgres: builtinPostgres,
805+
DeploymentID: deploymentID,
806+
Database: options.Database,
807+
Logger: logger.Named("telemetry"),
808+
URL: vals.Telemetry.URL.Value(),
809+
Tunnel: tunnel != nil,
810+
DeploymentConfig: vals,
824811
ParseLicenseJWT: func(lic *telemetry.License) error {
825812
// This will be nil when running in AGPL-only mode.
826813
if options.ParseLicenseClaims == nil {

coderd/apidoc/docs.go

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/telemetry/telemetry.go

Lines changed: 43 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,13 @@ type Options struct {
4141
// URL is an endpoint to direct telemetry towards!
4242
URL *url.URL
4343

44-
BuiltinPostgres bool
45-
DeploymentID string
46-
GitHubOAuth bool
47-
OIDCAuth bool
48-
OIDCIssuerURL string
49-
Wildcard bool
50-
DERPServerRelayURL string
51-
GitAuth []GitAuth
52-
Prometheus bool
53-
STUN bool
54-
SnapshotFrequency time.Duration
55-
Tunnel bool
56-
ParseLicenseJWT func(lic *License) error
57-
Experiments []string
44+
DeploymentID string
45+
DeploymentConfig *codersdk.DeploymentValues
46+
BuiltinPostgres bool
47+
Tunnel bool
48+
49+
SnapshotFrequency time.Duration
50+
ParseLicenseJWT func(lic *License) error
5851
}
5952

6053
// New constructs a reporter for telemetry data.
@@ -242,31 +235,24 @@ func (r *remoteReporter) deployment() error {
242235
}
243236

244237
data, err := json.Marshal(&Deployment{
245-
ID: r.options.DeploymentID,
246-
Architecture: sysInfo.Architecture,
247-
BuiltinPostgres: r.options.BuiltinPostgres,
248-
Containerized: containerized,
249-
Wildcard: r.options.Wildcard,
250-
DERPServerRelayURL: r.options.DERPServerRelayURL,
251-
GitAuth: r.options.GitAuth,
252-
Kubernetes: os.Getenv("KUBERNETES_SERVICE_HOST") != "",
253-
GitHubOAuth: r.options.GitHubOAuth,
254-
OIDCAuth: r.options.OIDCAuth,
255-
OIDCIssuerURL: r.options.OIDCIssuerURL,
256-
Prometheus: r.options.Prometheus,
257-
InstallSource: installSource,
258-
STUN: r.options.STUN,
259-
Tunnel: r.options.Tunnel,
260-
OSType: sysInfo.OS.Type,
261-
OSFamily: sysInfo.OS.Family,
262-
OSPlatform: sysInfo.OS.Platform,
263-
OSName: sysInfo.OS.Name,
264-
OSVersion: sysInfo.OS.Version,
265-
CPUCores: runtime.NumCPU(),
266-
MemoryTotal: mem.Total,
267-
MachineID: sysInfo.UniqueID,
268-
StartedAt: r.startedAt,
269-
ShutdownAt: r.shutdownAt,
238+
ID: r.options.DeploymentID,
239+
Architecture: sysInfo.Architecture,
240+
BuiltinPostgres: r.options.BuiltinPostgres,
241+
Containerized: containerized,
242+
Config: r.options.DeploymentConfig,
243+
Kubernetes: os.Getenv("KUBERNETES_SERVICE_HOST") != "",
244+
InstallSource: installSource,
245+
Tunnel: r.options.Tunnel,
246+
OSType: sysInfo.OS.Type,
247+
OSFamily: sysInfo.OS.Family,
248+
OSPlatform: sysInfo.OS.Platform,
249+
OSName: sysInfo.OS.Name,
250+
OSVersion: sysInfo.OS.Version,
251+
CPUCores: runtime.NumCPU(),
252+
MemoryTotal: mem.Total,
253+
MachineID: sysInfo.UniqueID,
254+
StartedAt: r.startedAt,
255+
ShutdownAt: r.shutdownAt,
270256
})
271257
if err != nil {
272258
return xerrors.Errorf("marshal deployment: %w", err)
@@ -481,10 +467,6 @@ func (r *remoteReporter) createSnapshot() (*Snapshot, error) {
481467
}
482468
return nil
483469
})
484-
eg.Go(func() error {
485-
snapshot.Experiments = ConvertExperiments(r.options.Experiments)
486-
return nil
487-
})
488470

489471
err := eg.Wait()
490472
if err != nil {
@@ -745,16 +727,6 @@ func ConvertExternalProvisioner(id uuid.UUID, tags map[string]string, provisione
745727
}
746728
}
747729

748-
func ConvertExperiments(experiments []string) []Experiment {
749-
var out []Experiment
750-
751-
for _, exp := range experiments {
752-
out = append(out, Experiment{Name: exp})
753-
}
754-
755-
return out
756-
}
757-
758730
// Snapshot represents a point-in-time anonymized database dump.
759731
// Data is aggregated by latest on the server-side, so partial data
760732
// can be sent without issue.
@@ -777,40 +749,28 @@ type Snapshot struct {
777749
WorkspaceResourceMetadata []WorkspaceResourceMetadata `json:"workspace_resource_metadata"`
778750
WorkspaceResources []WorkspaceResource `json:"workspace_resources"`
779751
Workspaces []Workspace `json:"workspaces"`
780-
Experiments []Experiment `json:"experiments"`
781752
}
782753

783754
// Deployment contains information about the host running Coder.
784755
type Deployment struct {
785-
ID string `json:"id"`
786-
Architecture string `json:"architecture"`
787-
BuiltinPostgres bool `json:"builtin_postgres"`
788-
Containerized bool `json:"containerized"`
789-
Kubernetes bool `json:"kubernetes"`
790-
Tunnel bool `json:"tunnel"`
791-
Wildcard bool `json:"wildcard"`
792-
DERPServerRelayURL string `json:"derp_server_relay_url"`
793-
GitAuth []GitAuth `json:"git_auth"`
794-
GitHubOAuth bool `json:"github_oauth"`
795-
OIDCAuth bool `json:"oidc_auth"`
796-
OIDCIssuerURL string `json:"oidc_issuer_url"`
797-
Prometheus bool `json:"prometheus"`
798-
InstallSource string `json:"install_source"`
799-
STUN bool `json:"stun"`
800-
OSType string `json:"os_type"`
801-
OSFamily string `json:"os_family"`
802-
OSPlatform string `json:"os_platform"`
803-
OSName string `json:"os_name"`
804-
OSVersion string `json:"os_version"`
805-
CPUCores int `json:"cpu_cores"`
806-
MemoryTotal uint64 `json:"memory_total"`
807-
MachineID string `json:"machine_id"`
808-
StartedAt time.Time `json:"started_at"`
809-
ShutdownAt *time.Time `json:"shutdown_at"`
810-
}
811-
812-
type GitAuth struct {
813-
Type string `json:"type"`
756+
ID string `json:"id"`
757+
Architecture string `json:"architecture"`
758+
BuiltinPostgres bool `json:"builtin_postgres"`
759+
Containerized bool `json:"containerized"`
760+
Kubernetes bool `json:"kubernetes"`
761+
Config *codersdk.DeploymentValues `json:"config"`
762+
Tunnel bool `json:"tunnel"`
763+
InstallSource string `json:"install_source"`
764+
OSType string `json:"os_type"`
765+
OSFamily string `json:"os_family"`
766+
OSPlatform string `json:"os_platform"`
767+
OSName string `json:"os_name"`
768+
OSVersion string `json:"os_version"`
769+
CPUCores int `json:"cpu_cores"`
770+
MemoryTotal uint64 `json:"memory_total"`
771+
MachineID string `json:"machine_id"`
772+
StartedAt time.Time `json:"started_at"`
773+
ShutdownAt *time.Time `json:"shutdown_at"`
814774
}
815775

816776
type APIKey struct {
@@ -985,10 +945,6 @@ type ExternalProvisioner struct {
985945
ShutdownAt *time.Time `json:"shutdown_at"`
986946
}
987947

988-
type Experiment struct {
989-
Name string `json:"name"`
990-
}
991-
992948
type noopReporter struct{}
993949

994950
func (*noopReporter) Report(_ *Snapshot) {}

coderd/telemetry/telemetry_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,6 @@ func TestTelemetry(t *testing.T) {
114114
require.Len(t, snapshot.Users, 1)
115115
require.Equal(t, snapshot.Users[0].EmailHashed, "bb44bf07cf9a2db0554bba63a03d822c927deae77df101874496df5a6a3e896d@coder.com")
116116
})
117-
t.Run("Experiments", func(t *testing.T) {
118-
t.Parallel()
119-
120-
const expName = "my-experiment"
121-
exps := []string{expName}
122-
_, snapshot := collectSnapshot(t, dbmem.New(), func(opts telemetry.Options) telemetry.Options {
123-
opts.Experiments = exps
124-
return opts
125-
})
126-
require.Equal(t, []telemetry.Experiment{{Name: expName}}, snapshot.Experiments)
127-
})
128117
}
129118

130119
// nolint:paralleltest

codersdk/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ type ExternalAuthConfig struct {
393393
AppInstallationsURL string `json:"app_installations_url" yaml:"app_installations_url"`
394394
NoRefresh bool `json:"no_refresh" yaml:"no_refresh"`
395395
Scopes []string `json:"scopes" yaml:"scopes"`
396-
ExtraTokenKeys []string `json:"extra_token_keys" yaml:"extra_token_keys"`
396+
ExtraTokenKeys []string `json:"-" yaml:"extra_token_keys"`
397397
DeviceFlow bool `json:"device_flow" yaml:"device_flow"`
398398
DeviceCodeURL string `json:"device_code_url" yaml:"device_code_url"`
399399
// Regex allows API requesters to match an auth config by

docs/api/general.md

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/schemas.md

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/api/typesGenerated.ts

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/pages/DeploySettingsPage/ExternalAuthSettingsPage/ExternalAuthSettingsPageView.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const meta: Meta<typeof ExternalAuthSettingsPageView> = {
1919
app_installations_url: "",
2020
no_refresh: false,
2121
scopes: [],
22-
extra_token_keys: [],
2322
device_flow: true,
2423
device_code_url: "",
2524
display_icon: "",

0 commit comments

Comments
 (0)