Tweak last_contact health logic for leader

This commit is contained in:
Kyle Havlovitz 2017-03-15 19:57:54 -07:00
parent bc0494e396
commit 9c7bba7903
No known key found for this signature in database
GPG Key ID: 8A5E6B173056AD6C
4 changed files with 15 additions and 16 deletions

View File

@ -199,7 +199,9 @@ func (s *Server) serverHealthLoop() {
case <-s.shutdownCh:
return
case <-ticker.C:
s.updateClusterHealth()
if err := s.updateClusterHealth(); err != nil {
s.logger.Printf("[ERR] consul: error updating cluster health: %s", err)
}
}
}
}
@ -254,12 +256,7 @@ func (s *Server) updateClusterHealth() error {
ID: string(server.ID),
Address: string(server.Address),
LastContact: -1,
Voter: server.Suffrage != raft.Nonvoter,
}
// Set LastContact to 0 for the leader
if s.raft.Leader() == server.Address {
health.LastContact = 0
Voter: server.Suffrage == raft.Voter,
}
member, ok := serverMap[string(server.ID)]
@ -286,8 +283,9 @@ func (s *Server) updateClusterHealth() error {
clusterHealth.Healthy = healthyCount == len(servers)
// If we have extra healthy voters, update FailureTolerance
if voterCount > len(servers)/2+1 {
clusterHealth.FailureTolerance = voterCount - (len(servers)/2 + 1)
requiredQuorum := len(servers)/2 + 1
if voterCount > requiredQuorum {
clusterHealth.FailureTolerance = voterCount - requiredQuorum
}
// Heartbeat a metric for monitoring if we're the leader

View File

@ -580,7 +580,6 @@ func (s *Server) joinConsulServer(m serf.Member, parts *agent.Server) error {
}
}
// TODO (slackpad) - This will need to be changed once we support node IDs.
addr := (&net.TCPAddr{IP: m.Addr, Port: parts.Port}).String()
minRaftProtocol, err := ServerMinRaftProtocol(s.serfLAN.Members())

View File

@ -979,10 +979,10 @@ func (r *Raft) Stats() map[string]string {
}
last := r.LastContact()
if last.IsZero() {
s["last_contact"] = "never"
} else if r.getState() == Leader {
if r.getState() == Leader {
s["last_contact"] = "0"
} else if last.IsZero() {
s["last_contact"] = "never"
} else {
s["last_contact"] = fmt.Sprintf("%v", time.Now().Sub(last))
}

8
vendor/vendor.json vendored
View File

@ -600,10 +600,12 @@
"revisionTime": "2015-11-16T02:03:38Z"
},
{
"checksumSHA1": "wpirHJV/6VEbbD+HyAP2/6Xc0ek=",
"checksumSHA1": "NvFexY/rs9sPfve+ny/rkMkCL5M=",
"path": "github.com/hashicorp/raft",
"revision": "aaad9f10266e089bd401e7a6487651a69275641b",
"revisionTime": "2016-11-10T00:52:40Z"
"revision": "6b063a18bfe6e0da3fdc2b9bf6256be9c0a4849a",
"revisionTime": "2017-03-16T02:42:32Z",
"version": "library-v2-stage-one",
"versionExact": "library-v2-stage-one"
},
{
"checksumSHA1": "QAxukkv54/iIvLfsUP6IK4R0m/A=",