deployment collects host information and reports it to the telemetry server.
()
| 306 | |
| 307 | // deployment collects host information and reports it to the telemetry server. |
| 308 | func (r *remoteReporter) deployment() error { |
| 309 | sysInfoHost, err := sysinfo.Host() |
| 310 | if err != nil { |
| 311 | return xerrors.Errorf("get host info: %w", err) |
| 312 | } |
| 313 | mem, err := sysInfoHost.Memory() |
| 314 | if err != nil { |
| 315 | return xerrors.Errorf("get memory info: %w", err) |
| 316 | } |
| 317 | sysInfo := sysInfoHost.Info() |
| 318 | |
| 319 | containerized := false |
| 320 | if sysInfo.Containerized != nil { |
| 321 | containerized = *sysInfo.Containerized |
| 322 | } |
| 323 | |
| 324 | // Tracks where Coder was installed from! |
| 325 | installSource := os.Getenv("CODER_TELEMETRY_INSTALL_SOURCE") |
| 326 | if len(installSource) > 64 { |
| 327 | return xerrors.Errorf("install source must be <=64 chars: %s", installSource) |
| 328 | } |
| 329 | |
| 330 | idpOrgSync, err := checkIDPOrgSync(r.ctx, r.options.Database, r.options.DeploymentConfig) |
| 331 | if err != nil { |
| 332 | r.options.Logger.Debug(r.ctx, "check IDP org sync", slog.Error(err)) |
| 333 | } |
| 334 | |
| 335 | data, err := json.Marshal(&Deployment{ |
| 336 | ID: r.options.DeploymentID, |
| 337 | Architecture: sysInfo.Architecture, |
| 338 | BuiltinPostgres: r.options.BuiltinPostgres, |
| 339 | Containerized: containerized, |
| 340 | Config: r.options.DeploymentConfig, |
| 341 | Kubernetes: os.Getenv("KUBERNETES_SERVICE_HOST") != "", |
| 342 | InstallSource: installSource, |
| 343 | Tunnel: r.options.Tunnel, |
| 344 | OSType: sysInfo.OS.Type, |
| 345 | OSFamily: sysInfo.OS.Family, |
| 346 | OSPlatform: sysInfo.OS.Platform, |
| 347 | OSName: sysInfo.OS.Name, |
| 348 | OSVersion: sysInfo.OS.Version, |
| 349 | CPUCores: runtime.NumCPU(), |
| 350 | MemoryTotal: mem.Total, |
| 351 | MachineID: sysInfo.UniqueID, |
| 352 | StartedAt: r.startedAt, |
| 353 | ShutdownAt: r.shutdownAt, |
| 354 | IDPOrgSync: &idpOrgSync, |
| 355 | }) |
| 356 | if err != nil { |
| 357 | return xerrors.Errorf("marshal deployment: %w", err) |
| 358 | } |
| 359 | req, err := http.NewRequestWithContext(r.ctx, "POST", r.deploymentURL.String(), bytes.NewReader(data)) |
| 360 | if err != nil { |
| 361 | return xerrors.Errorf("create deployment request: %w", err) |
| 362 | } |
| 363 | req.Header.Set(VersionHeader, buildinfo.Version()) |
| 364 | resp, err := r.client.Do(req) |
| 365 | if err != nil { |