(ctx context.Context, client *codersdk.Client, log slog.Logger)
| 364 | } |
| 365 | |
| 366 | func NetworkInfo(ctx context.Context, client *codersdk.Client, log slog.Logger) Network { |
| 367 | var ( |
| 368 | n Network |
| 369 | eg errgroup.Group |
| 370 | ) |
| 371 | |
| 372 | eg.Go(func() error { |
| 373 | coordResp, err := client.Request(ctx, http.MethodGet, "/api/v2/debug/coordinator", nil) |
| 374 | if err != nil { |
| 375 | return xerrors.Errorf("fetch coordinator debug page: %w", err) |
| 376 | } |
| 377 | defer coordResp.Body.Close() |
| 378 | if coordResp.StatusCode == http.StatusForbidden || coordResp.StatusCode == http.StatusUnauthorized { |
| 379 | _, _ = io.Copy(io.Discard, coordResp.Body) |
| 380 | log.Warn(ctx, "unable to fetch coordinator debug page", |
| 381 | slog.F("status", coordResp.StatusCode)) |
| 382 | return nil |
| 383 | } |
| 384 | bs, err := io.ReadAll(coordResp.Body) |
| 385 | if err != nil { |
| 386 | return xerrors.Errorf("read coordinator debug page: %w", err) |
| 387 | } |
| 388 | n.CoordinatorDebug = string(bs) |
| 389 | return nil |
| 390 | }) |
| 391 | |
| 392 | eg.Go(func() error { |
| 393 | tailResp, err := client.Request(ctx, http.MethodGet, "/api/v2/debug/tailnet", nil) |
| 394 | if err != nil { |
| 395 | return xerrors.Errorf("fetch tailnet debug page: %w", err) |
| 396 | } |
| 397 | defer tailResp.Body.Close() |
| 398 | if tailResp.StatusCode == http.StatusForbidden || tailResp.StatusCode == http.StatusUnauthorized { |
| 399 | _, _ = io.Copy(io.Discard, tailResp.Body) |
| 400 | log.Warn(ctx, "unable to fetch tailnet debug page", |
| 401 | slog.F("status", tailResp.StatusCode)) |
| 402 | return nil |
| 403 | } |
| 404 | bs, err := io.ReadAll(tailResp.Body) |
| 405 | if err != nil { |
| 406 | return xerrors.Errorf("read tailnet debug page: %w", err) |
| 407 | } |
| 408 | n.TailnetDebug = string(bs) |
| 409 | return nil |
| 410 | }) |
| 411 | |
| 412 | eg.Go(func() error { |
| 413 | // Need connection info to get DERP map for netcheck |
| 414 | connInfo, err := workspacesdk.New(client).AgentConnectionInfoGeneric(ctx) |
| 415 | if err != nil { |
| 416 | log.Warn(ctx, "unable to fetch generic agent connection info") |
| 417 | return nil |
| 418 | } |
| 419 | n.ConnectionInfo = connInfo |
| 420 | var rpt derphealth.Report |
| 421 | rpt.Run(ctx, &derphealth.ReportOptions{ |
| 422 | DERPMap: connInfo.DERPMap, |
| 423 | }) |
no test coverage detected