Skip to content

fix: preserve order of node reports in healthcheck #10835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
sort in place
  • Loading branch information
mtojek committed Nov 22, 2023
commit 3dcdb3e4f6f7a1bbd2b8f807b6c218d54e1044cc
10 changes: 3 additions & 7 deletions coderd/healthcheck/derphealth/derp.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (r *RegionReport) Run(ctx context.Context) {
r.mu.Lock()
defer r.mu.Unlock()

r.NodeReports = sortedNodeReports(r.NodeReports)
sortNodeReports(r.NodeReports)

// Coder allows for 1 unhealthy node in the region, unless there is only 1 node.
if len(r.Region.Nodes) == 1 {
Expand Down Expand Up @@ -500,12 +500,8 @@ func convertError(err error) *string {
return nil
}

func sortedNodeReports(reports []*NodeReport) []*NodeReport {
sorted := make([]*NodeReport, len(reports))
copy(sorted, reports)

slices.SortFunc(sorted, func(a, b *NodeReport) int {
func sortNodeReports(reports []*NodeReport) {
slices.SortFunc(reports, func(a, b *NodeReport) int {
return slice.Ascending(a.Node.Name, b.Node.Name)
})
return sorted
}