[MM-57066][MM-57329] Added metrics for all notification stopping points, consolidated categories between metrics and logging (#26799)

* [MM-57066] Add metric counters for notification events

* Some small changes

* Account for Metrics() sometimes being nil

* Fix test (again)

* Fix more tests

* A few changes from testing - added success counter

* Missed a mock

* Lint

* Add feature flag for notification monitoring
Этот коммит содержится в:
Devin Binnie
2024-04-18 10:30:08 -04:00
коммит произвёл GitHub
родитель 0ce5def8e2
Коммит 02e23a3275
26 изменённых файлов: 572 добавлений и 241 удалений

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

@@ -86,6 +86,7 @@ func (h *postedAckBroadcastHook) Process(msg *platform.HookedWebSocketEvent, web
// This works since we currently do have an order for broadcast hooks, but this probably should be reworked going forward
if msg.Get("followers") != nil || msg.Get("mentions") != nil {
msg.Add("should_ack", true)
incrementWebsocketCounter(webConn)
return nil
}
@@ -107,6 +108,7 @@ func (h *postedAckBroadcastHook) Process(msg *platform.HookedWebSocketEvent, web
// Always ACK direct channels
if channelType == model.ChannelTypeDirect {
msg.Add("should_ack", true)
incrementWebsocketCounter(webConn)
return nil
}
@@ -117,11 +119,24 @@ func (h *postedAckBroadcastHook) Process(msg *platform.HookedWebSocketEvent, web
if len(users) > 0 && slices.Contains(users, webConn.UserId) {
msg.Add("should_ack", true)
incrementWebsocketCounter(webConn)
}
return nil
}
func incrementWebsocketCounter(wc *platform.WebConn) {
if wc.Platform.Metrics() == nil {
return
}
if !wc.Platform.Config().FeatureFlags.NotificationMonitoring {
return
}
wc.Platform.Metrics().IncrementNotificationCounter(model.NotificationTypeWebsocket)
}
// getTypedArg returns a correctly typed hook argument with the given key, reinterpreting the type using JSON encoding
// if necessary. This is needed because broadcast hook args are JSON encoded in a multi-server environment, and any
// type information is lost because those types aren't known at decode time.