Skip to content
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
use latest p2p setup time
  • Loading branch information
ethanndickson committed Jul 9, 2024
commit 11f2a2b69de7b80a46f91b7637d0910340242930
3 changes: 1 addition & 2 deletions tailnet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func (c *Conn) SendConnectedTelemetry(ip netip.Addr, application string) {
if c.telemetrySink == nil {
return
}
c.telemetryStore.markConnected(&ip, c.createdAt, application)
c.telemetryStore.markConnected(&ip, application)
e := c.newTelemetryEvent()
e.Status = proto.TelemetryEvent_CONNECTED
c.sendTelemetryBackground(e)
Expand Down Expand Up @@ -768,7 +768,6 @@ func (c *Conn) sendPingTelemetry(pr *ipnstate.PingResult) {
if pr.Endpoint != "" {
e.P2PLatency = latency
e.P2PEndpoint = c.telemetryStore.toEndpoint(pr.Endpoint)
e.P2PSetup = durationpb.New(time.Since(c.createdAt))
} else {
e.DerpLatency = latency
}
Expand Down
19 changes: 13 additions & 6 deletions tailnet/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type TelemetryStore struct {
// 0 if not connected
nodeIDRemote uint64
p2p bool

p2pSetupTime time.Duration
lastDerpTime time.Time
}

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

return &proto.TelemetryEvent{
out := &proto.TelemetryEvent{
Time: timestamppb.Now(),
DerpMap: DERPMapToProto(b.cleanDerpMap),
LatestNetcheck: b.cleanNetCheck,
Expand All @@ -70,17 +73,18 @@ func (b *TelemetryStore) newEvent() *proto.TelemetryEvent {
HomeDerp: b.homeDerp,
ConnectionSetup: b.connSetupTime,
Application: b.application,

// TODO(ethanndickson):
P2PSetup: &durationpb.Duration{},
}
if b.p2pSetupTime > 0 {
out.P2PSetup = durationpb.New(b.p2pSetupTime)
}
return out
}

func (b *TelemetryStore) markConnected(ip *netip.Addr, connCreatedAt time.Time, application string) {
func (b *TelemetryStore) markConnected(ip *netip.Addr, application string) {
b.mu.Lock()
defer b.mu.Unlock()

b.connSetupTime = durationpb.New(time.Since(connCreatedAt))
b.lastDerpTime = time.Now()
b.connectedIP = ip
b.application = application
}
Expand All @@ -94,9 +98,12 @@ func (b *TelemetryStore) checkConnType(relay string) bool {
return false
} else if !b.p2p && relay == "" {
b.p2p = true
b.p2pSetupTime = time.Since(b.lastDerpTime)
return true
} else if b.p2p && relay != "" {
b.p2p = false
b.lastDerpTime = time.Now()
b.p2pSetupTime = 0
return true
}
return false
Expand Down
3 changes: 1 addition & 2 deletions tailnet/telemetry_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"net/netip"
"testing"
"time"

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

telemetry, err := newTelemetryStore()
require.NoError(t, err)
telemetry.markConnected(&remoteIP, time.Now(), application)
telemetry.markConnected(&remoteIP, application)
telemetry.updateNetworkMap(nm)
e := telemetry.newEvent()
// DERPMapToProto already tested
Expand Down