Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0afee1

Browse files
authored
feat: add debug endpoint for single tailnet (#10485)
1 parent f4de2b6 commit e0afee1

File tree

9 files changed

+88
-1
lines changed

9 files changed

+88
-1
lines changed

coderd/apidoc/docs.go

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ func New(options *Options) *API {
955955
)
956956

957957
r.Get("/coordinator", api.debugCoordinator)
958+
r.Get("/tailnet", api.debugTailnet)
958959
r.Get("/health", api.debugDeploymentHealth)
959960
r.Get("/ws", (&healthcheck.WebsocketEchoServer{}).ServeHTTP)
960961
})

coderd/coderdtest/swaggerparser.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ func assertProduce(t *testing.T, comment SwaggerComment) {
352352
(comment.router == "/workspaceagents/me/startup" && comment.method == "post") ||
353353
(comment.router == "/workspaceagents/me/startup/logs" && comment.method == "patch") ||
354354
(comment.router == "/licenses/{id}" && comment.method == "delete") ||
355-
(comment.router == "/debug/coordinator" && comment.method == "get") {
355+
(comment.router == "/debug/coordinator" && comment.method == "get") ||
356+
(comment.router == "/debug/tailnet" && comment.method == "get") {
356357
return // Exception: HTTP 200 is returned without response entity
357358
}
358359

coderd/debug.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ func (api *API) debugCoordinator(rw http.ResponseWriter, r *http.Request) {
2323
(*api.TailnetCoordinator.Load()).ServeHTTPDebug(rw, r)
2424
}
2525

26+
// @Summary Debug Info Tailnet
27+
// @ID debug-info-tailnet
28+
// @Security CoderSessionToken
29+
// @Produce text/html
30+
// @Tags Debug
31+
// @Success 200
32+
// @Router /debug/tailnet [get]
33+
func (api *API) debugTailnet(rw http.ResponseWriter, r *http.Request) {
34+
api.agentProvider.ServeHTTPDebug(rw, r)
35+
}
36+
2637
// @Summary Debug Info Deployment Health
2738
// @ID debug-info-deployment-health
2839
// @Security CoderSessionToken

coderd/tailnet.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"cdr.dev/slog"
2323
"github.com/coder/coder/v2/coderd/tracing"
24+
"github.com/coder/coder/v2/coderd/workspaceapps"
2425
"github.com/coder/coder/v2/coderd/wsconncache"
2526
"github.com/coder/coder/v2/codersdk"
2627
"github.com/coder/coder/v2/site"
@@ -38,6 +39,8 @@ func init() {
3839
}
3940
}
4041

42+
var _ workspaceapps.AgentProvider = (*ServerTailnet)(nil)
43+
4144
// NewServerTailnet creates a new tailnet intended for use by coderd. It
4245
// automatically falls back to wsconncache if a legacy agent is encountered.
4346
func NewServerTailnet(
@@ -419,6 +422,10 @@ func (s *ServerTailnet) DialAgentNetConn(ctx context.Context, agentID uuid.UUID,
419422
}}, err
420423
}
421424

425+
func (s *ServerTailnet) ServeHTTPDebug(w http.ResponseWriter, r *http.Request) {
426+
s.conn.MagicsockServeHTTPDebug(w, r)
427+
}
428+
422429
type netConnCloser struct {
423430
net.Conn
424431
close func()

coderd/workspaceapps/proxy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type AgentProvider interface {
7474
// func.
7575
AgentConn(ctx context.Context, agentID uuid.UUID) (_ *codersdk.WorkspaceAgentConn, release func(), _ error)
7676

77+
ServeHTTPDebug(w http.ResponseWriter, r *http.Request)
78+
7779
Close() error
7880
}
7981

coderd/wsconncache/wsconncache.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ import (
1616
"golang.org/x/sync/singleflight"
1717
"golang.org/x/xerrors"
1818

19+
"github.com/coder/coder/v2/coderd/workspaceapps"
1920
"github.com/coder/coder/v2/codersdk"
2021
"github.com/coder/coder/v2/site"
2122
)
2223

24+
var _ workspaceapps.AgentProvider = (*AgentProvider)(nil)
25+
2326
type AgentProvider struct {
2427
Cache *Cache
2528
}
@@ -56,6 +59,8 @@ func (a *AgentProvider) ReverseProxy(targetURL *url.URL, dashboardURL *url.URL,
5659
return proxy, release, nil
5760
}
5861

62+
func (*AgentProvider) ServeHTTPDebug(http.ResponseWriter, *http.Request) {}
63+
5964
func (a *AgentProvider) Close() error {
6065
return a.Cache.Close()
6166
}

docs/api/debug.md

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)