Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2265587

Browse files
Maisem Alimaisem
Maisem Ali
authored andcommitted
wgengine/{,magicsock}: add metrics for rebinds and restuns
Signed-off-by: Maisem Ali <[email protected]>
1 parent 78feded commit 2265587

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

wgengine/magicsock/magicsock.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ import (
5454
"tailscale.com/types/netmap"
5555
"tailscale.com/types/nettype"
5656
"tailscale.com/util/clientmetric"
57-
"tailscale.com/util/netconv"
5857
"tailscale.com/util/mak"
58+
"tailscale.com/util/netconv"
5959
"tailscale.com/util/uniq"
6060
"tailscale.com/version"
6161
"tailscale.com/wgengine/monitor"
@@ -603,6 +603,7 @@ func (c *Conn) stopPeriodicReSTUNTimerLocked() {
603603

604604
// c.mu must NOT be held.
605605
func (c *Conn) updateEndpoints(why string) {
606+
metricUpdateEndpoints.Add(1)
606607
defer func() {
607608
c.mu.Lock()
608609
defer c.mu.Unlock()
@@ -1048,7 +1049,7 @@ func (c *Conn) determineEndpoints(ctx context.Context) ([]tailcfg.Endpoint, erro
10481049
}
10491050

10501051
var already map[netaddr.IPPort]tailcfg.EndpointType // endpoint -> how it was found
1051-
var eps []tailcfg.Endpoint // unique endpoints
1052+
var eps []tailcfg.Endpoint // unique endpoints
10521053

10531054
ipp := func(s string) (ipp netaddr.IPPort) {
10541055
ipp, _ = netaddr.ParseIPPort(s)
@@ -2768,6 +2769,7 @@ func (c *Conn) ReSTUN(why string) {
27682769
// raced with a shutdown.
27692770
return
27702771
}
2772+
metricReSTUNCalls.Add(1)
27712773

27722774
// If the user stopped the app, stop doing work. (When the
27732775
// user stops Tailscale via the GUI apps, ipn/local.go
@@ -2917,6 +2919,7 @@ func (c *Conn) rebind(curPortFate currentPortFate) error {
29172919
// Rebind closes and re-binds the UDP sockets and resets the DERP connection.
29182920
// It should be followed by a call to ReSTUN.
29192921
func (c *Conn) Rebind() {
2922+
metricRebindCalls.Add(1)
29202923
if err := c.rebind(keepCurrentPort); err != nil {
29212924
c.logf("%w", err)
29222925
return
@@ -4138,6 +4141,10 @@ var (
41384141
metricNumPeers = clientmetric.NewGauge("magicsock_netmap_num_peers")
41394142
metricNumDERPConns = clientmetric.NewGauge("magicsock_num_derp_conns")
41404143

4144+
metricRebindCalls = clientmetric.NewCounter("magicsock_rebind_calls")
4145+
metricReSTUNCalls = clientmetric.NewCounter("magicsock_restun_calls")
4146+
metricUpdateEndpoints = clientmetric.NewCounter("magicsock_update_endpoints")
4147+
41414148
// Sends (data or disco)
41424149
metricSendDERPQueued = clientmetric.NewCounter("magicsock_send_derp_queued")
41434150
metricSendDERPErrorChan = clientmetric.NewCounter("magicsock_send_derp_error_chan")

wgengine/userspace.go

+6
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,10 @@ func (e *userspaceEngine) linkChange(changed bool, cur *interfaces.State) {
12031203
why := "link-change-minor"
12041204
if changed {
12051205
why = "link-change-major"
1206+
metricNumMajorChanges.Add(1)
12061207
e.magicConn.Rebind()
1208+
} else {
1209+
metricNumMinorChanges.Add(1)
12071210
}
12081211
e.magicConn.ReSTUN(why)
12091212
}
@@ -1551,4 +1554,7 @@ func (ls fwdDNSLinkSelector) PickLink(ip netaddr.IP) (linkName string) {
15511554
var (
15521555
metricMagicDNSPacketIn = clientmetric.NewGauge("magicdns_packet_in") // for 100.100.100.100
15531556
metricReflectToOS = clientmetric.NewGauge("packet_reflect_to_os")
1557+
1558+
metricNumMajorChanges = clientmetric.NewCounter("wgengine_major_changes")
1559+
metricNumMinorChanges = clientmetric.NewCounter("wgengine_minor_changes")
15541560
)

0 commit comments

Comments
 (0)