Skip to content

Commit

Permalink
router: add ConnCount (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Dec 22, 2022
1 parent 6c986bb commit 8aee2ce
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/manager/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ import (
type Router interface {
Route(RedirectableConn) (string, error)
RedirectConnections() error
ConnCount() int
Close()
}

var _ Router = &ScoreBasedRouter{}

var (
ErrNoInstanceToSelect = errors.New("no instances to route")
)
Expand Down Expand Up @@ -416,6 +419,17 @@ func (router *ScoreBasedRouter) removeBackendIfEmpty(be *list.Element) bool {
return false
}

func (router *ScoreBasedRouter) ConnCount() int {
router.Lock()
defer router.Unlock()
j := 0
for be := router.backends.Front(); be != nil; be = be.Next() {
backend := be.Value.(*backendWrapper)
j += backend.connList.Len()
}
return j
}

// Close implements Router.Close interface.
func (router *ScoreBasedRouter) Close() {
router.Lock()
Expand Down

0 comments on commit 8aee2ce

Please sign in to comment.