Track settings when send fails
This commit is contained in:
parent
328a3eac53
commit
e1bce0d74b
3 changed files with 21 additions and 10 deletions
|
@ -179,6 +179,12 @@ type bridgeStateSIMMeta struct {
|
||||||
RCSEnabled bool `json:"rcs_enabled"`
|
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 {
|
func (user *User) GetSIMsForBridgeState() []bridgeStateSIMMeta {
|
||||||
user.simMetadataLock.RLock()
|
user.simMetadataLock.RLock()
|
||||||
data := make([]bridgeStateSIMMeta, 0, len(user.simMetadata))
|
data := make([]bridgeStateSIMMeta, 0, len(user.simMetadata))
|
||||||
|
|
|
@ -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
|
var msgType string
|
||||||
switch evt.Type {
|
switch evt.Type {
|
||||||
case event.EventMessage:
|
case event.EventMessage:
|
||||||
|
@ -220,7 +220,12 @@ func (portal *Portal) sendMessageMetrics(evt *event.Event, err error, part strin
|
||||||
Msg("Failed to handle Matrix event")
|
Msg("Failed to handle Matrix event")
|
||||||
reason, statusCode, isCertain, sendNotice, _ := errorToStatusReason(err)
|
reason, statusCode, isCertain, sendNotice, _ := errorToStatusReason(err)
|
||||||
checkpointStatus := status.ReasonToCheckpointStatus(reason, statusCode)
|
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 {
|
if sendNotice {
|
||||||
ms.setNoticeID(portal.sendErrorMessage(evt, err, msgType, isCertain, ms.getNoticeID()))
|
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()
|
ms.lock.Lock()
|
||||||
defer ms.lock.Unlock()
|
defer ms.lock.Unlock()
|
||||||
if !completed && ms.completed {
|
if !completed && ms.completed {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ms.portal.sendMessageMetrics(evt, err, part, ms)
|
ms.portal.sendMessageMetrics(user, evt, err, part, ms)
|
||||||
ms.retryNum++
|
ms.retryNum++
|
||||||
ms.completed = completed
|
ms.completed = completed
|
||||||
}
|
}
|
||||||
|
|
12
portal.go
12
portal.go
|
@ -1722,7 +1722,7 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
|
||||||
req, err := portal.convertMatrixMessage(ctx, sender, content, txnID)
|
req, err := portal.convertMatrixMessage(ctx, sender, content, txnID)
|
||||||
timings.convert = time.Since(start)
|
timings.convert = time.Since(start)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
go ms.sendMessageMetrics(evt, err, "Error converting", true)
|
go ms.sendMessageMetrics(sender, evt, err, "Error converting", true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debug().
|
log.Debug().
|
||||||
|
@ -1733,11 +1733,11 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
|
||||||
resp, err := sender.Client.SendMessage(req)
|
resp, err := sender.Client.SendMessage(req)
|
||||||
timings.send = time.Since(start)
|
timings.send = time.Since(start)
|
||||||
if err != nil {
|
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 {
|
} 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 {
|
} 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) {
|
func (portal *Portal) HandleMatrixReaction(sender *User, evt *event.Event) {
|
||||||
err := portal.handleMatrixReaction(sender, evt)
|
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 {
|
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) {
|
func (portal *Portal) HandleMatrixRedaction(sender *User, evt *event.Event) {
|
||||||
err := portal.handleMatrixRedaction(sender, evt)
|
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 {
|
func (portal *Portal) handleMatrixMessageRedaction(ctx context.Context, sender *User, redacts id.EventID) error {
|
||||||
|
|
Loading…
Reference in a new issue