8000 chore: add additional network telemetry stats & events by ethanndickson · Pull Request #13800 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore: add additional network telemetry stats & events #13800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 10, 2024
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
Prev Previous commit
Next Next commit
ensure latest derpmap
  • Loading branch information
ethanndickson committed Jul 9, 2024
commit fe7252a5bf78300ef9c5b7b0a506ba923d441120
5 changes: 3 additions & 2 deletions tailnet/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,16 @@ func (c *configMaps) getBlockEndpoints() bool {
// setDERPMap sets the DERP map, triggering a configuration of the engine if it has changed.
// c.L MUST NOT be held.
// Returns if the derpMap is dirty.
func (c *configMaps) setDERPMap(derpMap *tailcfg.DERPMap) {
func (c *configMaps) setDERPMap(derpMap *tailcfg.DERPMap) bool {
c.L.Lock()
defer c.L.Unlock()
if CompareDERPMaps(c.derpMap, derpMap) {
return
return false
}
c.derpMap = derpMap
c.derpMapDirty = true
c.Broadcast()
return true
}

// derMapLocked returns the current DERPMap. c.L must be held
Expand Down
6 changes: 4 additions & 2 deletions tailnet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ func (c *Conn) SetNodeCallback(callback func(node *Node)) {

// SetDERPMap updates the DERPMap of a connection.
func (c *Conn) SetDERPMap(derpMap *tailcfg.DERPMap) {
c.configMaps.setDERPMap(derpMap)
if c.configMaps.setDERPMap(derpMap) && c.telemetryStore != nil {
c.telemetryStore.updateDerpMap(derpMap)
}
}

func (c *Conn) SetDERPForceWebSockets(v bool) {
Expand Down Expand Up @@ -814,7 +816,7 @@ func (c *Conn) watchConnChange() {
}
peer := status.Peer[peers[0]]
// If the connection type has changed, send a telemetry event with the latest ping stats
if c.telemetryStore.checkConnType(peer.Relay) && c.telemetryStore.connectedIP != nil {
if c.telemetryStore.changedConntype(peer.Relay) && c.telemetryStore.connectedIP != nil {
_, _, _, _ = c.Ping(c.watchCtx, *c.telemetryStore.connectedIP)
}
}
Expand Down
10 changes: 8 additions & 2 deletions tailnet/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func (b *TelemetryStore) markConnected(ip *netip.Addr, application string) {
b.application = application
}

// Return whether we've changed to/from a P2P connection
func (b *TelemetryStore) checkConnType(relay string) bool {
func (b *TelemetryStore) changedConntype(relay string) bool {
b.mu.Lock()
defer b.mu.Unlock()

Expand Down Expand Up @@ -141,6 +140,13 @@ func (b *TelemetryStore) updateNetworkMap(nm *netmap.NetworkMap) {
// Given a DERPMap, anonymise all IPs and hostnames.
// Keep track of seen hostnames/cert names to anonymize them from future logs.
// b.mu must NOT be held.
func (b *TelemetryStore) updateDerpMap(cur *tailcfg.DERPMap) {
b.mu.Lock()
defer b.mu.Unlock()

b.updateDerpMapLocked(cur)
}

func (b *TelemetryStore) updateDerpMapLocked(cur *tailcfg.DERPMap) {
if cur == nil {
return
Expand Down
4 changes: 1 addition & 3 deletions tailnet/telemetry_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ func TestTelemetryStore(t *testing.T) {
},
},
}
telemetry.mu.Lock()
telemetry.updateDerpMapLocked(derpMap)
telemetry.mu.Unlock()
telemetry.updateDerpMap(derpMap)

event := telemetry.newEvent()
require.Len(t, event.DerpMap.Regions[999].Nodes, 1)
Expand Down
Loading
0