mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
control/controlclient: plumb health.Tracker
Updates #11874 Updates #4136 Change-Id: Ia941153bd83523f0c8b56852010f5231d774d91a Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
6d69fc137f
commit
a4a282cd49
@ -12,7 +12,6 @@
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tailscale.com/health"
|
|
||||||
"tailscale.com/logtail/backoff"
|
"tailscale.com/logtail/backoff"
|
||||||
"tailscale.com/net/sockstats"
|
"tailscale.com/net/sockstats"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
@ -195,7 +194,7 @@ func NewNoStart(opts Options) (_ *Auto, err error) {
|
|||||||
c.mapCtx, c.mapCancel = context.WithCancel(context.Background())
|
c.mapCtx, c.mapCancel = context.WithCancel(context.Background())
|
||||||
c.mapCtx = sockstats.WithSockStats(c.mapCtx, sockstats.LabelControlClientAuto, opts.Logf)
|
c.mapCtx = sockstats.WithSockStats(c.mapCtx, sockstats.LabelControlClientAuto, opts.Logf)
|
||||||
|
|
||||||
c.unregisterHealthWatch = health.Global.RegisterWatcher(direct.ReportHealthChange)
|
c.unregisterHealthWatch = opts.HealthTracker.RegisterWatcher(direct.ReportHealthChange)
|
||||||
return c, nil
|
return c, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -316,7 +315,7 @@ func (c *Auto) authRoutine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if goal == nil {
|
if goal == nil {
|
||||||
health.Global.SetAuthRoutineInError(nil)
|
c.direct.health.SetAuthRoutineInError(nil)
|
||||||
// Wait for user to Login or Logout.
|
// Wait for user to Login or Logout.
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
c.logf("[v1] authRoutine: context done.")
|
c.logf("[v1] authRoutine: context done.")
|
||||||
@ -343,7 +342,7 @@ func (c *Auto) authRoutine() {
|
|||||||
f = "TryLogin"
|
f = "TryLogin"
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
health.Global.SetAuthRoutineInError(err)
|
c.direct.health.SetAuthRoutineInError(err)
|
||||||
report(err, f)
|
report(err, f)
|
||||||
bo.BackOff(ctx, err)
|
bo.BackOff(ctx, err)
|
||||||
continue
|
continue
|
||||||
@ -373,7 +372,7 @@ func (c *Auto) authRoutine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// success
|
// success
|
||||||
health.Global.SetAuthRoutineInError(nil)
|
c.direct.health.SetAuthRoutineInError(nil)
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
c.urlToVisit = ""
|
c.urlToVisit = ""
|
||||||
c.loggedIn = true
|
c.loggedIn = true
|
||||||
@ -503,11 +502,11 @@ func (c *Auto) mapRoutine() {
|
|||||||
c.logf("[v1] mapRoutine: context done.")
|
c.logf("[v1] mapRoutine: context done.")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
health.Global.SetOutOfPollNetMap()
|
c.direct.health.SetOutOfPollNetMap()
|
||||||
|
|
||||||
err := c.direct.PollNetMap(ctx, mrs)
|
err := c.direct.PollNetMap(ctx, mrs)
|
||||||
|
|
||||||
health.Global.SetOutOfPollNetMap()
|
c.direct.health.SetOutOfPollNetMap()
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
c.inMapPoll = false
|
c.inMapPoll = false
|
||||||
if c.state == StateSynchronized {
|
if c.state == StateSynchronized {
|
||||||
|
@ -69,6 +69,7 @@ type Direct struct {
|
|||||||
clock tstime.Clock
|
clock tstime.Clock
|
||||||
logf logger.Logf
|
logf logger.Logf
|
||||||
netMon *netmon.Monitor // or nil
|
netMon *netmon.Monitor // or nil
|
||||||
|
health *health.Tracker
|
||||||
discoPubKey key.DiscoPublic
|
discoPubKey key.DiscoPublic
|
||||||
getMachinePrivKey func() (key.MachinePrivate, error)
|
getMachinePrivKey func() (key.MachinePrivate, error)
|
||||||
debugFlags []string
|
debugFlags []string
|
||||||
@ -119,10 +120,11 @@ type Options struct {
|
|||||||
Hostinfo *tailcfg.Hostinfo // non-nil passes ownership, nil means to use default using os.Hostname, etc
|
Hostinfo *tailcfg.Hostinfo // non-nil passes ownership, nil means to use default using os.Hostname, etc
|
||||||
DiscoPublicKey key.DiscoPublic
|
DiscoPublicKey key.DiscoPublic
|
||||||
Logf logger.Logf
|
Logf logger.Logf
|
||||||
HTTPTestClient *http.Client // optional HTTP client to use (for tests only)
|
HTTPTestClient *http.Client // optional HTTP client to use (for tests only)
|
||||||
NoiseTestClient *http.Client // optional HTTP client to use for noise RPCs (tests only)
|
NoiseTestClient *http.Client // optional HTTP client to use for noise RPCs (tests only)
|
||||||
DebugFlags []string // debug settings to send to control
|
DebugFlags []string // debug settings to send to control
|
||||||
NetMon *netmon.Monitor // optional network monitor
|
NetMon *netmon.Monitor // optional network monitor
|
||||||
|
HealthTracker *health.Tracker
|
||||||
PopBrowserURL func(url string) // optional func to open browser
|
PopBrowserURL func(url string) // optional func to open browser
|
||||||
OnClientVersion func(*tailcfg.ClientVersion) // optional func to inform GUI of client version status
|
OnClientVersion func(*tailcfg.ClientVersion) // optional func to inform GUI of client version status
|
||||||
OnControlTime func(time.Time) // optional func to notify callers of new time from control
|
OnControlTime func(time.Time) // optional func to notify callers of new time from control
|
||||||
@ -248,7 +250,7 @@ func NewDirect(opts Options) (*Direct, error) {
|
|||||||
tr := http.DefaultTransport.(*http.Transport).Clone()
|
tr := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
tr.Proxy = tshttpproxy.ProxyFromEnvironment
|
tr.Proxy = tshttpproxy.ProxyFromEnvironment
|
||||||
tshttpproxy.SetTransportGetProxyConnectHeader(tr)
|
tshttpproxy.SetTransportGetProxyConnectHeader(tr)
|
||||||
tr.TLSClientConfig = tlsdial.Config(serverURL.Hostname(), health.Global, tr.TLSClientConfig)
|
tr.TLSClientConfig = tlsdial.Config(serverURL.Hostname(), opts.HealthTracker, tr.TLSClientConfig)
|
||||||
tr.DialContext = dnscache.Dialer(opts.Dialer.SystemDial, dnsCache)
|
tr.DialContext = dnscache.Dialer(opts.Dialer.SystemDial, dnsCache)
|
||||||
tr.DialTLSContext = dnscache.TLSDialer(opts.Dialer.SystemDial, dnsCache, tr.TLSClientConfig)
|
tr.DialTLSContext = dnscache.TLSDialer(opts.Dialer.SystemDial, dnsCache, tr.TLSClientConfig)
|
||||||
tr.ForceAttemptHTTP2 = true
|
tr.ForceAttemptHTTP2 = true
|
||||||
@ -271,6 +273,7 @@ func NewDirect(opts Options) (*Direct, error) {
|
|||||||
discoPubKey: opts.DiscoPublicKey,
|
discoPubKey: opts.DiscoPublicKey,
|
||||||
debugFlags: opts.DebugFlags,
|
debugFlags: opts.DebugFlags,
|
||||||
netMon: opts.NetMon,
|
netMon: opts.NetMon,
|
||||||
|
health: opts.HealthTracker,
|
||||||
skipIPForwardingCheck: opts.SkipIPForwardingCheck,
|
skipIPForwardingCheck: opts.SkipIPForwardingCheck,
|
||||||
pinger: opts.Pinger,
|
pinger: opts.Pinger,
|
||||||
popBrowser: opts.PopBrowserURL,
|
popBrowser: opts.PopBrowserURL,
|
||||||
@ -894,10 +897,10 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap
|
|||||||
ipForwardingBroken(hi.RoutableIPs, c.netMon.InterfaceState()) {
|
ipForwardingBroken(hi.RoutableIPs, c.netMon.InterfaceState()) {
|
||||||
extraDebugFlags = append(extraDebugFlags, "warn-ip-forwarding-off")
|
extraDebugFlags = append(extraDebugFlags, "warn-ip-forwarding-off")
|
||||||
}
|
}
|
||||||
if health.Global.RouterHealth() != nil {
|
if c.health.RouterHealth() != nil {
|
||||||
extraDebugFlags = append(extraDebugFlags, "warn-router-unhealthy")
|
extraDebugFlags = append(extraDebugFlags, "warn-router-unhealthy")
|
||||||
}
|
}
|
||||||
extraDebugFlags = health.Global.AppendWarnableDebugFlags(extraDebugFlags)
|
extraDebugFlags = c.health.AppendWarnableDebugFlags(extraDebugFlags)
|
||||||
if hostinfo.DisabledEtcAptSource() {
|
if hostinfo.DisabledEtcAptSource() {
|
||||||
extraDebugFlags = append(extraDebugFlags, "warn-etc-apt-source-disabled")
|
extraDebugFlags = append(extraDebugFlags, "warn-etc-apt-source-disabled")
|
||||||
}
|
}
|
||||||
@ -970,7 +973,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap
|
|||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
health.Global.NoteMapRequestHeard(request)
|
c.health.NoteMapRequestHeard(request)
|
||||||
watchdogTimer.Reset(watchdogTimeout)
|
watchdogTimer.Reset(watchdogTimeout)
|
||||||
|
|
||||||
if nu == nil {
|
if nu == nil {
|
||||||
@ -1041,7 +1044,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap
|
|||||||
metricMapResponseMessages.Add(1)
|
metricMapResponseMessages.Add(1)
|
||||||
|
|
||||||
if isStreaming {
|
if isStreaming {
|
||||||
health.Global.GotStreamedMapResponse()
|
c.health.GotStreamedMapResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
if pr := resp.PingRequest; pr != nil && c.isUniquePingRequest(pr) {
|
if pr := resp.PingRequest; pr != nil && c.isUniquePingRequest(pr) {
|
||||||
|
@ -1763,6 +1763,7 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
|
|||||||
DiscoPublicKey: discoPublic,
|
DiscoPublicKey: discoPublic,
|
||||||
DebugFlags: debugFlags,
|
DebugFlags: debugFlags,
|
||||||
NetMon: b.sys.NetMon.Get(),
|
NetMon: b.sys.NetMon.Get(),
|
||||||
|
HealthTracker: b.health,
|
||||||
Pinger: b,
|
Pinger: b,
|
||||||
PopBrowserURL: b.tellClientToBrowseToURL,
|
PopBrowserURL: b.tellClientToBrowseToURL,
|
||||||
OnClientVersion: b.onClientVersion,
|
OnClientVersion: b.onClientVersion,
|
||||||
|
Loading…
Reference in New Issue
Block a user