wgengine/magicsock: exclude disco from throughput metrics

The user-facing metrics are intended to track data transmitted at
the overlay network level.

Updates tailscale/corp#22075

Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
Anton Tolchanov 2024-10-29 13:46:34 +00:00 committed by Anton Tolchanov
parent e1e22785b4
commit 532b26145a
3 changed files with 14 additions and 10 deletions

View File

@ -649,9 +649,10 @@ func (c *Conn) runDerpReader(ctx context.Context, regionID int, dc *derphttp.Cli
} }
type derpWriteRequest struct { type derpWriteRequest struct {
addr netip.AddrPort addr netip.AddrPort
pubKey key.NodePublic pubKey key.NodePublic
b []byte // copied; ownership passed to receiver b []byte // copied; ownership passed to receiver
isDisco bool
} }
// runDerpWriter runs in a goroutine for the life of a DERP // runDerpWriter runs in a goroutine for the life of a DERP
@ -673,7 +674,7 @@ func (c *Conn) runDerpWriter(ctx context.Context, dc *derphttp.Client, ch <-chan
if err != nil { if err != nil {
c.logf("magicsock: derp.Send(%v): %v", wr.addr, err) c.logf("magicsock: derp.Send(%v): %v", wr.addr, err)
metricSendDERPError.Add(1) metricSendDERPError.Add(1)
} else { } else if !wr.isDisco {
c.metrics.outboundPacketsDERPTotal.Add(1) c.metrics.outboundPacketsDERPTotal.Add(1)
c.metrics.outboundBytesDERPTotal.Add(int64(len(wr.b))) c.metrics.outboundBytesDERPTotal.Add(int64(len(wr.b)))
} }
@ -696,8 +697,6 @@ func (c *connBind) receiveDERP(buffs [][]byte, sizes []int, eps []conn.Endpoint)
// No data read occurred. Wait for another packet. // No data read occurred. Wait for another packet.
continue continue
} }
c.metrics.inboundPacketsDERPTotal.Add(1)
c.metrics.inboundBytesDERPTotal.Add(int64(n))
sizes[0] = n sizes[0] = n
eps[0] = ep eps[0] = ep
return 1, nil return 1, nil
@ -737,6 +736,9 @@ func (c *Conn) processDERPReadResult(dm derpReadResult, b []byte) (n int, ep *en
if stats := c.stats.Load(); stats != nil { if stats := c.stats.Load(); stats != nil {
stats.UpdateRxPhysical(ep.nodeAddr, ipp, 1, dm.n) stats.UpdateRxPhysical(ep.nodeAddr, ipp, 1, dm.n)
} }
c.metrics.inboundPacketsDERPTotal.Add(1)
c.metrics.inboundBytesDERPTotal.Add(int64(n))
return n, ep return n, ep
} }

View File

@ -983,7 +983,8 @@ func (de *endpoint) send(buffs [][]byte) error {
allOk := true allOk := true
var txBytes int var txBytes int
for _, buff := range buffs { for _, buff := range buffs {
ok, _ := de.c.sendAddr(derpAddr, de.publicKey, buff) const isDisco = false
ok, _ := de.c.sendAddr(derpAddr, de.publicKey, buff, isDisco)
txBytes += len(buff) txBytes += len(buff)
if !ok { if !ok {
allOk = false allOk = false

View File

@ -1356,7 +1356,7 @@ func (c *Conn) sendUDPStd(addr netip.AddrPort, b []byte) (sent bool, err error)
// An example of when they might be different: sending to an // An example of when they might be different: sending to an
// IPv6 address when the local machine doesn't have IPv6 support // IPv6 address when the local machine doesn't have IPv6 support
// returns (false, nil); it's not an error, but nothing was sent. // returns (false, nil); it's not an error, but nothing was sent.
func (c *Conn) sendAddr(addr netip.AddrPort, pubKey key.NodePublic, b []byte) (sent bool, err error) { func (c *Conn) sendAddr(addr netip.AddrPort, pubKey key.NodePublic, b []byte, isDisco bool) (sent bool, err error) {
if addr.Addr() != tailcfg.DerpMagicIPAddr { if addr.Addr() != tailcfg.DerpMagicIPAddr {
return c.sendUDP(addr, b) return c.sendUDP(addr, b)
} }
@ -1379,7 +1379,7 @@ func (c *Conn) sendAddr(addr netip.AddrPort, pubKey key.NodePublic, b []byte) (s
case <-c.donec: case <-c.donec:
metricSendDERPErrorClosed.Add(1) metricSendDERPErrorClosed.Add(1)
return false, errConnClosed return false, errConnClosed
case ch <- derpWriteRequest{addr, pubKey, pkt}: case ch <- derpWriteRequest{addr, pubKey, pkt, isDisco}:
metricSendDERPQueued.Add(1) metricSendDERPQueued.Add(1)
return true, nil return true, nil
default: default:
@ -1577,7 +1577,8 @@ func (c *Conn) sendDiscoMessage(dst netip.AddrPort, dstKey key.NodePublic, dstDi
box := di.sharedKey.Seal(m.AppendMarshal(nil)) box := di.sharedKey.Seal(m.AppendMarshal(nil))
pkt = append(pkt, box...) pkt = append(pkt, box...)
sent, err = c.sendAddr(dst, dstKey, pkt) const isDisco = true
sent, err = c.sendAddr(dst, dstKey, pkt, isDisco)
if sent { if sent {
if logLevel == discoLog || (logLevel == discoVerboseLog && debugDisco()) { if logLevel == discoLog || (logLevel == discoVerboseLog && debugDisco()) {
node := "?" node := "?"