MM-34878: Add metrics for websocket reconnects (#17522)

* MM-34878: Add metrics for websocket reconnects

Added two new metrics to track successful websocket drain
and dead queue misses.

```release-note
NONE
```

https://mattermost.atlassian.net/browse/MM-34878

* remove TODO line
Этот коммит содержится в:
Agniva De Sarker
2021-04-29 19:42:48 +05:30
коммит произвёл GitHub
родитель fc0dbe0ace
Коммит 21776870d6
3 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@@ -34,6 +34,12 @@ const (
deadQueueSize = 128 // Approximated from /proc/sys/net/core/wmem_default / 2048 (avg msg size)
)
const (
reconnectFound = "success"
reconnectNotFound = "failure"
reconnectLossless = "lossless"
)
type WebConnConfig struct {
WebSocket *websocket.Conn
Session model.Session
@@ -304,11 +310,13 @@ func (wc *WebConn) writePump() {
wc.logSocketErr("websocket.drainDeadQueue", err)
return
}
if m := wc.App.Metrics(); m != nil {
m.IncrementWebsocketReconnectEvent(reconnectFound)
}
} else if wc.hasMsgLoss() {
// If the seq number is not in dead queue, but it was supposed to be,
// then generate a different connection ID,
// and set sequence to 0, and clear dead queue.
// TODO: Add metrics for this. (both true and false cases)
wc.clearDeadQueue()
wc.SetConnectionID(model.NewId())
wc.Sequence = 0
@@ -320,6 +328,13 @@ func (wc *WebConn) writePump() {
wc.logSocketErr("websocket.sendHello", err)
return
}
if m := wc.App.Metrics(); m != nil {
m.IncrementWebsocketReconnectEvent(reconnectNotFound)
}
} else {
if m := wc.App.Metrics(); m != nil {
m.IncrementWebsocketReconnectEvent(reconnectLossless)
}
}
}