mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-02 01:51:59 +00:00
health: include DERP region name in bad derp notifications (#12530)
Fixes tailscale/corp#20971 We added some Warnables for DERP failure situations, but their Text currently spits out the DERP region ID ("10") in the UI, which is super ugly. It would be better to provide the RegionName of the DERP region that is failing. We can do so by storing a reference to the last-known DERP map in the health package whenever we fetch one, and using it when generating the notification text. This way, the following message... > Tailscale could not connect to the relay server '10'. The server might be temporarily unavailable, or your Internet connection might be down. becomes: > Tailscale could not connect to the 'Seattle' relay server. The server might be temporarily unavailable, or your Internet connection might be down. which is a lot more user-friendly. Signed-off-by: Andrea Gottardo <andrea@gottardo.me>
This commit is contained in:
@@ -88,7 +88,8 @@ type Tracker struct {
|
||||
derpRegionConnected map[int]bool
|
||||
derpRegionHealthProblem map[int]string
|
||||
derpRegionLastFrame map[int]time.Time
|
||||
lastMapRequestHeard time.Time // time we got a 200 from control for a MapRequest
|
||||
derpMap *tailcfg.DERPMap // last DERP map from control, could be nil if never received one
|
||||
lastMapRequestHeard time.Time // time we got a 200 from control for a MapRequest
|
||||
ipnState string
|
||||
ipnWantRunning bool
|
||||
anyInterfaceUp opt.Bool // empty means unknown (assume true)
|
||||
@@ -672,6 +673,18 @@ func (t *Tracker) GetDERPRegionReceivedTime(region int) time.Time {
|
||||
return t.derpRegionLastFrame[region]
|
||||
}
|
||||
|
||||
// SetDERPMap sets the last fetched DERP map in the Tracker. The DERP map is used
|
||||
// to provide a region name in user-facing DERP-related warnings.
|
||||
func (t *Tracker) SetDERPMap(dm *tailcfg.DERPMap) {
|
||||
if t.nil() {
|
||||
return
|
||||
}
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
t.derpMap = dm
|
||||
t.selfCheckLocked()
|
||||
}
|
||||
|
||||
// state is an ipn.State.String() value: "Running", "Stopped", "NeedsLogin", etc.
|
||||
func (t *Tracker) SetIPNState(state string, wantRunning bool) {
|
||||
if t.nil() {
|
||||
@@ -914,13 +927,15 @@ func (t *Tracker) updateBuiltinWarnablesLocked() {
|
||||
return
|
||||
} else if !t.derpRegionConnected[rid] {
|
||||
t.setUnhealthyLocked(noDERPConnectionWarnable, Args{
|
||||
ArgRegionID: fmt.Sprint(rid),
|
||||
ArgDERPRegionID: fmt.Sprint(rid),
|
||||
ArgDERPRegionName: t.derpMap.Regions[rid].RegionName,
|
||||
})
|
||||
return
|
||||
} else if d := now.Sub(t.derpRegionLastFrame[rid]).Round(time.Second); d > tooIdle {
|
||||
t.setUnhealthyLocked(derpTimeoutWarnable, Args{
|
||||
ArgRegionID: fmt.Sprint(rid),
|
||||
ArgDuration: d.String(),
|
||||
ArgDERPRegionID: fmt.Sprint(rid),
|
||||
ArgDERPRegionName: t.derpMap.Regions[rid].RegionName,
|
||||
ArgDuration: d.String(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -964,8 +979,8 @@ func (t *Tracker) updateBuiltinWarnablesLocked() {
|
||||
if len(t.derpRegionHealthProblem) > 0 {
|
||||
for regionID, problem := range t.derpRegionHealthProblem {
|
||||
t.setUnhealthyLocked(derpRegionErrorWarnable, Args{
|
||||
ArgRegionID: fmt.Sprint(regionID),
|
||||
ArgError: problem,
|
||||
ArgDERPRegionID: fmt.Sprint(regionID),
|
||||
ArgError: problem,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user