Skip to content

Commit f8d6536

Browse files
authored
balance, backend: add balance logs for troubleshooting (#1034)
1 parent 248210c commit f8d6536

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

pkg/balance/router/group.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ func (g *Group) onCreateConn(backendInst BackendInst, conn RedirectableConn, suc
284284
if succeed {
285285
connWrapper := &connWrapper{
286286
RedirectableConn: conn,
287+
createTime: time.Now(),
287288
phase: phaseNotRedirected,
288289
}
289290
g.addConn(backend, connWrapper)
@@ -407,6 +408,9 @@ func (g *Group) redirectConn(conn *connWrapper, fromBackend *backendWrapper, toB
407408
zap.String("from", fromBackend.addr),
408409
zap.String("to", toBackend.addr),
409410
}
411+
if !conn.lastRedirect.IsZero() {
412+
fields = append(fields, zap.Duration("since_last_redirect", curTime.Sub(conn.lastRedirect)))
413+
}
410414
fields = append(fields, logFields...)
411415
succeed := conn.Redirect(toBackend)
412416
if succeed {

pkg/balance/router/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,6 @@ type connWrapper struct {
211211
redirectReason string
212212
// Last redirect start time of this connection.
213213
lastRedirect time.Time
214+
createTime time.Time
214215
phase connPhase
215216
}

pkg/proxy/backend/backend_conn_mgr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ func (mgr *BackendConnManager) notifyRedirectResult(ctx context.Context, rs *red
687687
} else {
688688
err := eventReceiver.OnRedirectSucceed(rs.from, rs.to, mgr)
689689
mgr.logger.Debug("redirect connection succeeds", zap.String("from", rs.from),
690-
zap.String("to", rs.to), zap.NamedError("notify_err", err))
690+
zap.String("to", rs.to), zap.Duration("lifetime", time.Since(mgr.createTime)), zap.NamedError("notify_err", err))
691691
}
692692
}
693693

0 commit comments

Comments
 (0)