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
send update events only when home derp changes
  • Loading branch information
ethanndickson committed Jul 8, 2024
commit ae17bb3ead50a54a49e979ad52a79b422b2bc0d6
7 changes: 4 additions & 3 deletions tailnet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ func NewConn(options *Options) (conn *Conn, err error) {
magicConn.SetDERPForcedWebsocketCallback(nodeUp.setDERPForcedWebsocket)
if telemetryStore != nil {
wireguardEngine.SetNetInfoCallback(func(ni *tailcfg.NetInfo) {
nodeUp.setNetInfo(ni)
telemetryStore.setNetInfo(ni)
nodeUp.setNetInfo(ni)
})
} else {
wireguardEngine.SetNetInfoCallback(nodeUp.setNetInfo)
Expand Down Expand Up @@ -393,8 +393,9 @@ func (c *Conn) SetAddresses(ips []netip.Prefix) error {
func (c *Conn) SetNodeCallback(callback func(node *Node)) {
if c.telemetryStore != nil {
c.nodeUpdater.setCallback(func(node *Node) {
c.telemetryStore.updateByNode(node)
c.sendUpdatedTelemetry()
if c.telemetryStore.updateByNode(node) {
c.sendUpdatedTelemetry()
}
callback(node)
})
} else {
Expand Down
25 changes: 13 additions & 12 deletions tailnet/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type TelemetryStore struct {
nodeID uint64
homeDerp int32

connSetupTime time.Duration
connSetupTime *durationpb.Duration
}

func newTelemetryStore() (*TelemetryStore, error) {
Expand All @@ -59,7 +59,7 @@ func (b *TelemetryStore) newEvent() *proto.TelemetryEvent {
LatestNetcheck: b.cleanNetCheck,
NodeIdSelf: b.nodeID,
HomeDerp: b.homeDerp,
ConnectionSetup: durationpb.New(b.connSetupTime),
ConnectionSetup: b.connSetupTime,

// TODO(ethanndickson):
P2PSetup: &durationpb.Duration{},
Expand All @@ -70,7 +70,7 @@ func (b *TelemetryStore) markConnected(connSetupTime time.Duration) {
b.mu.Lock()
defer b.mu.Unlock()

b.connSetupTime = connSetupTime
b.connSetupTime = durationpb.New(connSetupTime)
}

// Given a DERPMap, anonymise all IPs and hostnames.
Expand All @@ -97,24 +97,26 @@ func (b *TelemetryStore) updateDerpMap(cur *tailcfg.DERPMap) {
b.cleanDerpMap = cleanMap
}

func (b *TelemetryStore) updateByNode(n *Node) {
// Update the telemetry store with the current node state.
// Returns true if the home DERP has changed.
func (b *TelemetryStore) updateByNode(n *Node) bool {
b.mu.Lock()
defer b.mu.Unlock()

b.nodeID = uint64(n.ID)
b.homeDerp = int32(n.PreferredDERP)
newHome := int32(n.PreferredDERP)
if b.homeDerp != newHome {
b.homeDerp = newHome
return true
}
return false
}

// Store an anonymized proto.Netcheck given a tailscale NetInfo.
func (b *TelemetryStore) setNetInfo(ni *tailcfg.NetInfo) bool {
func (b *TelemetryStore) setNetInfo(ni *tailcfg.NetInfo) {
b.mu.Lock()
defer b.mu.Unlock()

derpHomeChanged := false
if b.cleanNetCheck != nil {
derpHomeChanged = b.cleanNetCheck.PreferredDERP != int64(ni.PreferredDERP)
}

b.cleanNetCheck = &proto.Netcheck{
UDP: ni.UDP,
IPv6: ni.IPv6,
Expand Down Expand Up @@ -152,7 +154,6 @@ func (b *TelemetryStore) setNetInfo(ni *tailcfg.NetInfo) bool {
for rid, seconds := range ni.DERPLatencyV6 {
b.cleanNetCheck.RegionV6Latency[int64(rid)] = durationpb.New(time.Duration(seconds * float64(time.Second)))
}
return derpHomeChanged
}

func (b *TelemetryStore) toEndpoint(ipport string) *proto.TelemetryEvent_P2PEndpoint {
Expand Down