address pr feedback

License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
This commit is contained in:
Adrian Lanzafame 2019-06-12 21:30:14 +10:00 committed by Hector Sanjuan
parent e1b40d49c1
commit 5e09da9d63

View File

@ -189,7 +189,6 @@ func (mc *Checker) FailedMetric(metric string, pid peer.ID) bool {
// as to whether a peer has failed or not. The debugging parameter
// enables a more computation heavy path of the function but
// allows for insight into the return phi value.
// This should not be used for anything other than testing.
func (mc *Checker) failed(metric string, pid peer.ID, debugging bool) (float64, []float64, float64, bool) {
latest := mc.metrics.PeerLatest(metric, pid)
if latest == nil {
@ -201,22 +200,27 @@ func (mc *Checker) failed(metric string, pid peer.ID, debugging bool) (float64,
// to be less than that of the TTL value of the metrics
pmtrs := mc.metrics.PeerMetricAll(metric, pid)
var withinTTL bool
switch {
case len(pmtrs) == 1:
if len(pmtrs) == 1 {
// one metric isn't enough to consider a peer failed
// unless it is expired
if pmtrs[0].Expired() {
return 0.0, nil, 0.0, true
}
return 0.0, nil, 0.0, false
case len(pmtrs) >= 2:
}
if len(pmtrs) >= 2 {
currMetricExpiry := time.Unix(0, pmtrs[1].Expire)
prevMetricReceived := time.Unix(0, pmtrs[0].ReceivedAt)
// accrual failure detection should only kick if the
// the ttl has expired
withinTTL = prevMetricReceived.Before(currMetricExpiry)
if withinTTL && !debugging {
return 0.0, nil, 0.0, false
}
if debugging {
fmt.Printf("validTTL: %v\texp: %v,\tra: %v\n", withinTTL, currMetricExpiry, prevMetricReceived)
}
// shortcut the function if not debugging
if withinTTL && !debugging {
return 0.0, nil, 0.0, false
}
}
v := time.Now().UnixNano() - latest.ReceivedAt