[FIX] fix bug

This commit is contained in:
zhoujunhao 2018-07-26 23:06:18 +08:00
parent 5476b1698c
commit 83a060ae44
2 changed files with 27 additions and 3 deletions

View File

@ -26,6 +26,7 @@ import (
"github.com/goodrain/rainbond/monitor/utils"
"github.com/prometheus/common/model"
"time"
"github.com/tidwall/gjson"
)
type Builder struct {
@ -35,7 +36,18 @@ type Builder struct {
}
func (b *Builder) UpdateEndpoints(endpoints ...*config.Endpoint) {
newArr := utils.TrimAndSort(endpoints)
// 用v3 API注册返回json格试所以要提前处理一下
newEndpoints := make([]*config.Endpoint, 0, len(endpoints))
for _, end := range endpoints {
newEnd := *end
newEndpoints = append(newEndpoints, &newEnd)
}
for i, end := range endpoints {
newEndpoints[i].URL = gjson.Get(end.URL, "Addr").String()
}
newArr := utils.TrimAndSort(newEndpoints)
if utils.ArrCompare(b.sortedEndpoints, newArr) {
logrus.Debugf("The endpoints is not modify: %s", b.Name())

View File

@ -26,6 +26,7 @@ import (
"github.com/goodrain/rainbond/monitor/utils"
"github.com/prometheus/common/model"
"time"
"github.com/tidwall/gjson"
)
type Worker struct {
@ -35,7 +36,18 @@ type Worker struct {
}
func (w *Worker) UpdateEndpoints(endpoints ...*config.Endpoint) {
newArr := utils.TrimAndSort(endpoints)
// 用v3 API注册返回json格试所以要提前处理一下
newEndpoints := make([]*config.Endpoint, 0, len(endpoints))
for _, end := range endpoints {
newEnd := *end
newEndpoints = append(newEndpoints, &newEnd)
}
for i, end := range endpoints {
newEndpoints[i].URL = gjson.Get(end.URL, "Addr").String()
}
newArr := utils.TrimAndSort(newEndpoints)
if utils.ArrCompare(w.sortedEndpoints, newArr) {
logrus.Debugf("The endpoints is not modify: %s", w.Name())
@ -53,7 +65,7 @@ func (w *Worker) Error(err error) {
}
func (w *Worker) Name() string {
return "builder"
return "worker"
}
func (w *Worker) toScrape() *prometheus.ScrapeConfig {