fix: counter type check

This commit is contained in:
710leo 2020-04-30 17:51:45 +08:00
parent 25a1d30877
commit afb80933d0
2 changed files with 9 additions and 13 deletions

View File

@ -85,7 +85,8 @@ func (m *MetricValue) CheckValidity(now int64) (err error) {
if m.CounterType == "" {
m.CounterType = GAUGE
}
if m.CounterType != GAUGE {
if m.CounterType != GAUGE && m.CounterType != COUNTER {
err = fmt.Errorf("wrong counter type")
return
}

View File

@ -110,25 +110,20 @@ func Xclude(request *IndexReq) ([]IndexData, error) {
return nil, errors.New("empty index addr")
}
var (
result IndexResp
succ bool = false
)
var result IndexResp
perm := rand.Perm(len(addrs))
var err error
for i := range perm {
url := fmt.Sprintf("http://%s%s", addrs[perm[i]], Config.IndexPath)
err := httplib.Post(url).JSONBodyQuiet([]IndexReq{*request}).SetTimeout(time.Duration(Config.IndexCallTimeout) * time.Millisecond).ToJSON(&result)
if err != nil {
logger.Warningf("index xclude failed, error:%v, req:%v", err, request)
continue
} else {
succ = true
err = httplib.Post(url).JSONBodyQuiet([]IndexReq{*request}).SetTimeout(time.Duration(Config.IndexCallTimeout) * time.Millisecond).ToJSON(&result)
if err == nil {
break
}
logger.Warningf("index xclude failed, error:%v, req:%+v", err, request)
}
if !succ {
return nil, errors.New("index xclude failed")
if err != nil {
return nil, fmt.Errorf("index xclude failed, error:%v, req:%+v", err, request)
}
if result.Err != "" {