(ctx context.Context, client *codersdk.Client, log slog.Logger, agentID uuid.UUID, eg *errgroup.Group, a *Agent)
| 582 | } |
| 583 | |
| 584 | func connectedAgentInfo(ctx context.Context, client *codersdk.Client, log slog.Logger, agentID uuid.UUID, eg *errgroup.Group, a *Agent) (closer func()) { |
| 585 | conn, err := workspacesdk.New(client). |
| 586 | DialAgent(ctx, agentID, &workspacesdk.DialAgentOptions{ |
| 587 | Logger: log.Named("dial-agent"), |
| 588 | BlockEndpoints: false, |
| 589 | }) |
| 590 | |
| 591 | closer = func() {} |
| 592 | |
| 593 | if err != nil { |
| 594 | log.Error(ctx, "dial agent", slog.Error(err)) |
| 595 | return closer |
| 596 | } |
| 597 | |
| 598 | if !conn.AwaitReachable(ctx) { |
| 599 | log.Error(ctx, "timed out waiting for agent") |
| 600 | return closer |
| 601 | } |
| 602 | |
| 603 | closer = func() { |
| 604 | if err := conn.Close(); err != nil { |
| 605 | log.Error(ctx, "failed to close agent connection", slog.Error(err)) |
| 606 | } |
| 607 | <-conn.TailnetConn().Closed() |
| 608 | } |
| 609 | |
| 610 | eg.Go(func() error { |
| 611 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost/", nil) |
| 612 | if err != nil { |
| 613 | return xerrors.Errorf("create request: %w", err) |
| 614 | } |
| 615 | rr := httptest.NewRecorder() |
| 616 | conn.TailnetConn().MagicsockServeHTTPDebug(rr, req) |
| 617 | a.ClientMagicsockHTML = rr.Body.Bytes() |
| 618 | return nil |
| 619 | }) |
| 620 | |
| 621 | eg.Go(func() error { |
| 622 | promRes, err := conn.PrometheusMetrics(ctx) |
| 623 | if err != nil { |
| 624 | return xerrors.Errorf("fetch agent prometheus metrics: %w", err) |
| 625 | } |
| 626 | a.Prometheus = promRes |
| 627 | return nil |
| 628 | }) |
| 629 | |
| 630 | eg.Go(func() error { |
| 631 | _, _, pingRes, err := conn.Ping(ctx) |
| 632 | if err != nil { |
| 633 | return xerrors.Errorf("ping agent: %w", err) |
| 634 | } |
| 635 | a.PingResult = pingRes |
| 636 | return nil |
| 637 | }) |
| 638 | |
| 639 | eg.Go(func() error { |
| 640 | pds := conn.GetPeerDiagnostics() |
| 641 | a.PeerDiagnostics = &pds |
no test coverage detected