Improve websocket logging (#24259)
After reliable websockets were introduced, we would keep pushing to a webConn even after the client has disconnected. This would lead to the websocket.slow/full and eventually the disconnect messages which unnecessarily confuse the admin. We don't log them if the connection is inactive. We use the active field and convert it to an atomic to use more widely. ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2ed0c6495b
Коммит
0e75982f2b
@@ -98,9 +98,7 @@ type WebConn struct {
|
||||
deadQueuePointer int
|
||||
// active indicates whether there is an open websocket connection attached
|
||||
// to this webConn or not.
|
||||
// It is not used as an atomic, because there is no need to.
|
||||
// So do not use this outside the web hub.
|
||||
active bool
|
||||
active atomic.Bool
|
||||
// reuseCount indicates how many times this connection has been reused.
|
||||
// This is used to differentiate between a fresh connection and
|
||||
// a reused connection.
|
||||
@@ -220,7 +218,6 @@ func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, runn
|
||||
UserId: cfg.Session.UserId,
|
||||
T: cfg.TFunc,
|
||||
Locale: cfg.Locale,
|
||||
active: cfg.Active,
|
||||
reuseCount: cfg.ReuseCount,
|
||||
endWritePump: make(chan struct{}),
|
||||
pumpFinished: make(chan struct{}),
|
||||
@@ -228,6 +225,7 @@ func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, runn
|
||||
lastLogTimeSlow: time.Now(),
|
||||
lastLogTimeFull: time.Now(),
|
||||
}
|
||||
wc.active.Store(cfg.Active)
|
||||
|
||||
wc.SetSession(&cfg.Session)
|
||||
wc.SetSessionToken(cfg.Session.Token)
|
||||
@@ -295,7 +293,7 @@ func (wc *WebConn) GetConnectionID() string {
|
||||
// are inactive or not.
|
||||
func areAllInactive(conns []*WebConn) bool {
|
||||
for _, conn := range conns {
|
||||
if conn.active {
|
||||
if conn.active.Load() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -474,7 +472,7 @@ func (wc *WebConn) writePump() {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(wc.send) >= sendFullWarn && time.Since(wc.lastLogTimeFull) > websocketSuppressWarnThreshold {
|
||||
if wc.active.Load() && len(wc.send) >= sendFullWarn && time.Since(wc.lastLogTimeFull) > websocketSuppressWarnThreshold {
|
||||
logData := []mlog.Field{
|
||||
mlog.String("user_id", wc.UserId),
|
||||
mlog.String("conn_id", wc.GetConnectionID()),
|
||||
@@ -727,7 +725,7 @@ func (wc *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
|
||||
case model.WebsocketEventTyping,
|
||||
model.WebsocketEventStatusChange,
|
||||
model.WebsocketEventMultipleChannelsViewed:
|
||||
if time.Since(wc.lastLogTimeSlow) > websocketSuppressWarnThreshold {
|
||||
if wc.active.Load() && time.Since(wc.lastLogTimeSlow) > websocketSuppressWarnThreshold {
|
||||
mlog.Warn(
|
||||
"websocket.slow: dropping message",
|
||||
mlog.String("user_id", wc.UserId),
|
||||
|
||||
Ссылка в новой задаче
Block a user