Skip to content

Commit 7418583

Browse files
authored
health: compare warnable codes to avoid errors on release branch (tailscale#17637)
This compares the warnings we actually care about and skips the unstable warnings and the changes with no warnings. Fixes tailscale#17635 Signed-off-by: Claus Lensbøl <[email protected]>
1 parent d47c697 commit 7418583

File tree

5 files changed

+77
-27
lines changed

5 files changed

+77
-27
lines changed

cmd/derper/depaware.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
116116
tailscale.com/syncs from tailscale.com/cmd/derper+
117117
tailscale.com/tailcfg from tailscale.com/client/local+
118118
tailscale.com/tka from tailscale.com/client/local+
119-
LW tailscale.com/tsconst from tailscale.com/net/netmon+
119+
tailscale.com/tsconst from tailscale.com/net/netmon+
120120
tailscale.com/tstime from tailscale.com/derp+
121121
tailscale.com/tstime/mono from tailscale.com/tstime/rate
122122
tailscale.com/tstime/rate from tailscale.com/derp/derpserver

cmd/tailscaled/depaware-min.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
116116
tailscale.com/tailcfg from tailscale.com/client/tailscale/apitype+
117117
tailscale.com/tempfork/heap from tailscale.com/wgengine/magicsock
118118
tailscale.com/tka from tailscale.com/control/controlclient+
119-
tailscale.com/tsconst from tailscale.com/net/netns
119+
tailscale.com/tsconst from tailscale.com/net/netns+
120120
tailscale.com/tsd from tailscale.com/cmd/tailscaled+
121121
tailscale.com/tstime from tailscale.com/control/controlclient+
122122
tailscale.com/tstime/mono from tailscale.com/net/tstun+

health/health_test.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/google/go-cmp/cmp/cmpopts"
2020
"tailscale.com/metrics"
2121
"tailscale.com/tailcfg"
22+
"tailscale.com/tsconst"
2223
"tailscale.com/tstest"
2324
"tailscale.com/tstime"
2425
"tailscale.com/types/opt"
@@ -739,21 +740,27 @@ func TestControlHealthNotifies(t *testing.T) {
739740
ht.SetIPNState("NeedsLogin", true)
740741
ht.GotStreamedMapResponse()
741742

742-
// Expect events at starup, before doing anything else
743+
// Expect events at starup, before doing anything else, skip unstable
744+
// event and no warning event as they show up at different times.
743745
synctest.Wait()
744-
if err := eventbustest.ExpectExactly(tw,
745-
eventbustest.Type[Change](), // warming-up
746-
eventbustest.Type[Change](), // is-using-unstable-version
747-
eventbustest.Type[Change](), // not-in-map-poll
746+
if err := eventbustest.Expect(tw,
747+
CompareWarnableCode(t, tsconst.HealthWarnableWarmingUp),
748+
CompareWarnableCode(t, tsconst.HealthWarnableNotInMapPoll),
749+
CompareWarnableCode(t, tsconst.HealthWarnableWarmingUp),
748750
); err != nil {
749751
t.Errorf("startup error: %v", err)
750752
}
751753

752754
// Only set initial state if we need to
753755
if len(test.initialState) != 0 {
756+
t.Log("Setting initial state")
754757
ht.SetControlHealth(test.initialState)
755758
synctest.Wait()
756-
if err := eventbustest.ExpectExactly(tw, eventbustest.Type[Change]()); err != nil {
759+
if err := eventbustest.Expect(tw,
760+
CompareWarnableCode(t, tsconst.HealthWarnableMagicsockReceiveFuncError),
761+
// Skip event with no warnable
762+
CompareWarnableCode(t, tsconst.HealthWarnableNoDERPHome),
763+
); err != nil {
757764
t.Errorf("initial state error: %v", err)
758765
}
759766
}
@@ -771,6 +778,22 @@ func TestControlHealthNotifies(t *testing.T) {
771778
}
772779
}
773780

781+
func CompareWarnableCode(t *testing.T, code string) func(Change) bool {
782+
t.Helper()
783+
return func(c Change) bool {
784+
t.Helper()
785+
if c.Warnable != nil {
786+
t.Logf("Warnable code: %s", c.Warnable.Code)
787+
if string(c.Warnable.Code) == code {
788+
return true
789+
}
790+
} else {
791+
t.Log("No Warnable")
792+
}
793+
return false
794+
}
795+
}
796+
774797
func TestControlHealthIgnoredOutsideMapPoll(t *testing.T) {
775798
synctest.Test(t, func(t *testing.T) {
776799
bus := eventbustest.NewBus(t)

health/warnings.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"tailscale.com/feature/buildfeatures"
12+
"tailscale.com/tsconst"
1213
"tailscale.com/version"
1314
)
1415

@@ -26,7 +27,7 @@ This file contains definitions for the Warnables maintained within this `health`
2627
// updateAvailableWarnable is a Warnable that warns the user that an update is available.
2728
var updateAvailableWarnable = condRegister(func() *Warnable {
2829
return &Warnable{
29-
Code: "update-available",
30+
Code: tsconst.HealthWarnableUpdateAvailable,
3031
Title: "Update available",
3132
Severity: SeverityLow,
3233
Text: func(args Args) string {
@@ -42,7 +43,7 @@ var updateAvailableWarnable = condRegister(func() *Warnable {
4243
// securityUpdateAvailableWarnable is a Warnable that warns the user that an important security update is available.
4344
var securityUpdateAvailableWarnable = condRegister(func() *Warnable {
4445
return &Warnable{
45-
Code: "security-update-available",
46+
Code: tsconst.HealthWarnableSecurityUpdateAvailable,
4647
Title: "Security update available",
4748
Severity: SeverityMedium,
4849
Text: func(args Args) string {
@@ -59,7 +60,7 @@ var securityUpdateAvailableWarnable = condRegister(func() *Warnable {
5960
// so they won't be surprised by all the issues that may arise.
6061
var unstableWarnable = condRegister(func() *Warnable {
6162
return &Warnable{
62-
Code: "is-using-unstable-version",
63+
Code: tsconst.HealthWarnableIsUsingUnstableVersion,
6364
Title: "Using an unstable version",
6465
Severity: SeverityLow,
6566
Text: StaticMessage("This is an unstable version of Tailscale meant for testing and development purposes. Please report any issues to Tailscale."),
@@ -69,7 +70,7 @@ var unstableWarnable = condRegister(func() *Warnable {
6970
// NetworkStatusWarnable is a Warnable that warns the user that the network is down.
7071
var NetworkStatusWarnable = condRegister(func() *Warnable {
7172
return &Warnable{
72-
Code: "network-status",
73+
Code: tsconst.HealthWarnableNetworkStatus,
7374
Title: "Network down",
7475
Severity: SeverityMedium,
7576
Text: StaticMessage("Tailscale cannot connect because the network is down. Check your Internet connection."),
@@ -81,7 +82,7 @@ var NetworkStatusWarnable = condRegister(func() *Warnable {
8182
// IPNStateWarnable is a Warnable that warns the user that Tailscale is stopped.
8283
var IPNStateWarnable = condRegister(func() *Warnable {
8384
return &Warnable{
84-
Code: "wantrunning-false",
85+
Code: tsconst.HealthWarnableWantRunningFalse,
8586
Title: "Tailscale off",
8687
Severity: SeverityLow,
8788
Text: StaticMessage("Tailscale is stopped."),
@@ -91,7 +92,7 @@ var IPNStateWarnable = condRegister(func() *Warnable {
9192
// localLogWarnable is a Warnable that warns the user that the local log is misconfigured.
9293
var localLogWarnable = condRegister(func() *Warnable {
9394
return &Warnable{
94-
Code: "local-log-config-error",
95+
Code: tsconst.HealthWarnableLocalLogConfigError,
9596
Title: "Local log misconfiguration",
9697
Severity: SeverityLow,
9798
Text: func(args Args) string {
@@ -104,7 +105,7 @@ var localLogWarnable = condRegister(func() *Warnable {
104105
// and provides the last login error if available.
105106
var LoginStateWarnable = condRegister(func() *Warnable {
106107
return &Warnable{
107-
Code: "login-state",
108+
Code: tsconst.HealthWarnableLoginState,
108109
Title: "Logged out",
109110
Severity: SeverityMedium,
110111
Text: func(args Args) string {
@@ -121,7 +122,7 @@ var LoginStateWarnable = condRegister(func() *Warnable {
121122
// notInMapPollWarnable is a Warnable that warns the user that we are using a stale network map.
122123
var notInMapPollWarnable = condRegister(func() *Warnable {
123124
return &Warnable{
124-
Code: "not-in-map-poll",
125+
Code: tsconst.HealthWarnableNotInMapPoll,
125126
Title: "Out of sync",
126127
Severity: SeverityMedium,
127128
DependsOn: []*Warnable{NetworkStatusWarnable, IPNStateWarnable},
@@ -134,7 +135,7 @@ var notInMapPollWarnable = condRegister(func() *Warnable {
134135
// noDERPHomeWarnable is a Warnable that warns the user that Tailscale doesn't have a home DERP.
135136
var noDERPHomeWarnable = condRegister(func() *Warnable {
136137
return &Warnable{
137-
Code: "no-derp-home",
138+
Code: tsconst.HealthWarnableNoDERPHome,
138139
Title: "No home relay server",
139140
Severity: SeverityMedium,
140141
DependsOn: []*Warnable{NetworkStatusWarnable},
@@ -147,7 +148,7 @@ var noDERPHomeWarnable = condRegister(func() *Warnable {
147148
// noDERPConnectionWarnable is a Warnable that warns the user that Tailscale couldn't connect to a specific DERP server.
148149
var noDERPConnectionWarnable = condRegister(func() *Warnable {
149150
return &Warnable{
150-
Code: "no-derp-connection",
151+
Code: tsconst.HealthWarnableNoDERPConnection,
151152
Title: "Relay server unavailable",
152153
Severity: SeverityMedium,
153154
DependsOn: []*Warnable{
@@ -177,7 +178,7 @@ var noDERPConnectionWarnable = condRegister(func() *Warnable {
177178
// heard from the home DERP region for a while.
178179
var derpTimeoutWarnable = condRegister(func() *Warnable {
179180
return &Warnable{
180-
Code: "derp-timed-out",
181+
Code: tsconst.HealthWarnableDERPTimedOut,
181182
Title: "Relay server timed out",
182183
Severity: SeverityMedium,
183184
DependsOn: []*Warnable{
@@ -198,7 +199,7 @@ var derpTimeoutWarnable = condRegister(func() *Warnable {
198199
// derpRegionErrorWarnable is a Warnable that warns the user that a DERP region is reporting an issue.
199200
var derpRegionErrorWarnable = condRegister(func() *Warnable {
200201
return &Warnable{
201-
Code: "derp-region-error",
202+
Code: tsconst.HealthWarnableDERPRegionError,
202203
Title: "Relay server error",
203204
Severity: SeverityLow,
204205
DependsOn: []*Warnable{NetworkStatusWarnable},
@@ -211,7 +212,7 @@ var derpRegionErrorWarnable = condRegister(func() *Warnable {
211212
// noUDP4BindWarnable is a Warnable that warns the user that Tailscale couldn't listen for incoming UDP connections.
212213
var noUDP4BindWarnable = condRegister(func() *Warnable {
213214
return &Warnable{
214-
Code: "no-udp4-bind",
215+
Code: tsconst.HealthWarnableNoUDP4Bind,
215216
Title: "NAT traversal setup failure",
216217
Severity: SeverityMedium,
217218
DependsOn: []*Warnable{NetworkStatusWarnable, IPNStateWarnable},
@@ -223,7 +224,7 @@ var noUDP4BindWarnable = condRegister(func() *Warnable {
223224
// mapResponseTimeoutWarnable is a Warnable that warns the user that Tailscale hasn't received a network map from the coordination server in a while.
224225
var mapResponseTimeoutWarnable = condRegister(func() *Warnable {
225226
return &Warnable{
226-
Code: "mapresponse-timeout",
227+
Code: tsconst.HealthWarnableMapResponseTimeout,
227228
Title: "Network map response timeout",
228229
Severity: SeverityMedium,
229230
DependsOn: []*Warnable{NetworkStatusWarnable, IPNStateWarnable},
@@ -236,7 +237,7 @@ var mapResponseTimeoutWarnable = condRegister(func() *Warnable {
236237
// tlsConnectionFailedWarnable is a Warnable that warns the user that Tailscale could not establish an encrypted connection with a server.
237238
var tlsConnectionFailedWarnable = condRegister(func() *Warnable {
238239
return &Warnable{
239-
Code: "tls-connection-failed",
240+
Code: tsconst.HealthWarnableTLSConnectionFailed,
240241
Title: "Encrypted connection failed",
241242
Severity: SeverityMedium,
242243
DependsOn: []*Warnable{NetworkStatusWarnable},
@@ -249,7 +250,7 @@ var tlsConnectionFailedWarnable = condRegister(func() *Warnable {
249250
// magicsockReceiveFuncWarnable is a Warnable that warns the user that one of the Magicsock functions is not running.
250251
var magicsockReceiveFuncWarnable = condRegister(func() *Warnable {
251252
return &Warnable{
252-
Code: "magicsock-receive-func-error",
253+
Code: tsconst.HealthWarnableMagicsockReceiveFuncError,
253254
Title: "MagicSock function not running",
254255
Severity: SeverityMedium,
255256
Text: func(args Args) string {
@@ -261,7 +262,7 @@ var magicsockReceiveFuncWarnable = condRegister(func() *Warnable {
261262
// testWarnable is a Warnable that is used within this package for testing purposes only.
262263
var testWarnable = condRegister(func() *Warnable {
263264
return &Warnable{
264-
Code: "test-warnable",
265+
Code: tsconst.HealthWarnableTestWarnable,
265266
Title: "Test warnable",
266267
Severity: SeverityLow,
267268
Text: func(args Args) string {
@@ -273,7 +274,7 @@ var testWarnable = condRegister(func() *Warnable {
273274
// applyDiskConfigWarnable is a Warnable that warns the user that there was an error applying the envknob config stored on disk.
274275
var applyDiskConfigWarnable = condRegister(func() *Warnable {
275276
return &Warnable{
276-
Code: "apply-disk-config",
277+
Code: tsconst.HealthWarnableApplyDiskConfig,
277278
Title: "Could not apply configuration",
278279
Severity: SeverityMedium,
279280
Text: func(args Args) string {
@@ -291,7 +292,7 @@ const warmingUpWarnableDuration = 5 * time.Second
291292
// the backend is fully started.
292293
var warmingUpWarnable = condRegister(func() *Warnable {
293294
return &Warnable{
294-
Code: "warming-up",
295+
Code: tsconst.HealthWarnableWarmingUp,
295296
Title: "Tailscale is starting",
296297
Severity: SeverityLow,
297298
Text: StaticMessage("Tailscale is starting. Please wait."),

tsconst/health.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Tailscale Inc & AUTHORS
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
package tsconst
5+
6+
const (
7+
HealthWarnableUpdateAvailable = "update-available"
8+
HealthWarnableSecurityUpdateAvailable = "security-update-available"
9+
HealthWarnableIsUsingUnstableVersion = "is-using-unstable-version"
10+
HealthWarnableNetworkStatus = "network-status"
11+
HealthWarnableWantRunningFalse = "wantrunning-false"
12+
HealthWarnableLocalLogConfigError = "local-log-config-error"
13+
HealthWarnableLoginState = "login-state"
14+
HealthWarnableNotInMapPoll = "not-in-map-poll"
15+
HealthWarnableNoDERPHome = "no-derp-home"
16+
HealthWarnableNoDERPConnection = "no-derp-connection"
17+
HealthWarnableDERPTimedOut = "derp-timed-out"
18+
HealthWarnableDERPRegionError = "derp-region-error"
19+
HealthWarnableNoUDP4Bind = "no-udp4-bind"
20+
HealthWarnableMapResponseTimeout = "mapresponse-timeout"
21+
HealthWarnableTLSConnectionFailed = "tls-connection-failed"
22+
HealthWarnableMagicsockReceiveFuncError = "magicsock-receive-func-error"
23+
HealthWarnableTestWarnable = "test-warnable"
24+
HealthWarnableApplyDiskConfig = "apply-disk-config"
25+
HealthWarnableWarmingUp = "warming-up"
26+
)

0 commit comments

Comments
 (0)