Skip to content

Commit fefacc5

Browse files
authored
chore: Expose additional agent options to telemetry (#5070)
This also adds a few properties for deployments!
1 parent 9692cc2 commit fefacc5

File tree

2 files changed

+119
-81
lines changed

2 files changed

+119
-81
lines changed

cli/server.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -509,18 +509,28 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
509509
return xerrors.Errorf("parse telemetry url: %w", err)
510510
}
511511

512+
gitAuth := make([]telemetry.GitAuth, 0)
513+
for _, cfg := range gitAuthConfigs {
514+
gitAuth = append(gitAuth, telemetry.GitAuth{
515+
Type: string(cfg.Type),
516+
})
517+
}
518+
512519
options.Telemetry, err = telemetry.New(telemetry.Options{
513-
BuiltinPostgres: builtinPostgres,
514-
DeploymentID: deploymentID,
515-
Database: options.Database,
516-
Logger: logger.Named("telemetry"),
517-
URL: telemetryURL,
518-
GitHubOAuth: cfg.OAuth2.Github.ClientID.Value != "",
519-
OIDCAuth: cfg.OIDC.ClientID.Value != "",
520-
OIDCIssuerURL: cfg.OIDC.IssuerURL.Value,
521-
Prometheus: cfg.Prometheus.Enable.Value,
522-
STUN: len(cfg.DERP.Server.STUNAddresses.Value) != 0,
523-
Tunnel: tunnel != nil,
520+
BuiltinPostgres: builtinPostgres,
521+
DeploymentID: deploymentID,
522+
Database: options.Database,
523+
Logger: logger.Named("telemetry"),
524+
URL: telemetryURL,
525+
Wildcard: cfg.WildcardAccessURL.Value != "",
526+
DERPServerRelayURL: cfg.DERP.Server.RelayURL.Value,
527+
GitAuth: gitAuth,
528+
GitHubOAuth: cfg.OAuth2.Github.ClientID.Value != "",
529+
OIDCAuth: cfg.OIDC.ClientID.Value != "",
530+
OIDCIssuerURL: cfg.OIDC.IssuerURL.Value,
531+
Prometheus: cfg.Prometheus.Enable.Value,
532+
STUN: len(cfg.DERP.Server.STUNAddresses.Value) != 0,
533+
Tunnel: tunnel != nil,
524534
})
525535
if err != nil {
526536
return xerrors.Errorf("create telemetry reporter: %w", err)

coderd/telemetry/telemetry.go

Lines changed: 98 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ type Options struct {
3939
// URL is an endpoint to direct telemetry towards!
4040
URL *url.URL
4141

42-
BuiltinPostgres bool
43-
DeploymentID string
44-
GitHubOAuth bool
45-
OIDCAuth bool
46-
OIDCIssuerURL string
47-
Prometheus bool
48-
STUN bool
49-
SnapshotFrequency time.Duration
50-
Tunnel bool
42+
BuiltinPostgres bool
43+
DeploymentID string
44+
GitHubOAuth bool
45+
OIDCAuth bool
46+
OIDCIssuerURL string
47+
Wildcard bool
48+
DERPServerRelayURL string
49+
GitAuth []GitAuth
50+
Prometheus bool
51+
STUN bool
52+
SnapshotFrequency time.Duration
53+
Tunnel bool
5154
}
5255

5356
// New constructs a reporter for telemetry data.
@@ -228,27 +231,30 @@ func (r *remoteReporter) deployment() error {
228231
containerized = *sysInfo.Containerized
229232
}
230233
data, err := json.Marshal(&Deployment{
231-
ID: r.options.DeploymentID,
232-
Architecture: sysInfo.Architecture,
233-
BuiltinPostgres: r.options.BuiltinPostgres,
234-
Containerized: containerized,
235-
Kubernetes: os.Getenv("KUBERNETES_SERVICE_HOST") != "",
236-
GitHubOAuth: r.options.GitHubOAuth,
237-
OIDCAuth: r.options.OIDCAuth,
238-
OIDCIssuerURL: r.options.OIDCIssuerURL,
239-
Prometheus: r.options.Prometheus,
240-
STUN: r.options.STUN,
241-
Tunnel: r.options.Tunnel,
242-
OSType: sysInfo.OS.Type,
243-
OSFamily: sysInfo.OS.Family,
244-
OSPlatform: sysInfo.OS.Platform,
245-
OSName: sysInfo.OS.Name,
246-
OSVersion: sysInfo.OS.Version,
247-
CPUCores: runtime.NumCPU(),
248-
MemoryTotal: mem.Total,
249-
MachineID: sysInfo.UniqueID,
250-
StartedAt: r.startedAt,
251-
ShutdownAt: r.shutdownAt,
234+
ID: r.options.DeploymentID,
235+
Architecture: sysInfo.Architecture,
236+
BuiltinPostgres: r.options.BuiltinPostgres,
237+
Containerized: containerized,
238+
Wildcard: r.options.Wildcard,
239+
DERPServerRelayURL: r.options.DERPServerRelayURL,
240+
GitAuth: r.options.GitAuth,
241+
Kubernetes: os.Getenv("KUBERNETES_SERVICE_HOST") != "",
242+
GitHubOAuth: r.options.GitHubOAuth,
243+
OIDCAuth: r.options.OIDCAuth,
244+
OIDCIssuerURL: r.options.OIDCIssuerURL,
245+
Prometheus: r.options.Prometheus,
246+
STUN: r.options.STUN,
247+
Tunnel: r.options.Tunnel,
248+
OSType: sysInfo.OS.Type,
249+
OSFamily: sysInfo.OS.Family,
250+
OSPlatform: sysInfo.OS.Platform,
251+
OSName: sysInfo.OS.Name,
252+
OSVersion: sysInfo.OS.Version,
253+
CPUCores: runtime.NumCPU(),
254+
MemoryTotal: mem.Total,
255+
MachineID: sysInfo.UniqueID,
256+
StartedAt: r.startedAt,
257+
ShutdownAt: r.shutdownAt,
252258
})
253259
if err != nil {
254260
return xerrors.Errorf("marshal deployment: %w", err)
@@ -512,17 +518,28 @@ func ConvertProvisionerJob(job database.ProvisionerJob) ProvisionerJob {
512518

513519
// ConvertWorkspaceAgent anonymizes a workspace agent.
514520
func ConvertWorkspaceAgent(agent database.WorkspaceAgent) WorkspaceAgent {
515-
return WorkspaceAgent{
516-
ID: agent.ID,
517-
CreatedAt: agent.CreatedAt,
518-
ResourceID: agent.ResourceID,
519-
InstanceAuth: agent.AuthInstanceID.Valid,
520-
Architecture: agent.Architecture,
521-
OperatingSystem: agent.OperatingSystem,
522-
EnvironmentVariables: agent.EnvironmentVariables.Valid,
523-
StartupScript: agent.StartupScript.Valid,
524-
Directory: agent.Directory != "",
521+
snapAgent := WorkspaceAgent{
522+
ID: agent.ID,
523+
CreatedAt: agent.CreatedAt,
524+
ResourceID: agent.ResourceID,
525+
InstanceAuth: agent.AuthInstanceID.Valid,
526+
Architecture: agent.Architecture,
527+
OperatingSystem: agent.OperatingSystem,
528+
EnvironmentVariables: agent.EnvironmentVariables.Valid,
529+
StartupScript: agent.StartupScript.Valid,
530+
Directory: agent.Directory != "",
531+
ConnectionTimeoutSeconds: agent.ConnectionTimeoutSeconds,
525532
}
533+
if agent.FirstConnectedAt.Valid {
534+
snapAgent.FirstConnectedAt = &agent.FirstConnectedAt.Time
535+
}
536+
if agent.LastConnectedAt.Valid {
537+
snapAgent.LastConnectedAt = &agent.LastConnectedAt.Time
538+
}
539+
if agent.DisconnectedAt.Valid {
540+
snapAgent.DisconnectedAt = &agent.DisconnectedAt.Time
541+
}
542+
return snapAgent
526543
}
527544

528545
// ConvertWorkspaceApp anonymizes a workspace app.
@@ -625,27 +642,34 @@ type Snapshot struct {
625642

626643
// Deployment contains information about the host running Coder.
627644
type Deployment struct {
628-
ID string `json:"id"`
629-
Architecture string `json:"architecture"`
630-
BuiltinPostgres bool `json:"builtin_postgres"`
631-
Containerized bool `json:"containerized"`
632-
Kubernetes bool `json:"kubernetes"`
633-
Tunnel bool `json:"tunnel"`
634-
GitHubOAuth bool `json:"github_oauth"`
635-
OIDCAuth bool `json:"oidc_auth"`
636-
OIDCIssuerURL string `json:"oidc_issuer_url"`
637-
Prometheus bool `json:"prometheus"`
638-
STUN bool `json:"stun"`
639-
OSType string `json:"os_type"`
640-
OSFamily string `json:"os_family"`
641-
OSPlatform string `json:"os_platform"`
642-
OSName string `json:"os_name"`
643-
OSVersion string `json:"os_version"`
644-
CPUCores int `json:"cpu_cores"`
645-
MemoryTotal uint64 `json:"memory_total"`
646-
MachineID string `json:"machine_id"`
647-
StartedAt time.Time `json:"started_at"`
648-
ShutdownAt *time.Time `json:"shutdown_at"`
645+
ID string `json:"id"`
646+
Architecture string `json:"architecture"`
647+
BuiltinPostgres bool `json:"builtin_postgres"`
648+
Containerized bool `json:"containerized"`
649+
Kubernetes bool `json:"kubernetes"`
650+
Tunnel bool `json:"tunnel"`
651+
Wildcard bool `json:"wildcard"`
652+
DERPServerRelayURL string `json:"derp_server_relay_url"`
653+
GitAuth []GitAuth `json:"git_auth"`
654+
GitHubOAuth bool `json:"github_oauth"`
655+
OIDCAuth bool `json:"oidc_auth"`
656+
OIDCIssuerURL string `json:"oidc_issuer_url"`
657+
Prometheus bool `json:"prometheus"`
658+
STUN bool `json:"stun"`
659+
OSType string `json:"os_type"`
660+
OSFamily string `json:"os_family"`
661+
OSPlatform string `json:"os_platform"`
662+
OSName string `json:"os_name"`
663+
OSVersion string `json:"os_version"`
664+
CPUCores int `json:"cpu_cores"`
665+
MemoryTotal uint64 `json:"memory_total"`
666+
MachineID string `json:"machine_id"`
667+
StartedAt time.Time `json:"started_at"`
668+
ShutdownAt *time.Time `json:"shutdown_at"`
669+
}
670+
671+
type GitAuth struct {
672+
Type string `json:"type"`
649673
}
650674

651675
type APIKey struct {
@@ -682,15 +706,19 @@ type WorkspaceResourceMetadata struct {
682706
}
683707

684708
type WorkspaceAgent struct {
685-
ID uuid.UUID `json:"id"`
686-
CreatedAt time.Time `json:"created_at"`
687-
ResourceID uuid.UUID `json:"resource_id"`
688-
InstanceAuth bool `json:"instance_auth"`
689-
Architecture string `json:"architecture"`
690-
OperatingSystem string `json:"operating_system"`
691-
EnvironmentVariables bool `json:"environment_variables"`
692-
StartupScript bool `json:"startup_script"`
693-
Directory bool `json:"directory"`
709+
ID uuid.UUID `json:"id"`
710+
CreatedAt time.Time `json:"created_at"`
711+
ResourceID uuid.UUID `json:"resource_id"`
712+
InstanceAuth bool `json:"instance_auth"`
713+
Architecture string `json:"architecture"`
714+
OperatingSystem string `json:"operating_system"`
715+
EnvironmentVariables bool `json:"environment_variables"`
716+
StartupScript bool `json:"startup_script"`
717+
Directory bool `json:"directory"`
718+
FirstConnectedAt *time.Time `json:"first_connected_at"`
719+
LastConnectedAt *time.Time `json:"last_connected_at"`
720+
DisconnectedAt *time.Time `json:"disconnected_at"`
721+
ConnectionTimeoutSeconds int32 `json:"connection_timeout_seconds"`
694722
}
695723

696724
type WorkspaceApp struct {

0 commit comments

Comments
 (0)