fix: preserve order of node reports in healthcheck (#10835)

This commit is contained in:
Marcin Tojek 2023-11-22 11:15:11 +01:00 committed by GitHub
parent 60c01555b9
commit 8dd003ba5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import (
"sync/atomic"
"time"
"golang.org/x/exp/slices"
"golang.org/x/xerrors"
"tailscale.com/derp"
"tailscale.com/derp/derphttp"
@ -22,6 +23,7 @@ import (
tslogger "tailscale.com/types/logger"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/coderd/util/slice"
)
const (
@ -183,6 +185,11 @@ func (r *RegionReport) Run(ctx context.Context) {
}
wg.Wait()
r.mu.Lock()
defer r.mu.Unlock()
sortNodeReports(r.NodeReports)
// Coder allows for 1 unhealthy node in the region, unless there is only 1 node.
if len(r.Region.Nodes) == 1 {
r.Healthy = healthyNodes == len(r.Region.Nodes)
@ -492,3 +499,9 @@ func convertError(err error) *string {
return nil
}
func sortNodeReports(reports []*NodeReport) {
slices.SortFunc(reports, func(a, b *NodeReport) int {
return slice.Ascending(a.Node.Name, b.Node.Name)
})
}

View File

@ -83,7 +83,6 @@ func TestDERP(t *testing.T) {
t.Run("HealthyWithNodeDegraded", func(t *testing.T) {
t.Parallel()
t.Skip("https://github.com/coder/coder/issues/10824")
healthyDerpSrv := derp.NewServer(key.NewNode(), func(format string, args ...any) { t.Logf(format, args...) })
defer healthyDerpSrv.Close()