mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(support): correctly rename existing agent connection info, add real netcheck (#12946)
This commit is contained in:
+26
-12
@@ -13,6 +13,9 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
"golang.org/x/xerrors"
|
||||
"tailscale.com/ipn/ipnstate"
|
||||
"tailscale.com/net/netcheck"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
@@ -46,9 +49,16 @@ type Deployment struct {
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
CoordinatorDebug string `json:"coordinator_debug"`
|
||||
TailnetDebug string `json:"tailnet_debug"`
|
||||
Netcheck *workspacesdk.AgentConnectionInfo `json:"netcheck"`
|
||||
ConnectionInfo workspacesdk.AgentConnectionInfo
|
||||
CoordinatorDebug string `json:"coordinator_debug"`
|
||||
Netcheck *derphealth.Report `json:"netcheck"`
|
||||
TailnetDebug string `json:"tailnet_debug"`
|
||||
}
|
||||
|
||||
type Netcheck struct {
|
||||
Report *netcheck.Report `json:"report"`
|
||||
Error string `json:"error"`
|
||||
Logs []string `json:"logs"`
|
||||
}
|
||||
|
||||
type Workspace struct {
|
||||
@@ -62,6 +72,7 @@ type Workspace struct {
|
||||
|
||||
type Agent struct {
|
||||
Agent *codersdk.WorkspaceAgent `json:"agent"`
|
||||
ConnectionInfo *workspacesdk.AgentConnectionInfo `json:"connection_info"`
|
||||
ListeningPorts *codersdk.WorkspaceAgentListeningPortsResponse `json:"listening_ports"`
|
||||
Logs []byte `json:"logs"`
|
||||
ClientMagicsockHTML []byte `json:"client_magicsock_html"`
|
||||
@@ -136,7 +147,7 @@ func DeploymentInfo(ctx context.Context, client *codersdk.Client, log slog.Logge
|
||||
return d
|
||||
}
|
||||
|
||||
func NetworkInfo(ctx context.Context, client *codersdk.Client, log slog.Logger, agentID uuid.UUID) Network {
|
||||
func NetworkInfo(ctx context.Context, client *codersdk.Client, log slog.Logger) Network {
|
||||
var (
|
||||
n Network
|
||||
eg errgroup.Group
|
||||
@@ -171,15 +182,18 @@ func NetworkInfo(ctx context.Context, client *codersdk.Client, log slog.Logger,
|
||||
})
|
||||
|
||||
eg.Go(func() error {
|
||||
if agentID == uuid.Nil {
|
||||
log.Warn(ctx, "agent id required for agent connection info")
|
||||
// Need connection info to get DERP map for netcheck
|
||||
connInfo, err := workspacesdk.New(client).AgentConnectionInfoGeneric(ctx)
|
||||
if err != nil {
|
||||
log.Warn(ctx, "unable to fetch generic agent connection info")
|
||||
return nil
|
||||
}
|
||||
connInfo, err := workspacesdk.New(client).AgentConnectionInfo(ctx, agentID)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("fetch agent conn info: %w", err)
|
||||
}
|
||||
n.Netcheck = &connInfo
|
||||
n.ConnectionInfo = connInfo
|
||||
var rpt derphealth.Report
|
||||
rpt.Run(ctx, &derphealth.ReportOptions{
|
||||
DERPMap: connInfo.DERPMap,
|
||||
})
|
||||
n.Netcheck = &rpt
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -482,7 +496,7 @@ func Run(ctx context.Context, d *Deps) (*Bundle, error) {
|
||||
return nil
|
||||
})
|
||||
eg.Go(func() error {
|
||||
ni := NetworkInfo(ctx, d.Client, d.Log, d.AgentID)
|
||||
ni := NetworkInfo(ctx, d.Client, d.Log)
|
||||
b.Network = ni
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -62,9 +62,10 @@ func TestRun(t *testing.T) {
|
||||
assertSanitizedDeploymentConfig(t, bun.Deployment.Config)
|
||||
assertNotNilNotEmpty(t, bun.Deployment.HealthReport, "deployment health report should be present")
|
||||
assertNotNilNotEmpty(t, bun.Deployment.Experiments, "deployment experiments should be present")
|
||||
assertNotNilNotEmpty(t, bun.Network.ConnectionInfo, "agent connection info should be present")
|
||||
assertNotNilNotEmpty(t, bun.Network.CoordinatorDebug, "network coordinator debug should be present")
|
||||
assertNotNilNotEmpty(t, bun.Network.TailnetDebug, "network tailnet debug should be present")
|
||||
assertNotNilNotEmpty(t, bun.Network.Netcheck, "network netcheck should be present")
|
||||
assertNotNilNotEmpty(t, bun.Network.TailnetDebug, "network tailnet debug should be present")
|
||||
assertNotNilNotEmpty(t, bun.Workspace.Workspace, "workspace should be present")
|
||||
assertSanitizedWorkspace(t, bun.Workspace.Workspace)
|
||||
assertNotNilNotEmpty(t, bun.Workspace.BuildLogs, "workspace build logs should be present")
|
||||
@@ -109,9 +110,10 @@ func TestRun(t *testing.T) {
|
||||
assertSanitizedDeploymentConfig(t, bun.Deployment.Config)
|
||||
assertNotNilNotEmpty(t, bun.Deployment.HealthReport, "deployment health report should be present")
|
||||
assertNotNilNotEmpty(t, bun.Deployment.Experiments, "deployment experiments should be present")
|
||||
assertNotNilNotEmpty(t, bun.Network.ConnectionInfo, "agent connection info should be present")
|
||||
assertNotNilNotEmpty(t, bun.Network.CoordinatorDebug, "network coordinator debug should be present")
|
||||
assertNotNilNotEmpty(t, bun.Network.Netcheck, "network netcheck should be present")
|
||||
assertNotNilNotEmpty(t, bun.Network.TailnetDebug, "network tailnet debug should be present")
|
||||
assert.Empty(t, bun.Network.Netcheck, "did not expect netcheck to be present")
|
||||
assert.Empty(t, bun.Workspace.Workspace, "did not expect workspace to be present")
|
||||
assert.Empty(t, bun.Agent, "did not expect agent to be present")
|
||||
assertNotNilNotEmpty(t, bun.Logs, "bundle logs should be present")
|
||||
|
||||
Reference in New Issue
Block a user