Skip to content

feat(support): fetch agent network info over tailnet #12577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 15, 2024
Prev Previous commit
address PR comments, beef up test assertions
  • Loading branch information
johnstcn committed Mar 15, 2024
commit c29d922be19b372853bd858f3d5ccbec0a859e3f
2 changes: 2 additions & 0 deletions cli/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func findAgent(agentName string, haystack []codersdk.WorkspaceResource) (*coders
}

func writeBundle(src *support.Bundle, dest *zip.Writer) error {
// We JSON-encode the following:
for k, v := range map[string]any{
"deployment/buildinfo.json": src.Deployment.BuildInfo,
"deployment/config.json": src.Deployment.Config,
Expand Down Expand Up @@ -169,6 +170,7 @@ func writeBundle(src *support.Bundle, dest *zip.Writer) error {
return xerrors.Errorf("decode template zip from base64")
}

// The below we just write as we have them:
for k, v := range map[string]string{
"network/coordinator_debug.html": src.Network.CoordinatorDebug,
"network/tailnet_debug.html": src.Network.TailnetDebug,
Expand Down
8 changes: 3 additions & 5 deletions support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Workspace struct {
}

type Agent struct {
Agent codersdk.WorkspaceAgent `json:"agent"`
Agent *codersdk.WorkspaceAgent `json:"agent"`
ListeningPorts *codersdk.WorkspaceAgentListeningPortsResponse `json:"listening_ports"`
Logs []byte `json:"logs"`
MagicsockHTML []byte `json:"magicsock_html"`
Expand Down Expand Up @@ -295,7 +295,7 @@ func AgentInfo(ctx context.Context, client *codersdk.Client, log slog.Logger, ag
if err != nil {
return xerrors.Errorf("fetch workspace agent: %w", err)
}
a.Agent = agt
a.Agent = &agt
return nil
})

Expand All @@ -313,9 +313,7 @@ func AgentInfo(ctx context.Context, client *codersdk.Client, log slog.Logger, ag
return nil
})

dialCtx, dialCancel := context.WithCancel(ctx)
defer dialCancel()
conn, err := client.DialWorkspaceAgent(dialCtx, agentID, &codersdk.DialWorkspaceAgentOptions{
conn, err := client.DialWorkspaceAgent(ctx, agentID, &codersdk.DialWorkspaceAgentOptions{
Logger: log.Named("dial-agent"),
BlockEndpoints: false,
})
Expand Down
80 changes: 44 additions & 36 deletions support/support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,34 @@ func TestRun(t *testing.T) {
AgentID: agt.ID,
})
require.NoError(t, err)
require.NotEmpty(t, bun)
require.NotEmpty(t, bun.Deployment.BuildInfo)
require.NotEmpty(t, bun.Deployment.Config)
require.NotEmpty(t, bun.Deployment.Config.Options)
assertNotNilNotEmpty(t, bun, "bundle should be present")
assertNotNilNotEmpty(t, bun.Deployment.BuildInfo, "deployment build info should be present")
assertNotNilNotEmpty(t, bun.Deployment.Config, "deployment config should be present")
assertNotNilNotEmpty(t, bun.Deployment.Config.Options, "deployment config should be present")
assertSanitizedDeploymentConfig(t, bun.Deployment.Config)
require.NotEmpty(t, bun.Deployment.HealthReport)
require.NotEmpty(t, bun.Deployment.Experiments)
require.NotEmpty(t, bun.Network.CoordinatorDebug)
require.NotEmpty(t, bun.Network.TailnetDebug)
require.NotNil(t, bun.Network.Netcheck)
require.NotNil(t, bun.Workspace.Workspace)
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.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.Workspace.Workspace, "workspace should be present")
assertSanitizedWorkspace(t, bun.Workspace.Workspace)
require.NotEmpty(t, bun.Workspace.BuildLogs)
require.NotEmpty(t, bun.Workspace.Template)
require.NotEmpty(t, bun.Workspace.TemplateVersion)
require.NotEmpty(t, bun.Workspace.TemplateFileBase64)
require.NotNil(t, bun.Workspace.Parameters)
require.NotNil(t, bun.Agent.Agent)
require.NotNil(t, bun.Agent.ListeningPorts)
require.NotNil(t, bun.Agent.Logs)
require.NotNil(t, bun.Agent.MagicsockHTML)
require.NotNil(t, bun.Agent.Manifest)
require.NotNil(t, bun.Agent.PeerDiagnostics)
require.NotNil(t, bun.Agent.PingResult)
require.NotEmpty(t, bun.Agent.StartupLogs)
require.NotEmpty(t, bun.Logs)
assertNotNilNotEmpty(t, bun.Workspace.BuildLogs, "workspace build logs should be present")
assertNotNilNotEmpty(t, bun.Workspace.Template, "workspace template should be present")
assertNotNilNotEmpty(t, bun.Workspace.TemplateVersion, "workspace template version should be present")
assertNotNilNotEmpty(t, bun.Workspace.TemplateFileBase64, "workspace template file should be present")
require.NotNil(t, bun.Workspace.Parameters, "workspace parameters should be present")
assertNotNilNotEmpty(t, bun.Agent.Agent, "agent should be present")
assertNotNilNotEmpty(t, bun.Agent.ListeningPorts, "agent listening ports should be present")
assertNotNilNotEmpty(t, bun.Agent.Logs, "agent logs should be present")
assertNotNilNotEmpty(t, bun.Agent.MagicsockHTML, "agent magicsock should be present")
assertNotNilNotEmpty(t, bun.Agent.PeerDiagnostics, "agent peer diagnostics should be present")
assertNotNilNotEmpty(t, bun.Agent.PingResult, "agent ping result should be present")
assertNotNilNotEmpty(t, bun.Agent.StartupLogs, "agent startup logs should be present")
assertNotNilNotEmpty(t, bun.Logs, "bundle logs should be present")
})

t.Run("OK_NoAgent", func(t *testing.T) {
t.Run("OK_NoWorkspace", func(t *testing.T) {
t.Parallel()
cfg := coderdtest.DeploymentValues(t)
cfg.Experiments = []string{"foo"}
Expand All @@ -98,18 +97,19 @@ func TestRun(t *testing.T) {
Log: slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Named("bundle").Leveled(slog.LevelDebug),
})
require.NoError(t, err)
require.NotEmpty(t, bun)
require.NotEmpty(t, bun.Deployment.BuildInfo)
require.NotEmpty(t, bun.Deployment.Config)
require.NotEmpty(t, bun.Deployment.Config.Options)
assertNotNilNotEmpty(t, bun, "bundle should be present")
assertNotNilNotEmpty(t, bun.Deployment.BuildInfo, "deployment build info should be present")
assertNotNilNotEmpty(t, bun.Deployment.Config, "deployment config should be present")
assertNotNilNotEmpty(t, bun.Deployment.Config.Options, "deployment config should be present")
assertSanitizedDeploymentConfig(t, bun.Deployment.Config)
require.NotEmpty(t, bun.Deployment.HealthReport)
require.NotEmpty(t, bun.Deployment.Experiments)
require.NotEmpty(t, bun.Network.CoordinatorDebug)
require.NotEmpty(t, bun.Network.TailnetDebug)
require.NotNil(t, bun.Workspace)
assertSanitizedWorkspace(t, bun.Workspace.Workspace)
require.NotEmpty(t, bun.Logs)
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.CoordinatorDebug, "network coordinator debug 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")
})

t.Run("NoAuth", func(t *testing.T) {
Expand Down Expand Up @@ -225,3 +225,11 @@ func setupWorkspaceAndAgent(ctx context.Context, t *testing.T, client *codersdk.

return ws, agt
}

func assertNotNilNotEmpty[T any](t *testing.T, v T, msg string) {
t.Helper()

if assert.NotNil(t, v, msg+" but was nil") {
assert.NotEmpty(t, v, msg+" but was empty")
}
}