Notification metrics fixes (#26854)
* Ensure your own posts are never ACKed * Don't ACK mobile websocket notifications * Add counter for the unsupported Desktop Apps * Count only push messages when checking for acks * Fix generated * Add tests, fix comment * Fix help string * Check for nil session
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
29fbcdfc2a
Коммит
9cf5a4bccb
@@ -641,7 +641,9 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
c.App.CountNotificationAck(model.NotificationTypePush)
|
||||
if ack.NotificationType == model.PushTypeMessage {
|
||||
c.App.CountNotificationAck(model.NotificationTypePush)
|
||||
}
|
||||
|
||||
err := c.App.SendAckToPushProxy(&ack)
|
||||
if ack.IsIdLoaded {
|
||||
|
||||
@@ -1775,5 +1775,7 @@ func (a *App) CountNotificationReason(
|
||||
a.Metrics().IncrementNotificationErrorCounter(notificationType, notificationReason)
|
||||
case model.NotificationStatusNotSent:
|
||||
a.Metrics().IncrementNotificationNotSentCounter(notificationType, notificationReason)
|
||||
case model.NotificationStatusUnsupported:
|
||||
a.Metrics().IncrementNotificationUnsupportedCounter(notificationType, notificationReason)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +185,10 @@ func (a *App) sendPushNotificationToAllSessions(msg *model.PushNotification, use
|
||||
if a.Metrics() != nil {
|
||||
a.Metrics().IncrementPostSentPush()
|
||||
}
|
||||
|
||||
if msg.Type == model.PushTypeMessage {
|
||||
a.CountNotification(model.NotificationTypePush)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -82,12 +82,11 @@ func usePostedAckHook(message *model.WebSocketEvent, postedUserId string, channe
|
||||
}
|
||||
|
||||
func (h *postedAckBroadcastHook) Process(msg *platform.HookedWebSocketEvent, webConn *platform.WebConn, args map[string]any) error {
|
||||
// Add if we have mentions or followers
|
||||
// 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
|
||||
// Don't ACK mobile app websocket events at this time, we may revisit this when we can add this to mobile app
|
||||
if session := webConn.GetSession(); session != nil {
|
||||
if session.IsMobile() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
postedUserId, err := getTypedArg[string](args, "posted_user_id")
|
||||
@@ -100,6 +99,14 @@ func (h *postedAckBroadcastHook) Process(msg *platform.HookedWebSocketEvent, web
|
||||
return nil
|
||||
}
|
||||
|
||||
// Add if we have mentions or followers
|
||||
// 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
|
||||
}
|
||||
|
||||
channelType, err := getTypedArg[model.ChannelType](args, "channel_type")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Invalid channel_type value passed to postedAckBroadcastHook")
|
||||
|
||||
@@ -90,6 +90,7 @@ func TestPostedAckHook_Process(t *testing.T) {
|
||||
UserId: userID,
|
||||
Platform: &platform.PlatformService{},
|
||||
}
|
||||
webConn.SetSession(&model.Session{})
|
||||
|
||||
t.Run("should ack if user is in the list of users to notify", func(t *testing.T) {
|
||||
msg := platform.MakeHookedWebSocketEvent(model.NewWebSocketEvent(model.WebsocketEventPosted, "", "", "", nil, ""))
|
||||
@@ -138,6 +139,23 @@ func TestPostedAckHook_Process(t *testing.T) {
|
||||
|
||||
assert.True(t, msg.Event().GetData()["should_ack"].(bool))
|
||||
})
|
||||
|
||||
t.Run("should not ack for mobile app", func(t *testing.T) {
|
||||
mobileWebConn := &platform.WebConn{
|
||||
UserId: userID,
|
||||
Platform: &platform.PlatformService{},
|
||||
}
|
||||
mobileWebConn.SetSession(&model.Session{Props: map[string]string{"isMobile": "true"}})
|
||||
msg := platform.MakeHookedWebSocketEvent(model.NewWebSocketEvent(model.WebsocketEventPosted, "", "", "", nil, ""))
|
||||
|
||||
hook.Process(msg, mobileWebConn, map[string]any{
|
||||
"posted_user_id": model.NewId(),
|
||||
"channel_type": model.ChannelTypeDirect,
|
||||
"users": []string{},
|
||||
})
|
||||
|
||||
assert.Nil(t, msg.Event().GetData()["should_ack"])
|
||||
})
|
||||
}
|
||||
|
||||
func TestAddMentionsAndAddFollowersHooks(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user