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)
}
}
}

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

@@ -43,6 +43,7 @@ type MetricsInterface interface {
DecrementWebSocketBroadcastBufferSize(hub string, amount float64)
IncrementWebSocketBroadcastUsersRegistered(hub string, amount float64)
DecrementWebSocketBroadcastUsersRegistered(hub string, amount float64)
IncrementWebsocketReconnectEvent(eventType string)
AddMemCacheHitCounter(cacheName string, amount float64)
AddMemCacheMissCounter(cacheName string, amount float64)

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

@@ -230,6 +230,11 @@ func (_m *MetricsInterface) IncrementWebsocketEvent(eventType string) {
_m.Called(eventType)
}
// IncrementWebsocketReconnectEvent provides a mock function with given fields: eventType
func (_m *MetricsInterface) IncrementWebsocketReconnectEvent(eventType string) {
_m.Called(eventType)
}
// ObserveApiEndpointDuration provides a mock function with given fields: endpoint, method, statusCode, elapsed
func (_m *MetricsInterface) ObserveApiEndpointDuration(endpoint string, method string, statusCode string, elapsed float64) {
_m.Called(endpoint, method, statusCode, elapsed)