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:
Spike Curtis
2024-02-27 22:04:46 +04:00
committed by GitHub
parent 32691e67e6
commit 4e7beee102
11 changed files with 503 additions and 8 deletions

View File

@ -36,6 +36,7 @@ type nodeUpdater struct {
addresses []netip.Prefix
lastStatus time.Time
blockEndpoints bool
sentNode bool // for PeerDiagnostics
}
// updateLoop waits until the config is dirty and then calls the callback with the newest node.
@ -79,6 +80,7 @@ func (u *nodeUpdater) updateLoop() {
u.logger.Debug(context.Background(), "calling nodeUpdater callback", slog.F("node", node))
callback(node)
u.L.Lock()
u.sentNode = true
}
}
@ -212,6 +214,7 @@ func (u *nodeUpdater) setCallback(callback func(node *Node)) {
defer u.L.Unlock()
u.callback = callback
u.dirty = true
u.sentNode = false
u.Broadcast()
}
@ -228,3 +231,11 @@ func (u *nodeUpdater) setBlockEndpoints(blockEndpoints bool) {
u.blockEndpoints = blockEndpoints
u.Broadcast()
}
// fillPeerDiagnostics fills out the PeerDiagnostics with PreferredDERP and SentNode
func (u *nodeUpdater) fillPeerDiagnostics(d *PeerDiagnostics) {
u.L.Lock()
defer u.L.Unlock()
d.PreferredDERP = u.preferredDERP
d.SentNode = u.sentNode
}