health
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package health is a registry for other packages to report & checkoverall health status of the node.
Index¶
- Constants
- Variables
- func DebugHandler(typ string) http.Handler
- func RegisterDebugHandler(typ string, h http.Handler)
- func StaticMessage(s string) func(Args) string
- type Arg
- type Args
- type Change
- type ReceiveFunc
- type ReceiveFuncStats
- type Severity
- type State
- type Subsystemdeprecated
- type Tracker
- func (t *Tracker) AppendWarnableDebugFlags(base []string) []string
- func (t *Tracker) CurrentState() *State
- func (t *Tracker) DNSHealth() errordeprecated
- func (t *Tracker) GetDERPRegionReceivedTime(region int) time.Time
- func (t *Tracker) GetInPollNetMap() bool
- func (t *Tracker) GotStreamedMapResponse()
- func (t *Tracker) IsUnhealthy(w *Warnable) bool
- func (t *Tracker) LastNoiseDialWasRecent() bool
- func (t *Tracker) NoteDERPRegionReceivedFrame(region int)
- func (t *Tracker) NoteMapRequestHeard(mr *tailcfg.MapRequest)
- func (t *Tracker) OverallError() error
- func (t *Tracker) ReceiveFuncStats(which ReceiveFunc) *ReceiveFuncStats
- func (t *Tracker) RouterHealth() errordeprecated
- func (t *Tracker) SetAnyInterfaceUp(up bool)
- func (t *Tracker) SetAuthRoutineInError(err error)
- func (t *Tracker) SetAutoUpdatePrefs(check bool, apply opt.Bool)
- func (t *Tracker) SetControlHealth(problems map[tailcfg.DisplayMessageID]tailcfg.DisplayMessage)
- func (t *Tracker) SetDERPMap(dm *tailcfg.DERPMap)
- func (t *Tracker) SetDERPRegionConnectedState(region int, connected bool)
- func (t *Tracker) SetDERPRegionHealth(region int, problem string)
- func (t *Tracker) SetDNSHealth(err error)deprecated
- func (t *Tracker) SetDNSManagerHealth(err error)deprecated
- func (t *Tracker) SetHealthy(w *Warnable)
- func (t *Tracker) SetIPNState(state string, wantRunning bool)
- func (t *Tracker) SetLatestVersion(v *tailcfg.ClientVersion)
- func (t *Tracker) SetLocalLogConfigHealth(err error)
- func (t *Tracker) SetMagicSockDERPHome(region int, homeless bool)
- func (t *Tracker) SetMetricsRegistry(reg *usermetric.Registry)
- func (t *Tracker) SetOutOfPollNetMap()
- func (t *Tracker) SetRouterHealth(err error)deprecated
- func (t *Tracker) SetTKAHealth(err error)deprecated
- func (t *Tracker) SetTLSConnectionError(host string, err error)
- func (t *Tracker) SetUDP4Unbound(unbound bool)
- func (t *Tracker) SetUnhealthy(w *Warnable, args Args)
- func (t *Tracker) Strings() []string
- func (t *Tracker) TKAHealth() errordeprecated
- type UnhealthyState
- type UnhealthyStateAction
- type Warnable
- type WarnableCode
Constants¶
const (// SysRouter is the name of the wgengine/router subsystem.SysRouter =Subsystem("router")// SysDNS is the name of the net/dns subsystem.SysDNS =Subsystem("dns")// SysDNSManager is the name of the net/dns manager subsystem.SysDNSManager =Subsystem("dns-manager")// SysTKA is the name of the tailnet key authority subsystem.SysTKA =Subsystem("tailnet-lock"))
const MetricLabelWarning = "warning"Variables¶
var IPNStateWarnable = condRegister(func() *Warnable {return &Warnable{Code:tsconst.HealthWarnableWantRunningFalse,Title: "Tailscale off",Severity:SeverityLow,Text:StaticMessage("Tailscale is stopped."),}})
IPNStateWarnable is a Warnable that warns the user that Tailscale is stopped.
var LoginStateWarnable = condRegister(func() *Warnable {return &Warnable{Code:tsconst.HealthWarnableLoginState,Title: "Logged out",Severity:SeverityMedium,Text: func(argsArgs)string {if args[ArgError] != "" {returnfmt.Sprintf("You are logged out. The last login error was: %v", args[ArgError])} else {return "You are logged out."}},DependsOn: []*Warnable{IPNStateWarnable},}})
LoginStateWarnable is a Warnable that warns the user that they are logged out,and provides the last login error if available.
var NetworkStatusWarnable = condRegister(func() *Warnable {return &Warnable{Code:tsconst.HealthWarnableNetworkStatus,Title: "Network down",Severity:SeverityMedium,Text:StaticMessage("Tailscale cannot connect because the network is down. Check your Internet connection."),ImpactsConnectivity:true,TimeToVisible: 5 *time.Second,}})
NetworkStatusWarnable is a Warnable that warns the user that the network is down.
Functions¶
funcDebugHandler¶added inv1.20.0
funcRegisterDebugHandler¶added inv1.20.0
funcStaticMessage¶added inv1.70.0
StaticMessage returns a function that always returns the input string, to be used insimple Warnables that do not use the Args map to generate their Text.
Types¶
typeArg¶added inv1.70.0
type Argstring
Arg is a type for the key to be used in the Args of a Warnable.
const (// ArgAvailableVersion provides an update notification Warnable with the available version of the Tailscale client.ArgAvailableVersionArg = "available-version"// ArgCurrentVersion provides an update notification Warnable with the current version of the Tailscale client.ArgCurrentVersionArg = "current-version"// ArgDuration provides a Warnable with how long the Warnable has been in an unhealthy state.ArgDurationArg = "duration"// ArgError provides a Warnable with the underlying error behind an unhealthy state.ArgErrorArg = "error"// ArgMagicsockFunctionName provides a Warnable with the name of the Magicsock function that caused the unhealthy state.ArgMagicsockFunctionNameArg = "magicsock-function-name"// ArgDERPRegionID provides a Warnable with the ID of a DERP server involved in the unhealthy state.ArgDERPRegionIDArg = "derp-region-id"// ArgDERPRegionName provides a Warnable with the name of a DERP server involved in the unhealthy state.// It is used to show a more friendly message like "the Seattle relay server failed to connect" versus// "relay server 10 failed to connect".ArgDERPRegionNameArg = "derp-region-name"// ArgServerName provides a Warnable with the hostname of a server involved in the unhealthy state.ArgServerNameArg = "server-name"// ArgServerName provides a Warnable with comma delimited list of the hostname of the servers involved in the unhealthy state.// If no nameservers were available to query, this will be an empty string.ArgDNSServersArg = "dns-servers")
typeArgs¶added inv1.70.0
Args is a map of Args to string values that can be used to provide parameters regardingthe unhealthy state of a Warnable.For instance, if you have a Warnable to track the health of DNS lookups, here you can includethe hostname that failed to resolve, or the IP address of the DNS server that has been failingto respond. You can then use these parameters in the Text function of the Warnable to provide a detailederror message to the user.
typeChange¶added inv1.86.0
type Change struct {// ControlHealthChanged indicates it was health messages from the// control-plane server that changed.ControlHealthChangedbool// WarnableChanged indicates it was a client Warnable which changed state.WarnableChangedbool// Warnable is whose health changed, as indicated in UnhealthyState.Warnable *Warnable// UnhealthyState is set if the changed Warnable is now unhealthy, or nil// if Warnable is now healthy.UnhealthyState *UnhealthyState}Change is used to communicate a change to health. This could either be due toa Warnable changing from health to unhealthy (or vice-versa), or because thehealth messages received from the control-plane have changed.
Exactly one *Changed field will be true.
typeReceiveFunc¶added inv1.66.0
type ReceiveFuncint
ReceiveFunc is one of the three magicsock Receive funcs (IPv4, IPv6, orDERP).
const (ReceiveIPv4ReceiveFunc = 0ReceiveIPv6ReceiveFunc = 1ReceiveDERPReceiveFunc = 2)
ReceiveFunc indices for Tracker.MagicSockReceiveFuncs.
func (ReceiveFunc)String¶added inv1.66.0
func (fReceiveFunc) String()string
typeReceiveFuncStats¶added inv1.8.0
type ReceiveFuncStats struct {// contains filtered or unexported fields}ReceiveFuncStats tracks the calls made to a wireguard-go receive func.
func (*ReceiveFuncStats)Enter¶added inv1.8.0
func (s *ReceiveFuncStats) Enter()
func (*ReceiveFuncStats)Exit¶added inv1.8.0
func (s *ReceiveFuncStats) Exit()
func (*ReceiveFuncStats)Name¶added inv1.72.0
func (s *ReceiveFuncStats) Name()string
Name returns the name of the receive func ("ReceiveIPv4", "ReceiveIPv6", etc).
typeSeverity¶added inv1.70.0
type Severitystring
Severity represents how serious an error is. Each GUI interprets this severity value in different ways,to surface the error in a more or less visible way. For instance, the macOS GUI could change its menubaricon to display an exclamation mark and present a modal notification for SeverityHigh warnings, but notfor SeverityLow messages, which would only appear in the Settings window.
const (// SeverityHigh is the highest severity level, used for critical errors that need immediate attention.// On platforms where the client GUI can deliver notifications, a SeverityHigh Warnable will trigger// a modal notification.SeverityHighSeverity = "high"// SeverityMedium is used for errors that are important but not critical. This won't trigger a modal// notification, however it will be displayed in a more visible way than a SeverityLow Warnable.SeverityMediumSeverity = "medium"// SeverityLow is used for less important notices that don't need immediate attention. The user will// have to go to a Settings window, or another "hidden" GUI location to see these messages.SeverityLowSeverity = "low")
typeState¶added inv1.70.0
type State struct {// Each key-value pair in Warnings represents a Warnable that is currently// unhealthy. If a Warnable is healthy, it will not be present in this map.// When a Warnable is unhealthy and becomes healthy, its key-value pair// disappears in the next issued State. Observers should treat the absence of// a WarnableCode in this map as an indication that the Warnable became healthy,// and may use that to clear any notifications that were previously shown to the user.// If Warnings is nil, all Warnables are healthy and the backend is overall healthy.Warnings map[WarnableCode]UnhealthyState}State contains the health status of the backend, and isprovided to the client UI via LocalAPI through ipn.Notify.
It is also exposed via c2n for debugging purposes, so trynot to change its structure too gratuitously.
typeTracker¶added inv1.66.0
type Tracker struct {// MagicSockReceiveFuncs tracks the state of the three// magicsock receive functions: IPv4, IPv6, and DERP.MagicSockReceiveFuncs [3]ReceiveFuncStats// indexed by ReceiveFunc values// contains filtered or unexported fields}Tracker tracks the health of various Tailscale subsystems,comparing each subsystems' state with each other to make surethey're consistent based on the user's intended state.
If a clientWarnable becomes unhealthy or its unhealthy state is updated,an event will be emitted with WarnableChanged set to true and the Warnableand its UnhealthyState:
Change{WarnableChanged: true, Warnable: w, UnhealthyState: us}If a Warnable becomes healthy, an event will be emitted withWarnableChanged set to true, the Warnable set, and UnhealthyState set to nil:
Change{WarnableChanged: true, Warnable: w, UnhealthyState: nil}If the health messages from the control-plane change, an event will beemitted with ControlHealthChanged set to true. Recipients can fetch the set ofcontrol-plane health messages by callingTracker.CurrentState:
funcNewTracker¶added inv1.90.0
NewTracker contructs a newTracker and attaches the given eventbus.NewTracker will panic is no eventbus is given.
func (*Tracker)AppendWarnableDebugFlags¶added inv1.66.0
AppendWarnableDebugFlags appends to base any health items that are currently in failedstate and were created with MapDebugFlag.
func (*Tracker)CurrentState¶added inv1.70.0
CurrentState returns a snapshot of the current health status of the backend.It returns a State with nil Warnings if the backend is healthy (all Warnableshave no issues).The returned State is a snapshot of shared memory, and the caller should notmutate the returned value.
func (*Tracker)GetDERPRegionReceivedTime¶added inv1.66.0
GetDERPRegionReceivedTime returns the last time that a frame was receivedfrom the given DERP region, or the zero time if no communication with thatregion has occurred.
func (*Tracker)GetInPollNetMap¶added inv1.66.0
GetInPollNetMap reports whether the client has an openHTTP long poll open to the control plane.
func (*Tracker)GotStreamedMapResponse¶added inv1.66.0
func (t *Tracker) GotStreamedMapResponse()
GotStreamedMapResponse notes that we got a tailcfg.MapResponsemessage in streaming mode, even if it's just a keep-alive message.
This also notes that a map poll is in progress. To unset that, callSetOutOfPollNetMap().
func (*Tracker)IsUnhealthy¶added inv1.84.0
IsUnhealthy reports whether the current state is unhealthy because the givenwarnable is set.
func (*Tracker)LastNoiseDialWasRecent¶added inv1.76.0
LastNoiseDialWasRecent notes that we're attempting to dial control via thets2021 noise protocol and reports whether the prior dial was "recent"(currently defined as 2 minutes but subject to change).
If t is nil, it reports false.
func (*Tracker)NoteDERPRegionReceivedFrame¶added inv1.66.0
NoteDERPRegionReceivedFrame is called to note that a frame was received fromthe given DERP region at the current time.
func (*Tracker)NoteMapRequestHeard¶added inv1.66.0
func (t *Tracker) NoteMapRequestHeard(mr *tailcfg.MapRequest)
NoteMapRequestHeard notes whenever we successfully sent a map requestto control for which we received a 200 response.
func (*Tracker)OverallError¶added inv1.66.0
OverallError returns a summary of the health state.
If there are multiple problems, the error will be joined usingerrors.Join.
func (*Tracker)ReceiveFuncStats¶added inv1.66.0
func (t *Tracker) ReceiveFuncStats(whichReceiveFunc) *ReceiveFuncStats
ReceiveFuncStats returns the ReceiveFuncStats tracker for the given functype.
If t is nil, it returns nil.
func (*Tracker)RouterHealthdeprecatedadded inv1.66.0
func (*Tracker)SetAnyInterfaceUp¶added inv1.66.0
SetAnyInterfaceUp sets whether any network interface is up.
func (*Tracker)SetAuthRoutineInError¶added inv1.66.0
SetAuthRoutineInError records the latest error encountered as a result of alogin attempt. Providing a nil error indicates successful login, or thatbeing logged in w/coordination is not currently desired.
func (*Tracker)SetAutoUpdatePrefs¶added inv1.70.0
SetAutoUpdatePrefs sets the client auto-update preferences. The argumentsmatch the fields of ipn.AutoUpdatePrefs, but we cannot pass that structdirectly due to a circular import.
func (*Tracker)SetControlHealth¶added inv1.66.0
func (t *Tracker) SetControlHealth(problems map[tailcfg.DisplayMessageID]tailcfg.DisplayMessage)
func (*Tracker)SetDERPMap¶added inv1.70.0
SetDERPMap sets the last fetched DERP map in the Tracker. The DERP map is usedto provide a region name in user-facing DERP-related warnings.
func (*Tracker)SetDERPRegionConnectedState¶added inv1.66.0
func (*Tracker)SetDERPRegionHealth¶added inv1.66.0
SetDERPRegionHealth sets or clears any problem associated with theprovided DERP region.
func (*Tracker)SetDNSHealthdeprecatedadded inv1.66.0
func (*Tracker)SetDNSManagerHealthdeprecatedadded inv1.66.0
func (*Tracker)SetHealthy¶added inv1.70.0
SetHealthy removes any warningState for the given Warnable.
func (*Tracker)SetIPNState¶added inv1.66.0
state is an ipn.State.String() value: "Running", "Stopped", "NeedsLogin", etc.
func (*Tracker)SetLatestVersion¶added inv1.66.0
func (t *Tracker) SetLatestVersion(v *tailcfg.ClientVersion)
SetLatestVersion records the latest version of the Tailscale client.v can be nil if unknown.
func (*Tracker)SetLocalLogConfigHealth¶added inv1.66.0
SetLocalLogConfigHealth sets the error state of this client's local log configuration.
func (*Tracker)SetMagicSockDERPHome¶added inv1.66.0
SetMagicSockDERPHome notes what magicsock's view of its home DERP is.
The homeless parameter is whether magicsock is running in DERP-disconnectedmode, without discovering and maintaining a connection to its home DERP.
func (*Tracker)SetMetricsRegistry¶added inv1.76.0
func (t *Tracker) SetMetricsRegistry(reg *usermetric.Registry)
SetMetricsRegistry sets up the metrics for the Tracker. It takesa usermetric.Registry and registers the metrics there.
func (*Tracker)SetOutOfPollNetMap¶added inv1.66.0
func (t *Tracker) SetOutOfPollNetMap()
SetOutOfPollNetMap records that the client is no longer inan HTTP map request long poll to the control plane.
func (*Tracker)SetRouterHealthdeprecatedadded inv1.66.0
func (*Tracker)SetTKAHealthdeprecatedadded inv1.66.0
func (*Tracker)SetTLSConnectionError¶added inv1.66.0
SetTLSConnectionError sets the error state for connections to a specifichost. Setting the error to nil will clear any previously-set error.
func (*Tracker)SetUDP4Unbound¶added inv1.66.0
SetUDP4Unbound sets whether the udp4 bind failed completely.
func (*Tracker)SetUnhealthy¶added inv1.70.0
SetUnhealthy sets a warningState for the given Warnable with the provided Args, and should becalled when a Warnable becomes unhealthy, or its unhealthy status needs to be updated.SetUnhealthy takes ownership of args. The args can be nil if no additional information isneeded for the unhealthy state.
func (*Tracker)Strings¶added inv1.70.0
Strings() returns a string array containing the Text of all Warnings andControlHealth messages currently known to the Tracker. These strings can bepresented to the user, although ideally you would use the Code property oneach Warning to show a localized version of them instead. This function ishere for legacy compatibility purposes and is deprecated.
typeUnhealthyState¶added inv1.70.0
type UnhealthyState struct {WarnableCodeWarnableCodeSeveritySeverityTitlestringTextstringBrokenSince *time.Time `json:",omitempty"`ArgsArgs `json:",omitempty"`DependsOn []WarnableCode `json:",omitempty"`ImpactsConnectivitybool `json:",omitempty"`PrimaryAction *UnhealthyStateAction `json:",omitempty"`// ETag identifies a specific version of an UnhealthyState. If the contents// of the other fields of two UnhealthyStates are the same, the ETags will// be the same. If the contents differ, the ETags will also differ. The// implementation is not defined and the value is opaque: it might be a// hash, it might be a simple counter. Implementations should not rely on// any specific implementation detail or format of the ETag string other// than string (in)equality.ETagstring `json:",omitzero"`}UnhealthyState contains information to be shown to the user to inform themthat aWarnable is currently unhealthy ortailcfg.DisplayMessage is beingsent from the control-plane.
typeUnhealthyStateAction¶added inv1.86.0
UnhealthyStateAction represents an action (URL and link) to be presented tothe user associated with anUnhealthyState. Analogous totailcfg.DisplayMessageAction.
typeWarnable¶added inv1.34.0
type Warnable struct {// Code is a string that uniquely identifies this Warnable across the entire Tailscale backend,// and can be mapped to a user-displayable localized string.CodeWarnableCode// Title is a string that the GUI uses as title for any message involving this Warnable. The title// should be short and fit in a single line.Titlestring// Text is a function that generates an extended string that the GUI will display to the user when// this Warnable is in an unhealthy state. The function can use the Args map to provide dynamic// information to the user.Text func(argsArgs)string// Severity is the severity of the Warnable, which the GUI can use to determine how to display it.// For instance, a Warnable with SeverityHigh could trigger a modal view, while a Warnable with// SeverityLow could be displayed in a less intrusive way.// TODO(angott): turn this into a SeverityFunc, which allows the Warnable to change its severity based on// the Args of the unhappy state, just like we do in the Text function.SeveritySeverity// DependsOn is a set of Warnables that this Warnable depends on and need to be healthy// before this Warnable is relevant. The GUI can use this information to ignore// this Warnable if one of its dependencies is unhealthy.// That is, if any of these Warnables are unhealthy, then this Warnable is not relevant// and should be considered healthy to bother the user about.DependsOn []*Warnable// MapDebugFlag is a MapRequest.DebugFlag that is sent to control when this Warnable is unhealthy//// Deprecated: this is only used in one case, and will be removed in a future PRMapDebugFlagstring// ImpactsConnectivity is whether this Warnable in an unhealthy state will impact the user's// ability to connect to the Internet or other nodes on the tailnet. On platforms where// the client GUI supports a tray icon, the client will display an exclamation mark// on the tray icon when ImpactsConnectivity is set to true and the Warnable is unhealthy.ImpactsConnectivitybool// TimeToVisible is the Duration that the Warnable has to be in an unhealthy state before it// should be surfaced as unhealthy to the user. This is used to prevent transient errors from being// displayed to the user.TimeToVisibletime.Duration}A Warnable is something that we might want to warn the user about, or not. AWarnable is either in a healthy or unhealthy state. A Warnable is unhealthy ifthe Tracker knows about a WarningState affecting the Warnable.
In most cases, Warnables are components of the backend (for instance, "DNS"or "Magicsock"). Warnables are similar to the Subsystem type previously usedin this package, but they provide a unique identifying code for eachWarnable, along with more metadata that makes it easier for a GUI to displaythe Warnable in a user-friendly way.
typeWarnableCode¶added inv1.70.0
type WarnableCodestring
WarnableCode is a string that distinguishes each Warnable from others. It is globally unique withinthe program.