Track settings when send fails

This commit is contained in:
Tulir Asokan 2023-09-01 13:49:27 +03:00
parent 328a3eac53
commit e1bce0d74b
3 changed files with 21 additions and 10 deletions

View file

@ -179,6 +179,12 @@ type bridgeStateSIMMeta struct {
RCSEnabled bool `json:"rcs_enabled"`
}
func (user *User) SIMCount() int {
user.simMetadataLock.RLock()
defer user.simMetadataLock.RUnlock()
return len(user.simMetadata)
}
func (user *User) GetSIMsForBridgeState() []bridgeStateSIMMeta {
user.simMetadataLock.RLock()
data := make([]bridgeStateSIMMeta, 0, len(user.simMetadata))

View file

@ -191,7 +191,7 @@ func (portal *Portal) sendDeliveryReceipt(eventID id.EventID) {
}
}
func (portal *Portal) sendMessageMetrics(evt *event.Event, err error, part string, ms *metricSender) {
func (portal *Portal) sendMessageMetrics(user *User, evt *event.Event, err error, part string, ms *metricSender) {
var msgType string
switch evt.Type {
case event.EventMessage:
@ -220,7 +220,12 @@ func (portal *Portal) sendMessageMetrics(evt *event.Event, err error, part strin
Msg("Failed to handle Matrix event")
reason, statusCode, isCertain, sendNotice, _ := errorToStatusReason(err)
checkpointStatus := status.ReasonToCheckpointStatus(reason, statusCode)
portal.bridge.SendMessageCheckpoint(evt, status.MsgStepRemote, err, checkpointStatus, ms.getRetryNum())
checkpointErr := err
// This is very hacky and should be removed once we find what the error statuses mean
if strings.HasPrefix(err.Error(), "response status ") {
checkpointErr = fmt.Errorf("%w (default:%t,rcs:%t,sims:%d)", err, user.Settings.IsDefaultSMSApp, user.Settings.RCSEnabled, user.SIMCount())
}
portal.bridge.SendMessageCheckpoint(evt, status.MsgStepRemote, checkpointErr, checkpointStatus, ms.getRetryNum())
if sendNotice {
ms.setNoticeID(portal.sendErrorMessage(evt, err, msgType, isCertain, ms.getNoticeID()))
}
@ -303,13 +308,13 @@ func (ms *metricSender) setNoticeID(evtID id.EventID) {
}
}
func (ms *metricSender) sendMessageMetrics(evt *event.Event, err error, part string, completed bool) {
func (ms *metricSender) sendMessageMetrics(user *User, evt *event.Event, err error, part string, completed bool) {
ms.lock.Lock()
defer ms.lock.Unlock()
if !completed && ms.completed {
return
}
ms.portal.sendMessageMetrics(evt, err, part, ms)
ms.portal.sendMessageMetrics(user, evt, err, part, ms)
ms.retryNum++
ms.completed = completed
}

View file

@ -1722,7 +1722,7 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
req, err := portal.convertMatrixMessage(ctx, sender, content, txnID)
timings.convert = time.Since(start)
if err != nil {
go ms.sendMessageMetrics(evt, err, "Error converting", true)
go ms.sendMessageMetrics(sender, evt, err, "Error converting", true)
return
}
log.Debug().
@ -1733,11 +1733,11 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
resp, err := sender.Client.SendMessage(req)
timings.send = time.Since(start)
if err != nil {
go ms.sendMessageMetrics(evt, err, "Error sending", true)
go ms.sendMessageMetrics(sender, evt, err, "Error sending", true)
} else if resp.Status != gmproto.SendMessageResponse_SUCCESS {
go ms.sendMessageMetrics(evt, fmt.Errorf("response status %d", resp.Status), "Error sending", true)
go ms.sendMessageMetrics(sender, evt, fmt.Errorf("response status %d", resp.Status), "Error sending", true)
} else {
go ms.sendMessageMetrics(evt, nil, "", true)
go ms.sendMessageMetrics(sender, evt, nil, "", true)
}
}
@ -1778,7 +1778,7 @@ func (portal *Portal) HandleMatrixReadReceipt(brUser bridge.User, eventID id.Eve
func (portal *Portal) HandleMatrixReaction(sender *User, evt *event.Event) {
err := portal.handleMatrixReaction(sender, evt)
go portal.sendMessageMetrics(evt, err, "Error sending", nil)
go portal.sendMessageMetrics(sender, evt, err, "Error sending", nil)
}
func (portal *Portal) handleMatrixReaction(sender *User, evt *event.Event) error {
@ -1850,7 +1850,7 @@ func (portal *Portal) handleMatrixReaction(sender *User, evt *event.Event) error
func (portal *Portal) HandleMatrixRedaction(sender *User, evt *event.Event) {
err := portal.handleMatrixRedaction(sender, evt)
go portal.sendMessageMetrics(evt, err, "Error sending", nil)
go portal.sendMessageMetrics(sender, evt, err, "Error sending", nil)
}
func (portal *Portal) handleMatrixMessageRedaction(ctx context.Context, sender *User, redacts id.EventID) error {