wgengine/{,magicsock}: add metrics for rebinds and restuns

Signed-off-by: Maisem Ali <maisem@tailscale.com>
pull/4503/head
Maisem Ali 3 years ago committed by Maisem Ali
parent 78fededaa5
commit 2265587d38

@ -54,8 +54,8 @@ import (
"tailscale.com/types/netmap" "tailscale.com/types/netmap"
"tailscale.com/types/nettype" "tailscale.com/types/nettype"
"tailscale.com/util/clientmetric" "tailscale.com/util/clientmetric"
"tailscale.com/util/netconv"
"tailscale.com/util/mak" "tailscale.com/util/mak"
"tailscale.com/util/netconv"
"tailscale.com/util/uniq" "tailscale.com/util/uniq"
"tailscale.com/version" "tailscale.com/version"
"tailscale.com/wgengine/monitor" "tailscale.com/wgengine/monitor"
@ -603,6 +603,7 @@ func (c *Conn) stopPeriodicReSTUNTimerLocked() {
// c.mu must NOT be held. // c.mu must NOT be held.
func (c *Conn) updateEndpoints(why string) { func (c *Conn) updateEndpoints(why string) {
metricUpdateEndpoints.Add(1)
defer func() { defer func() {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
@ -2768,6 +2769,7 @@ func (c *Conn) ReSTUN(why string) {
// raced with a shutdown. // raced with a shutdown.
return return
} }
metricReSTUNCalls.Add(1)
// If the user stopped the app, stop doing work. (When the // If the user stopped the app, stop doing work. (When the
// user stops Tailscale via the GUI apps, ipn/local.go // user stops Tailscale via the GUI apps, ipn/local.go
@ -2917,6 +2919,7 @@ func (c *Conn) rebind(curPortFate currentPortFate) error {
// Rebind closes and re-binds the UDP sockets and resets the DERP connection. // Rebind closes and re-binds the UDP sockets and resets the DERP connection.
// It should be followed by a call to ReSTUN. // It should be followed by a call to ReSTUN.
func (c *Conn) Rebind() { func (c *Conn) Rebind() {
metricRebindCalls.Add(1)
if err := c.rebind(keepCurrentPort); err != nil { if err := c.rebind(keepCurrentPort); err != nil {
c.logf("%w", err) c.logf("%w", err)
return return
@ -4138,6 +4141,10 @@ var (
metricNumPeers = clientmetric.NewGauge("magicsock_netmap_num_peers") metricNumPeers = clientmetric.NewGauge("magicsock_netmap_num_peers")
metricNumDERPConns = clientmetric.NewGauge("magicsock_num_derp_conns") metricNumDERPConns = clientmetric.NewGauge("magicsock_num_derp_conns")
metricRebindCalls = clientmetric.NewCounter("magicsock_rebind_calls")
metricReSTUNCalls = clientmetric.NewCounter("magicsock_restun_calls")
metricUpdateEndpoints = clientmetric.NewCounter("magicsock_update_endpoints")
// Sends (data or disco) // Sends (data or disco)
metricSendDERPQueued = clientmetric.NewCounter("magicsock_send_derp_queued") metricSendDERPQueued = clientmetric.NewCounter("magicsock_send_derp_queued")
metricSendDERPErrorChan = clientmetric.NewCounter("magicsock_send_derp_error_chan") metricSendDERPErrorChan = clientmetric.NewCounter("magicsock_send_derp_error_chan")

@ -1203,7 +1203,10 @@ func (e *userspaceEngine) linkChange(changed bool, cur *interfaces.State) {
why := "link-change-minor" why := "link-change-minor"
if changed { if changed {
why = "link-change-major" why = "link-change-major"
metricNumMajorChanges.Add(1)
e.magicConn.Rebind() e.magicConn.Rebind()
} else {
metricNumMinorChanges.Add(1)
} }
e.magicConn.ReSTUN(why) e.magicConn.ReSTUN(why)
} }
@ -1551,4 +1554,7 @@ func (ls fwdDNSLinkSelector) PickLink(ip netaddr.IP) (linkName string) {
var ( var (
metricMagicDNSPacketIn = clientmetric.NewGauge("magicdns_packet_in") // for 100.100.100.100 metricMagicDNSPacketIn = clientmetric.NewGauge("magicdns_packet_in") // for 100.100.100.100
metricReflectToOS = clientmetric.NewGauge("packet_reflect_to_os") metricReflectToOS = clientmetric.NewGauge("packet_reflect_to_os")
metricNumMajorChanges = clientmetric.NewCounter("wgengine_major_changes")
metricNumMinorChanges = clientmetric.NewCounter("wgengine_minor_changes")
) )

Loading…
Cancel
Save