Skip to content

Commit ed377a5

Browse files
committed
feat(agent): expose HTTP debug over tailnet api
1 parent 20e6f85 commit ed377a5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

agent/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func (a *agent) apiHandler() http.Handler {
3636
cacheDuration: cacheDuration,
3737
}
3838
r.Get("/api/v0/listening-ports", lp.handler)
39+
r.Get("/debug/magicsock", a.HandleHTTPDebugMagicsock)
40+
r.Get("/debug/magicsock/debug-logging/{state}", a.HandleHTTPMagicsockDebugLoggingState)
3941

4042
return r
4143
}

codersdk/workspaceagentconn.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,22 @@ func (c *WorkspaceAgentConn) ListeningPorts(ctx context.Context) (WorkspaceAgent
356356
return resp, json.NewDecoder(res.Body).Decode(&resp)
357357
}
358358

359+
// DebugMagicsock makes a request to the workspace agent's magicsock debug endpoint.
360+
func (c *WorkspaceAgentConn) DebugMagicsock(ctx context.Context) ([]byte, error) {
361+
ctx, span := tracing.StartSpan(ctx)
362+
defer span.End()
363+
res, err := c.apiRequest(ctx, http.MethodGet, "/debug/magicsock", nil)
364+
if err != nil {
365+
return nil, xerrors.Errorf("do request: %w", err)
366+
}
367+
defer res.Body.Close()
368+
bs, err := io.ReadAll(res.Body)
369+
if err != nil {
370+
return nil, xerrors.Errorf("read response body: %w", err)
371+
}
372+
return bs, nil
373+
}
374+
359375
// apiRequest makes a request to the workspace agent's HTTP API server.
360376
func (c *WorkspaceAgentConn) apiRequest(ctx context.Context, method, path string, body io.Reader) (*http.Response, error) {
361377
ctx, span := tracing.StartSpan(ctx)

0 commit comments

Comments
 (0)