Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add debug endpoint for single tailnet
  • Loading branch information
coadler committed Nov 1, 2023
commit 76a2d76167302811c1a43d93a6fcb473e34bdf94
1 change: 1 addition & 0 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ func New(options *Options) *API {
)

r.Get("/coordinator", api.debugCoordinator)
r.Get("/tailnet", api.debugTailnet)
r.Get("/health", api.debugDeploymentHealth)
r.Get("/ws", (&healthcheck.WebsocketEchoServer{}).ServeHTTP)
})
Expand Down
11 changes: 11 additions & 0 deletions coderd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ func (api *API) debugCoordinator(rw http.ResponseWriter, r *http.Request) {
(*api.TailnetCoordinator.Load()).ServeHTTPDebug(rw, r)
}

// @Summary Debug Info Tailnet
// @ID debug-info-wireguard-coordinator
// @Security CoderSessionToken
// @Produce text/html
// @Tags Debug
// @Success 200
// @Router /debug/tailnet [get]
func (api *API) debugTailnet(rw http.ResponseWriter, r *http.Request) {
api.agentProvider.ServeHTTPDebug(rw, r)
}

// @Summary Debug Info Deployment Health
// @ID debug-info-deployment-health
// @Security CoderSessionToken
Expand Down
7 changes: 7 additions & 0 deletions coderd/tailnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"cdr.dev/slog"
"github.com/coder/coder/v2/coderd/tracing"
"github.com/coder/coder/v2/coderd/workspaceapps"
"github.com/coder/coder/v2/coderd/wsconncache"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/site"
Expand All @@ -38,6 +39,8 @@ func init() {
}
}

var _ workspaceapps.AgentProvider = (*ServerTailnet)(nil)

// NewServerTailnet creates a new tailnet intended for use by coderd. It
// automatically falls back to wsconncache if a legacy agent is encountered.
func NewServerTailnet(
Expand Down Expand Up @@ -419,6 +422,10 @@ func (s *ServerTailnet) DialAgentNetConn(ctx context.Context, agentID uuid.UUID,
}}, err
}

func (s *ServerTailnet) ServeHTTPDebug(w http.ResponseWriter, r *http.Request) {
s.conn.MagicsockServeHTTPDebug(w, r)
}

type netConnCloser struct {
net.Conn
close func()
Expand Down
2 changes: 2 additions & 0 deletions coderd/workspaceapps/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type AgentProvider interface {
// func.
AgentConn(ctx context.Context, agentID uuid.UUID) (_ *codersdk.WorkspaceAgentConn, release func(), _ error)

ServeHTTPDebug(w http.ResponseWriter, r *http.Request)

Close() error
}

Expand Down
5 changes: 5 additions & 0 deletions coderd/wsconncache/wsconncache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import (
"golang.org/x/sync/singleflight"
"golang.org/x/xerrors"

"github.com/coder/coder/v2/coderd/workspaceapps"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/site"
)

var _ workspaceapps.AgentProvider = (*AgentProvider)(nil)

type AgentProvider struct {
Cache *Cache
}
Expand Down Expand Up @@ -56,6 +59,8 @@ func (a *AgentProvider) ReverseProxy(targetURL *url.URL, dashboardURL *url.URL,
return proxy, release, nil
}

func (*AgentProvider) ServeHTTPDebug(http.ResponseWriter, *http.Request) {}

func (a *AgentProvider) Close() error {
return a.Cache.Close()
}
Expand Down