Merge pull request #2137 from signalfx/latency-errs

Disregard failed Pings in updateLatency() for cluster nodes
This commit is contained in:
Vladimir Mihailenco 2022-07-03 08:55:48 +03:00 committed by GitHub
commit 9f5aacde23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -204,15 +204,26 @@ func (n *clusterNode) updateLatency() {
const numProbe = 10 const numProbe = 10
var dur uint64 var dur uint64
successes := 0
for i := 0; i < numProbe; i++ { for i := 0; i < numProbe; i++ {
time.Sleep(time.Duration(10+rand.Intn(10)) * time.Millisecond) time.Sleep(time.Duration(10+rand.Intn(10)) * time.Millisecond)
start := time.Now() start := time.Now()
n.Client.Ping(context.TODO()) err := n.Client.Ping(context.TODO()).Err()
if err == nil {
dur += uint64(time.Since(start) / time.Microsecond) dur += uint64(time.Since(start) / time.Microsecond)
successes++
}
} }
latency := float64(dur) / float64(numProbe) var latency float64
if successes == 0 {
// If none of the pings worked, set latency to some arbitrarily high value so this node gets
// least priority.
latency = float64((1 * time.Minute) / time.Microsecond)
} else {
latency = float64(dur) / float64(successes)
}
atomic.StoreUint32(&n.latency, uint32(latency+0.5)) atomic.StoreUint32(&n.latency, uint32(latency+0.5))
} }