8000 feat(cli): add p2p diagnostics to ping · coder/coder@6b50ee0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b50ee0

Browse files
committed
feat(cli): add p2p diagnostics to ping
1 parent c8eacc6 commit 6b50ee0

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

cli/cliui/agent.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"golang.org/x/xerrors"
1313

1414
"github.com/coder/coder/v2/codersdk"
15+
"github.com/coder/coder/v2/codersdk/workspacesdk"
1516
"github.com/coder/coder/v2/tailnet"
1617
)
1718

@@ -346,3 +347,30 @@ func PeerDiagnostics(w io.Writer, d tailnet.PeerDiagnostics) {
346347
_, _ = fmt.Fprint(w, "✘ Wireguard is not connected\n")
347348
}
348349
}
350+
351+
type ConnDiags struct {
352+
Info *workspacesdk.AgentConnectionInfo
353+
PingP2P bool
354+
// TODO: More diagnostics
355+
}
356+
357+
func ConnDiagnostics(w io.Writer, d ConnDiags) {
358+
if d.PingP2P {
359+
_, _ = fmt.Fprintln(w, "✔ You are connected directly, peer-to-peer (p2p).")
360+
return
361+
}
362+
_, _ = fmt.Fprintln(w, "❗ You are connected via a DERP relay, not directly, peer-to-peer (p2p).")
363+
364+
if d.Info == nil {
365+
return
366+
}
367+
368+
if d.Info.DisableDirectConnections {
369+
_, _ = fmt.Fprintln(w, "❗ Your Coder administrator has blocked direct connections.")
370+
return
371+
}
372+
373+
if !d.Info.DERPMap.HasSTUN() {
374+
_, _ = fmt.Fprintln(w, "✘ The workspace agent appears to be unable to reach any STUN servers.\nhttps://coder.com/docs/networking/stun")
375+
}
376+
}

cli/ping.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ func (r *RootCmd) ping() *serpent.Command {
140140
if n == int(pingNum) {
141141
diags := conn.GetPeerDiagnostics()
142142
cliui.PeerDiagnostics(inv.Stdout, diags)
143+
144+
connDiags := cliui.ConnDiags{
145+
PingP2P: didP2p,
146+
}
147+
connInfo, err := workspacesdk.New(client).AgentConnectionInfo(ctx, workspaceAgent.ID)
148+
if err == nil {
149+
connDiags.Info = &connInfo
150+
}
151+
cliui.ConnDiagnostics(inv.Stdout, connDiags)
143152
return nil
144153
}
145154
}

0 commit comments

Comments
 (0)
2945
0