Skip to content

Commit 11f2a2b

Browse files
committed
use latest p2p setup time
1 parent 6a19849 commit 11f2a2b

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

tailnet/conn.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ func (c *Conn) SendConnectedTelemetry(ip netip.Addr, application string) {
732732
if c.telemetrySink == nil {
733733
return
734734
}
735-
c.telemetryStore.markConnected(&ip, c.createdAt, application)
735+
c.telemetryStore.markConnected(&ip, application)
736736
e := c.newTelemetryEvent()
737737
e.Status = proto.TelemetryEvent_CONNECTED
738738
c.sendTelemetryBackground(e)
@@ -768,7 +768,6 @@ func (c *Conn) sendPingTelemetry(pr *ipnstate.PingResult) {
768768
if pr.Endpoint != "" {
769769
e.P2PLatency = latency
770770
e.P2PEndpoint = c.telemetryStore.toEndpoint(pr.Endpoint)
771-
e.P2PSetup = durationpb.New(time.Since(c.createdAt))
772771
} else {
773772
e.DerpLatency = latency
774773
}

tailnet/telemetry.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ type TelemetryStore struct {
4343
// 0 if not connected
4444
nodeIDRemote uint64
4545
p2p bool
46+
47+
p2pSetupTime time.Duration
48+
lastDerpTime time.Time
4649
}
4750

4851
func newTelemetryStore() (*TelemetryStore, error) {
@@ -61,7 +64,7 @@ func (b *TelemetryStore) newEvent() *proto.TelemetryEvent {
6164
b.mu.Lock()
6265
defer b.mu.Unlock()
6366

64-
return &proto.TelemetryEvent{
67+
out := &proto.TelemetryEvent{
6568
Time: timestamppb.Now(),
6669
DerpMap: DERPMapToProto(b.cleanDerpMap),
6770
LatestNetcheck: b.cleanNetCheck,
@@ -70,17 +73,18 @@ func (b *TelemetryStore) newEvent() *proto.TelemetryEvent {
7073
HomeDerp: b.homeDerp,
7174
ConnectionSetup: b.connSetupTime,
7275
Application: b.application,
73-
74-
// TODO(ethanndickson):
75-
P2PSetup: &durationpb.Duration{},
7676
}
77+
if b.p2pSetupTime > 0 {
78+
out.P2PSetup = durationpb.New(b.p2pSetupTime)
79+
}
80+
return out
7781
}
7882

79-
func (b *TelemetryStore) markConnected(ip *netip.Addr, connCreatedAt time.Time, application string) {
83+
func (b *TelemetryStore) markConnected(ip *netip.Addr, application string) {
8084
b.mu.Lock()
8185
defer b.mu.Unlock()
8286

83-
b.connSetupTime = durationpb.New(time.Since(connCreatedAt))
87+
b.lastDerpTime = time.Now()
8488
b.connectedIP = ip
8589
b.application = application
8690
}
@@ -94,9 +98,12 @@ func (b *TelemetryStore) checkConnType(relay string) bool {
9498
return false
9599
} else if !b.p2p && relay == "" {
96100
b.p2p = true
101+
b.p2pSetupTime = time.Since(b.lastDerpTime)
97102
return true
98103
} else if b.p2p && relay != "" {
99104
b.p2p = false
105+
b.lastDerpTime = time.Now()
106+
b.p2pSetupTime = 0
100107
return true
101108
}
102109
return false

tailnet/telemetry_internal_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"net/netip"
66
"testing"
7-
"time"
87

98
"github.com/stretchr/testify/require"
109
"tailscale.com/tailcfg"
@@ -66,7 +65,7 @@ func TestTelemetryStore(t *testing.T) {
6665

6766
telemetry, err := newTelemetryStore()
6867
require.NoError(t, err)
69-
telemetry.markConnected(&remoteIP, time.Now(), application)
68+
telemetry.markConnected(&remoteIP, application)
7069
telemetry.updateNetworkMap(nm)
7170
e := telemetry.newEvent()
7271
// DERPMapToProto already tested

0 commit comments

Comments
 (0)