Skip to content
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

autopilot: include only servers from the same region #15290

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .changelog/15290.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
autopilot: Fixed a bug where autopilot would try to fetch raft stats from other regions
```
5 changes: 4 additions & 1 deletion nomad/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (s *Server) autopilotServers() map[raft.ServerID]*autopilot.Server {
s.logger.Warn("Error parsing server info", "name", member.Name, "error", err)
continue
} else if srv == nil {
// this member was a client
// this member was a client or in another region
continue
}

Expand All @@ -210,6 +210,9 @@ func (s *Server) autopilotServer(m serf.Member) (*autopilot.Server, error) {
if !ok {
return nil, nil
}
if srv.Region != s.Region() {
return nil, nil
}

return s.autopilotServerFromMetadata(srv)
}
Expand Down
36 changes: 36 additions & 0 deletions nomad/autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,42 @@ func TestAutopilot_RollingUpdate(t *testing.T) {
waitForStableLeadership(t, servers)
}

func TestAutopilot_MultiRegion(t *testing.T) {
ci.Parallel(t)

conf := func(c *Config) {
c.NumSchedulers = 0 // reduces test log noise
c.BootstrapExpect = 3
}
s1, cleanupS1 := TestServer(t, conf)
defer cleanupS1()

s2, cleanupS2 := TestServer(t, conf)
defer cleanupS2()

s3, cleanupS3 := TestServer(t, conf)
defer cleanupS3()

// federated regions should not be considered raft peers or show up in the
// known servers list
s4, cleanupS4 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 0
c.Region = "other"
})
defer cleanupS4()

servers := []*Server{s1, s2, s3}
TestJoin(t, s1, s2, s3, s4)

t.Logf("waiting for initial stable cluster")
waitForStableLeadership(t, servers)

apDelegate := &AutopilotDelegate{s3}
known := apDelegate.KnownServers()
must.Eq(t, 3, len(known))

}

func TestAutopilot_CleanupStaleRaftServer(t *testing.T) {
ci.Parallel(t)

Expand Down