Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router: add ConnCount #156

Merged
merged 2 commits into from
Dec 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
xhebox marked this conversation as resolved.
Show resolved Hide resolved
backend := be.Value.(*backendWrapper)
j += backend.connList.Len()
}
return j
}

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