mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: show tailnet peer diagnostics after coder ping (#12314)
Beginnings of a solution to #12297 Doesn't cover disco or definitively display whether we successfully connected to DERP, but shows some checklist diagnostics for connecting to an agent. For this first PR, I just added it to `coder ping` to see how we like it, but could be incorporated into `coder ssh` _et al._ after a timeout. ``` $ coder ping dogfood2 p2p connection established in 147ms pong from dogfood2 p2p via 95.217.xxx.yyy:42631 in 147ms pong from dogfood2 p2p via 95.217.xxx.yyy:42631 in 140ms pong from dogfood2 p2p via 95.217.xxx.yyy:42631 in 140ms ✔ preferred DERP region 999 (Council Bluffs, Iowa) ✔ sent local data to Coder networking coodinator ✔ received remote agent data from Coder networking coordinator preferred DERP 10013 (Europe Fly.io (Paris)) endpoints: 95.217.xxx.yyy:42631, 95.217.xxx.yyy:37576, 172.17.0.1:37576, 172.20.0.10:37576 ✔ Wireguard handshake 11s ago ```
This commit is contained in:
@@ -2,13 +2,17 @@ package cliui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
"github.com/coder/coder/v2/tailnet"
|
||||
)
|
||||
|
||||
var errAgentShuttingDown = xerrors.New("agent is shutting down")
|
||||
@@ -281,3 +285,55 @@ type closeFunc func() error
|
||||
func (c closeFunc) Close() error {
|
||||
return c()
|
||||
}
|
||||
|
||||
func PeerDiagnostics(w io.Writer, d tailnet.PeerDiagnostics) {
|
||||
if d.PreferredDERP > 0 {
|
||||
rn, ok := d.DERPRegionNames[d.PreferredDERP]
|
||||
if !ok {
|
||||
rn = "unknown"
|
||||
}
|
||||
_, _ = fmt.Fprintf(w, "✔ preferred DERP region: %d (%s)\n", d.PreferredDERP, rn)
|
||||
} else {
|
||||
_, _ = fmt.Fprint(w, "✘ not connected to DERP\n")
|
||||
}
|
||||
if d.SentNode {
|
||||
_, _ = fmt.Fprint(w, "✔ sent local data to Coder networking coodinator\n")
|
||||
} else {
|
||||
_, _ = fmt.Fprint(w, "✘ have not sent local data to Coder networking coordinator\n")
|
||||
}
|
||||
if d.ReceivedNode != nil {
|
||||
dp := d.ReceivedNode.DERP
|
||||
dn := ""
|
||||
// should be 127.3.3.40:N where N is the DERP region
|
||||
ap := strings.Split(dp, ":")
|
||||
if len(ap) == 2 {
|
||||
dp = ap[1]
|
||||
di, err := strconv.Atoi(dp)
|
||||
if err == nil {
|
||||
var ok bool
|
||||
dn, ok = d.DERPRegionNames[di]
|
||||
if ok {
|
||||
dn = fmt.Sprintf("(%s)", dn)
|
||||
} else {
|
||||
dn = "(unknown)"
|
||||
}
|
||||
}
|
||||
}
|
||||
_, _ = fmt.Fprintf(w,
|
||||
"✔ received remote agent data from Coder networking coordinator\n preferred DERP region: %s %s\n endpoints: %s\n",
|
||||
dp, dn, strings.Join(d.ReceivedNode.Endpoints, ", "))
|
||||
} else {
|
||||
_, _ = fmt.Fprint(w, "✘ have not received remote agent data from Coder networking coordinator\n")
|
||||
}
|
||||
if !d.LastWireguardHandshake.IsZero() {
|
||||
ago := time.Since(d.LastWireguardHandshake)
|
||||
symbol := "✔"
|
||||
// wireguard is supposed to refresh handshake on 5 minute intervals
|
||||
if ago > 5*time.Minute {
|
||||
symbol = "⚠"
|
||||
}
|
||||
_, _ = fmt.Fprintf(w, "%s Wireguard handshake %s ago\n", symbol, ago.Round(time.Second))
|
||||
} else {
|
||||
_, _ = fmt.Fprint(w, "✘ Wireguard is not connected\n")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user