cmd/tailscale: make status show health check problems

Fixes #2775

RELNOTE=tailscale status now shows health check problems

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-09-16 11:24:44 -07:00
parent 73f177e4d5
commit 4549d3151c
2 changed files with 15 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ package health
import (
"errors"
"fmt"
"os"
"sort"
"sync"
"sync/atomic"
@@ -265,6 +266,8 @@ func OverallError() error {
return overallErrorLocked()
}
var fakeErrForTesting = os.Getenv("TS_DEBUG_FAKE_HEALTH_ERROR")
func overallErrorLocked() error {
if !anyInterfaceUp {
return errors.New("network down")
@@ -315,6 +318,9 @@ func overallErrorLocked() error {
for regionID, problem := range derpRegionHealthProblem {
errs = append(errs, fmt.Errorf("derp%d: %v", regionID, problem))
}
if e := fakeErrForTesting; len(errs) == 0 && e != "" {
return errors.New(e)
}
sort.Slice(errs, func(i, j int) bool {
// Not super efficient (stringifying these in a sort), but probably max 2 or 3 items.
return errs[i].Error() < errs[j].Error()