mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
net/netmon, net/tsdial: add some link change metrics
Updates #9040 Change-Id: I2c87572d79d2118bcf1f0122eccfe712c1bea9d5 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
8683ce78c2
commit
1262df0578
@ -136,7 +136,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
|
|||||||
tailscale.com/types/structs from tailscale.com/ipn+
|
tailscale.com/types/structs from tailscale.com/ipn+
|
||||||
tailscale.com/types/tkatype from tailscale.com/types/key+
|
tailscale.com/types/tkatype from tailscale.com/types/key+
|
||||||
tailscale.com/types/views from tailscale.com/ipn/ipnstate+
|
tailscale.com/types/views from tailscale.com/ipn/ipnstate+
|
||||||
W tailscale.com/util/clientmetric from tailscale.com/net/tshttpproxy
|
tailscale.com/util/clientmetric from tailscale.com/net/tshttpproxy+
|
||||||
tailscale.com/util/cloudenv from tailscale.com/hostinfo+
|
tailscale.com/util/cloudenv from tailscale.com/hostinfo+
|
||||||
W tailscale.com/util/cmpver from tailscale.com/net/tshttpproxy
|
W tailscale.com/util/cmpver from tailscale.com/net/tshttpproxy
|
||||||
tailscale.com/util/cmpx from tailscale.com/cmd/derper+
|
tailscale.com/util/cmpx from tailscale.com/cmd/derper+
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
|
|
||||||
"tailscale.com/net/interfaces"
|
"tailscale.com/net/interfaces"
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
|
"tailscale.com/util/clientmetric"
|
||||||
"tailscale.com/util/set"
|
"tailscale.com/util/set"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -369,6 +370,13 @@ func (m *Monitor) debounce() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
metricChangeEq = clientmetric.NewCounter("netmon_link_change_eq")
|
||||||
|
metricChange = clientmetric.NewCounter("netmon_link_change")
|
||||||
|
metricChangeTimeJump = clientmetric.NewCounter("netmon_link_change_timejump")
|
||||||
|
metricChangeMajor = clientmetric.NewCounter("netmon_link_change_major")
|
||||||
|
)
|
||||||
|
|
||||||
// handlePotentialChange considers whether newState is different enough to wake
|
// handlePotentialChange considers whether newState is different enough to wake
|
||||||
// up callers and updates the monitor's state if so.
|
// up callers and updates the monitor's state if so.
|
||||||
//
|
//
|
||||||
@ -380,6 +388,7 @@ func (m *Monitor) handlePotentialChange(newState *interfaces.State, forceCallbac
|
|||||||
timeJumped := shouldMonitorTimeJump && m.checkWallTimeAdvanceLocked()
|
timeJumped := shouldMonitorTimeJump && m.checkWallTimeAdvanceLocked()
|
||||||
if !timeJumped && !forceCallbacks && oldState.Equal(newState) {
|
if !timeJumped && !forceCallbacks && oldState.Equal(newState) {
|
||||||
// Exactly equal. Nothing to do.
|
// Exactly equal. Nothing to do.
|
||||||
|
metricChangeEq.Add(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,6 +419,13 @@ func (m *Monitor) handlePotentialChange(newState *interfaces.State, forceCallbac
|
|||||||
delta.Major = true
|
delta.Major = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
metricChange.Add(1)
|
||||||
|
if delta.Major {
|
||||||
|
metricChangeMajor.Add(1)
|
||||||
|
}
|
||||||
|
if delta.TimeJumped {
|
||||||
|
metricChangeTimeJump.Add(1)
|
||||||
|
}
|
||||||
for _, cb := range m.cbs {
|
for _, cb := range m.cbs {
|
||||||
go cb(delta)
|
go cb(delta)
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"tailscale.com/net/netns"
|
"tailscale.com/net/netns"
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
"tailscale.com/types/netmap"
|
"tailscale.com/types/netmap"
|
||||||
|
"tailscale.com/util/clientmetric"
|
||||||
"tailscale.com/util/mak"
|
"tailscale.com/util/mak"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -138,16 +139,25 @@ func (d *Dialer) SetNetMon(netMon *netmon.Monitor) {
|
|||||||
d.netMonUnregister = d.netMon.RegisterChangeCallback(d.linkChanged)
|
d.netMonUnregister = d.netMon.RegisterChangeCallback(d.linkChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
metricLinkChangeConnClosed = clientmetric.NewCounter("tsdial_linkchange_closes")
|
||||||
|
)
|
||||||
|
|
||||||
func (d *Dialer) linkChanged(delta *netmon.ChangeDelta) {
|
func (d *Dialer) linkChanged(delta *netmon.ChangeDelta) {
|
||||||
d.mu.Lock()
|
d.mu.Lock()
|
||||||
defer d.mu.Unlock()
|
defer d.mu.Unlock()
|
||||||
|
var anyClosed bool
|
||||||
for id, c := range d.activeSysConns {
|
for id, c := range d.activeSysConns {
|
||||||
if changeAffectsConn(delta, c) {
|
if changeAffectsConn(delta, c) {
|
||||||
|
anyClosed = true
|
||||||
d.logf("tsdial: closing system connection %v->%v due to link change", c.LocalAddr(), c.RemoteAddr())
|
d.logf("tsdial: closing system connection %v->%v due to link change", c.LocalAddr(), c.RemoteAddr())
|
||||||
go c.Close()
|
go c.Close()
|
||||||
delete(d.activeSysConns, id)
|
delete(d.activeSysConns, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if anyClosed {
|
||||||
|
metricLinkChangeConnClosed.Add(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// changeAffectsConn reports whether the network change delta affects
|
// changeAffectsConn reports whether the network change delta affects
|
||||||
|
Loading…
x
Reference in New Issue
Block a user