From e541876ad67d4f33bf90c699afaa4b31d88ad3d9 Mon Sep 17 00:00:00 2001 From: Zheng Dayu Date: Wed, 3 Jul 2019 17:51:52 +0800 Subject: [PATCH] fix panic in metrics --- src/redis-shake/metric/metric.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/redis-shake/metric/metric.go b/src/redis-shake/metric/metric.go index a5fbd35..fbb6dc5 100644 --- a/src/redis-shake/metric/metric.go +++ b/src/redis-shake/metric/metric.go @@ -3,6 +3,7 @@ package metric import ( "encoding/json" "fmt" + "math" "strconv" "sync" "sync/atomic" @@ -42,7 +43,7 @@ func (p *Percent) Get(returnString bool) interface{} { if returnString { return "null" } else { - return int64(^uint64(0) >> 1) // int64_max + return math.MaxFloat64 } } else { dividend := atomic.LoadUint64(&p.Dividend) @@ -225,7 +226,10 @@ func (m *Metric) GetAvgDelay() interface{} { } func (m *Metric) GetAvgDelayFloat64() float64 { - return float64(m.AvgDelay.Get(false).(int64)) + if avgDelay, ok := m.AvgDelay.Get(false).(float64); ok { + return avgDelay + } + return math.MaxFloat64 } func (m *Metric) AddNetworkFlow(dbSyncerID int, val uint64) {