- Notifications
You must be signed in to change notification settings - Fork928
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
+265 −90
Merged
Changes fromall commits
Commits
Show all changes
11 commits Select commitHold shift + click to select a range
34d25a1
refactor(support): move agent-related info to top level
johnstcn1092eb2
feat(support): fetch manifest, logs etc. from agent
johnstcnbef4023
chore(support): add goleak detection
johnstcnf433105
increase test timeout
johnstcnd5fb619
feat(support): add agent magicsock HTML
johnstcn8022a43
remove unused field
johnstcn779b90e
wait for conn to close
johnstcn4ccb82b
actually close connections properly
johnstcndf184a0
use workspaceagentconn methods added in #12593
johnstcn017a5ec
Merge remote-tracking branch 'origin/main' into cj/support-agent
johnstcnc29d922
address PR comments, beef up test assertions
johnstcnFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
25 changes: 16 additions & 9 deletionscli/support.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
54 changes: 45 additions & 9 deletionscli/support_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4,19 +4,26 @@ import ( | ||
"archive/zip" | ||
"encoding/json" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
"time" | ||
"tailscale.com/ipn/ipnstate" | ||
"github.com/stretchr/testify/require" | ||
"github.com/coder/coder/v2/agent" | ||
"github.com/coder/coder/v2/agent/agenttest" | ||
"github.com/coder/coder/v2/cli/clitest" | ||
"github.com/coder/coder/v2/coderd/coderdtest" | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/database/dbfake" | ||
"github.com/coder/coder/v2/coderd/database/dbtime" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/codersdk/agentsdk" | ||
"github.com/coder/coder/v2/tailnet" | ||
"github.com/coder/coder/v2/testutil" | ||
) | ||
@@ -37,7 +44,14 @@ func TestSupportBundle(t *testing.T) { | ||
}).WithAgent().Do() | ||
ws, err := client.Workspace(ctx, r.Workspace.ID) | ||
require.NoError(t, err) | ||
tempDir := t.TempDir() | ||
logPath := filepath.Join(tempDir, "coder-agent.log") | ||
require.NoError(t, os.WriteFile(logPath, []byte("hello from the agent"), 0o600)) | ||
agt := agenttest.New(t, client.URL, r.AgentToken, func(o *agent.Options) { | ||
o.LogDir = tempDir | ||
}) | ||
defer agt.Close() | ||
coderdtest.NewWorkspaceAgentWaiter(t, client, r.Workspace.ID).Wait() | ||
// Insert a provisioner job log | ||
_, err = db.InsertProvisionerJobLogs(ctx, database.InsertProvisionerJobLogsParams{ | ||
@@ -51,7 +65,7 @@ func TestSupportBundle(t *testing.T) { | ||
require.NoError(t, err) | ||
// Insert an agent log | ||
_, err = db.InsertWorkspaceAgentLogs(ctx, database.InsertWorkspaceAgentLogsParams{ | ||
AgentID:ws.LatestBuild.Resources[0].Agents[0].ID, | ||
CreatedAt: dbtime.Now(), | ||
Output: []string{"started up"}, | ||
Level: []database.LogLevel{database.LogLevelInfo}, | ||
@@ -141,22 +155,44 @@ func assertBundleContents(t *testing.T, path string) { | ||
case "network/tailnet_debug.html": | ||
bs := readBytesFromZip(t, f) | ||
require.NotEmpty(t, bs, "tailnet debug should not be empty") | ||
case "network/netcheck.json": | ||
var v codersdk.WorkspaceAgentConnectionInfo | ||
decodeJSONFromZip(t, f, &v) | ||
require.NotEmpty(t,v, "connection info should not be empty") | ||
case "workspace/workspace.json": | ||
var v codersdk.Workspace | ||
decodeJSONFromZip(t, f, &v) | ||
require.NotEmpty(t, v, "workspace should not be empty") | ||
case "workspace/build_logs.txt": | ||
bs := readBytesFromZip(t, f) | ||
require.Contains(t, string(bs), "provision done") | ||
case "agent/agent.json": | ||
var v codersdk.WorkspaceAgent | ||
decodeJSONFromZip(t, f, &v) | ||
require.NotEmpty(t, v, "agent should not be empty") | ||
case "agent/listening_ports.json": | ||
var v codersdk.WorkspaceAgentListeningPortsResponse | ||
decodeJSONFromZip(t, f, &v) | ||
require.NotEmpty(t, v, "agent listening ports should not be empty") | ||
case "agent/logs.txt": | ||
bs := readBytesFromZip(t, f) | ||
require.NotEmpty(t, bs, "logs should not be empty") | ||
case "agent/magicsock.html": | ||
bs := readBytesFromZip(t, f) | ||
require.NotEmpty(t, bs, "agent magicsock should not be empty") | ||
case "agent/manifest.json": | ||
var v agentsdk.Manifest | ||
decodeJSONFromZip(t, f, &v) | ||
require.NotEmpty(t, v, "agent manifest should not be empty") | ||
case "agent/peer_diagnostics.json": | ||
var v *tailnet.PeerDiagnostics | ||
decodeJSONFromZip(t, f, &v) | ||
require.NotEmpty(t, v, "peer diagnostics should not be empty") | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
case "agent/ping_result.json": | ||
var v *ipnstate.PingResult | ||
decodeJSONFromZip(t, f, &v) | ||
require.NotEmpty(t, v, "ping result should not be empty") | ||
case "agent/startup_logs.txt": | ||
bs := readBytesFromZip(t, f) | ||
require.Contains(t, string(bs), "started up") | ||
case "workspace/template.json": | ||
@@ -178,7 +214,7 @@ func assertBundleContents(t *testing.T, path string) { | ||
bs := readBytesFromZip(t, f) | ||
require.NotEmpty(t, bs, "logs should not be empty") | ||
default: | ||
require.Failf(t, "unexpected file in bundle", f.Name) | ||
} | ||
} | ||
} | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.