Skip to content

Commit

Permalink
Merge pull request #699 from zhyass/feature_set
Browse files Browse the repository at this point in the history
*: fix the backendnum statistics error #698
  • Loading branch information
BohuTANG authored Nov 5, 2020
2 parents af586a4 + edd62cc commit 730c623
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/backend/scatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (scatter *Scatter) LoadConfig() error {
log.Error("scatter.parse.json.file[%v].error:%v", file, err)
return err
}
monitor.BackendSet("backend", 0)
for _, backend := range conf.Backends {
if err := scatter.add(backend); err != nil {
log.Error("scatter.add.backend[%+v].error:%v", backend.Name, err)
Expand Down
5 changes: 5 additions & 0 deletions src/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func QueryTotalCounterInc(command string, result string) {
queryTotalCounter.WithLabelValues(command, result).Inc()
}

// BackendSet set backend num.
func BackendSet(btype string, v float64) {
backendNum.WithLabelValues(btype).Set(v)
}

// BackendInc add 1
func BackendInc(btype string) {
backendNum.WithLabelValues(btype).Inc()
Expand Down
18 changes: 7 additions & 11 deletions src/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,21 @@ func TestBackendIncDec(t *testing.T) {
}

backend := "backend"
backup := "backup"

BackendInc(backend)
BackendInc(backup)

v1 := getBackendNum(backend)
v2 := getBackendNum(backup)

assert.EqualValues(t, 1, v1)
assert.EqualValues(t, 1, v2)

BackendDec(backend)
BackendDec(backup)
BackendSet(backend, 2)
v1 = getBackendNum(backend)
assert.EqualValues(t, 2, v1)

BackendDec(backend)
v1 = getBackendNum(backend)
v2 = getBackendNum(backup)
assert.EqualValues(t, 1, v1)

BackendSet(backend, 0)
v1 = getBackendNum(backend)
assert.EqualValues(t, 0, v1)
assert.EqualValues(t, 0, v2)
}

func TestDiskUsageSet(t *testing.T) {
Expand Down

0 comments on commit 730c623

Please sign in to comment.