Tweak last_contact health logic for leader
This commit is contained in:
parent
bc0494e396
commit
9c7bba7903
|
@ -199,7 +199,9 @@ func (s *Server) serverHealthLoop() {
|
||||||
case <-s.shutdownCh:
|
case <-s.shutdownCh:
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
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),
|
ID: string(server.ID),
|
||||||
Address: string(server.Address),
|
Address: string(server.Address),
|
||||||
LastContact: -1,
|
LastContact: -1,
|
||||||
Voter: server.Suffrage != raft.Nonvoter,
|
Voter: server.Suffrage == raft.Voter,
|
||||||
}
|
|
||||||
|
|
||||||
// Set LastContact to 0 for the leader
|
|
||||||
if s.raft.Leader() == server.Address {
|
|
||||||
health.LastContact = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
member, ok := serverMap[string(server.ID)]
|
member, ok := serverMap[string(server.ID)]
|
||||||
|
@ -286,8 +283,9 @@ func (s *Server) updateClusterHealth() error {
|
||||||
clusterHealth.Healthy = healthyCount == len(servers)
|
clusterHealth.Healthy = healthyCount == len(servers)
|
||||||
|
|
||||||
// If we have extra healthy voters, update FailureTolerance
|
// If we have extra healthy voters, update FailureTolerance
|
||||||
if voterCount > len(servers)/2+1 {
|
requiredQuorum := len(servers)/2 + 1
|
||||||
clusterHealth.FailureTolerance = voterCount - (len(servers)/2 + 1)
|
if voterCount > requiredQuorum {
|
||||||
|
clusterHealth.FailureTolerance = voterCount - requiredQuorum
|
||||||
}
|
}
|
||||||
|
|
||||||
// Heartbeat a metric for monitoring if we're the leader
|
// Heartbeat a metric for monitoring if we're the leader
|
||||||
|
|
|
@ -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()
|
addr := (&net.TCPAddr{IP: m.Addr, Port: parts.Port}).String()
|
||||||
|
|
||||||
minRaftProtocol, err := ServerMinRaftProtocol(s.serfLAN.Members())
|
minRaftProtocol, err := ServerMinRaftProtocol(s.serfLAN.Members())
|
||||||
|
|
|
@ -979,10 +979,10 @@ func (r *Raft) Stats() map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
last := r.LastContact()
|
last := r.LastContact()
|
||||||
if last.IsZero() {
|
if r.getState() == Leader {
|
||||||
s["last_contact"] = "never"
|
|
||||||
} else if r.getState() == Leader {
|
|
||||||
s["last_contact"] = "0"
|
s["last_contact"] = "0"
|
||||||
|
} else if last.IsZero() {
|
||||||
|
s["last_contact"] = "never"
|
||||||
} else {
|
} else {
|
||||||
s["last_contact"] = fmt.Sprintf("%v", time.Now().Sub(last))
|
s["last_contact"] = fmt.Sprintf("%v", time.Now().Sub(last))
|
||||||
}
|
}
|
||||||
|
|
|
@ -600,10 +600,12 @@
|
||||||
"revisionTime": "2015-11-16T02:03:38Z"
|
"revisionTime": "2015-11-16T02:03:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "wpirHJV/6VEbbD+HyAP2/6Xc0ek=",
|
"checksumSHA1": "NvFexY/rs9sPfve+ny/rkMkCL5M=",
|
||||||
"path": "github.com/hashicorp/raft",
|
"path": "github.com/hashicorp/raft",
|
||||||
"revision": "aaad9f10266e089bd401e7a6487651a69275641b",
|
"revision": "6b063a18bfe6e0da3fdc2b9bf6256be9c0a4849a",
|
||||||
"revisionTime": "2016-11-10T00:52:40Z"
|
"revisionTime": "2017-03-16T02:42:32Z",
|
||||||
|
"version": "library-v2-stage-one",
|
||||||
|
"versionExact": "library-v2-stage-one"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "QAxukkv54/iIvLfsUP6IK4R0m/A=",
|
"checksumSHA1": "QAxukkv54/iIvLfsUP6IK4R0m/A=",
|
||||||
|
|
Loading…
Reference in New Issue