Skip to content

Commit 9482c1c

Browse files
committed
ping and speedtest telemetry
1 parent 4be37dc commit 9482c1c

File tree

7 files changed

+277
-278
lines changed

7 files changed

+277
-278
lines changed

cli/speedtest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ func (r *RootCmd) speedtest() *serpent.Command {
186186
outputResult.Intervals[i] = interval
187187
}
188188
}
189+
_ = conn.Conn.SendSpeedtestTelemetry(outputResult.Overall.ThroughputMbits)
189190
out, err := formatter.Format(inv.Context(), outputResult)
190191
if err != nil {
191192
return err

coderd/telemetry/telemetry.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,14 +1221,11 @@ func netcheckFromProto(proto *tailnetproto.Netcheck) Netcheck {
12211221

12221222
PreferredDERP: proto.PreferredDERP,
12231223

1224-
RegionLatency: durationMapFromProto(proto.RegionLatency),
12251224
RegionV4Latency: durationMapFromProto(proto.RegionV4Latency),
12261225
RegionV6Latency: durationMapFromProto(proto.RegionV6Latency),
12271226

12281227
GlobalV4: netcheckIPFromProto(proto.GlobalV4),
12291228
GlobalV6: netcheckIPFromProto(proto.GlobalV6),
1230-
1231-
CaptivePortal: protoBool(proto.CaptivePortal),
12321229
}
12331230
}
12341231

codersdk/workspacesdk/connector_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (*fakeDRPCClient) DRPCConn() drpc.Conn {
323323
}
324324

325325
// PostTelemetry implements proto.DRPCTailnetClient.
326-
func (f *fakeDRPCClient) PostTelemetry(_ context.Context, in *proto.TelemetryRequest) (*proto.TelemetryResponse, error) {
326+
func (f *fakeDRPCClient) PostTelemetry(_ context.Context, _ *proto.TelemetryRequest) (*proto.TelemetryResponse, error) {
327327
return nil, f.telemeteryErorr
328328
}
329329

tailnet/conn.go

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,12 @@ func (c *Conn) Status() *ipnstate.Status {
448448
// Ping sends a ping to the Wireguard engine.
449449
// The bool returned is true if the ping was performed P2P.
450450
func (c *Conn) Ping(ctx context.Context, ip netip.Addr) (time.Duration, bool, *ipnstate.PingResult, error) {
451-
return c.pingWithType(ctx, ip, tailcfg.PingDisco)
451+
dur, p2p, pr, err := c.pingWithType(ctx, ip, tailcfg.PingDisco)
452+
if err == nil {
453+
// TODO(ethanndickson): Is this too often?
454+
_ = c.sendPingTelemetry(dur, p2p)
455+
}
456+
return dur, p2p, pr, err
452457
}
453458

454459
func (c *Conn) pingWithType(ctx context.Context, ip netip.Addr, pt tailcfg.PingType) (time.Duration, bool, *ipnstate.PingResult, error) {
@@ -525,7 +530,7 @@ func (c *Conn) AwaitReachable(ctx context.Context, ip netip.Addr) bool {
525530
case <-completedCtx.Done():
526531
// TODO(ethanndickson): For now, I'm interpreting 'connected' as when the
527532
// agent is reachable.
528-
// _ = c.connectedTelemetryEvent()
533+
_ = c.sendConnectedTelemetry()
529534
return true
530535
case <-t.C:
531536
// Pings can take a while, so we can run multiple
@@ -715,7 +720,24 @@ func (c *Conn) MagicsockServeHTTPDebug(w http.ResponseWriter, r *http.Request) {
715720
c.magicConn.ServeHTTPDebug(w, r)
716721
}
717722

718-
func (c *Conn) connectedTelemetryEvent() error {
723+
func (c *Conn) sendConnectedTelemetry() error {
724+
if c.telemetrySink == nil {
725+
return nil
726+
}
727+
e, err := c.newTelemetryEvent()
728+
if err != nil {
729+
return xerrors.Errorf("create telemetry event: %w", err)
730+
}
731+
e.Status = proto.TelemetryEvent_CONNECTED
732+
c.telemetryWg.Add(1)
733+
go func() {
734+
defer c.telemetryWg.Done()
735+
c.telemetrySink.SendTelemetryEvent(e)
736+
}()
737+
return nil
738+
}
739+
740+
func (c *Conn) SendSpeedtestTelemetry(throughputMbits float64) error {
719741
if c.telemetrySink == nil {
720742
return nil
721743
}
@@ -724,6 +746,30 @@ func (c *Conn) connectedTelemetryEvent() error {
724746
return xerrors.Errorf("create telemetry event: %w", err)
725747
}
726748
e.Status = proto.TelemetryEvent_CONNECTED
749+
e.ThroughputMbits = wrapperspb.Float(float32(throughputMbits))
750+
c.telemetryWg.Add(1)
751+
go func() {
752+
defer c.telemetryWg.Done()
753+
c.telemetrySink.SendTelemetryEvent(e)
754+
}()
755+
return nil
756+
}
757+
758+
// nolint: revive
759+
func (c *Conn) sendPingTelemetry(latency time.Duration, p2p bool) error {
760+
if c.telemetrySink == nil {
761+
return nil
762+
}
763+
e, err := c.newTelemetryEvent()
764+
if err != nil {
765+
return xerrors.Errorf("create telemetry event: %w", err)
766+
}
767+
e.Status = proto.TelemetryEvent_CONNECTED
768+
if p2p {
769+
e.P2PLatency = durationpb.New(latency)
770+
} else {
771+
e.DerpLatency = durationpb.New(latency)
772+
}
727773
c.telemetryWg.Add(1)
728774
go func() {
729775
defer c.telemetryWg.Done()
@@ -754,14 +800,11 @@ func (c *Conn) newTelemetryEvent() (*proto.TelemetryEvent, error) {
754800
Application: "",
755801
NodeIdRemote: 0,
756802
P2PEndpoint: &proto.TelemetryEvent_P2PEndpoint{},
757-
ThroughputMbits: &wrapperspb.FloatValue{},
758803
HomeDerp: "",
759804
ConnectionAge: &durationpb.Duration{},
760805
ConnectionSetup: &durationpb.Duration{},
761-
P2PSetup: &durationpb.Duration{},
762-
// TODO: One of these two
763-
DerpLatency: &durationpb.Duration{},
764-
P2PLatency: &durationpb.Duration{},
806+
// TODO: We only calculate this in one place, do we really want it?
807+
P2PSetup: &durationpb.Duration{},
765808
}, nil
766809
}
767810

tailnet/convert.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ func NetInfoToProto(netInfo *tailcfg.NetInfo) *proto.Netcheck {
304304
}
305305
return &proto.Netcheck{
306306
UDP: netInfo.WorkingUDP.EqualBool(true),
307-
IPv6CanSend: netInfo.WorkingIPv6.EqualBool(true),
308307
OSHasIPv6: netInfo.OSHasIPv6.EqualBool(true),
308+
IPv6: netInfo.WorkingIPv6.EqualBool(true),
309309
ICMPv4: netInfo.WorkingICMPv4.EqualBool(true),
310310
MappingVariesByDestIP: wrapperspb.Bool(netInfo.MappingVariesByDestIP.EqualBool(true)),
311311
HairPinning: wrapperspb.Bool(netInfo.HairPinning.EqualBool(true)),
@@ -315,14 +315,11 @@ func NetInfoToProto(netInfo *tailcfg.NetInfo) *proto.Netcheck {
315315
PreferredDERP: int64(netInfo.PreferredDERP),
316316
RegionV4Latency: rlv4,
317317
RegionV6Latency: rlv6,
318-
// TODO: what's the most useful value to have here?
319-
RegionLatency: make(map[int64]*durationpb.Duration),
320-
// TODO: None of these are exposed by tailscale
321-
IPv4CanSend: false,
322-
IPv4: false,
323-
IPv6: false,
324-
GlobalV4: &proto.Netcheck_NetcheckIP{},
325-
GlobalV6: &proto.Netcheck_NetcheckIP{},
326-
CaptivePortal: &wrapperspb.BoolValue{},
318+
// TODO: These aren't yet exposed by Tailscale
319+
IPv6CanSend: false,
320+
IPv4CanSend: false,
321+
IPv4: false,
322+
GlobalV4: &proto.Netcheck_NetcheckIP{},
323+
GlobalV6: &proto.Netcheck_NetcheckIP{},
327324
}
328325
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy