More logging tweaks

This commit is contained in:
Neil Alexander 2022-01-31 16:01:54 +00:00
parent 07d0e72a8b
commit 893aa3b141
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 21 additions and 13 deletions

View file

@ -666,7 +666,7 @@ func (t *missingStateReq) createRespStateFromStateIDs(stateIDs gomatrixserverlib
for i := range stateIDs.StateEventIDs { for i := range stateIDs.StateEventIDs {
ev, ok := t.haveEvents[stateIDs.StateEventIDs[i]] ev, ok := t.haveEvents[stateIDs.StateEventIDs[i]]
if !ok { if !ok {
logrus.Warnf("Missing state event in createRespStateFromStateIDs: %s", stateIDs.StateEventIDs[i]) logrus.Tracef("Missing state event in createRespStateFromStateIDs: %s", stateIDs.StateEventIDs[i])
continue continue
} }
respState.StateEvents = append(respState.StateEvents, ev.Unwrap()) respState.StateEvents = append(respState.StateEvents, ev.Unwrap())
@ -674,7 +674,7 @@ func (t *missingStateReq) createRespStateFromStateIDs(stateIDs gomatrixserverlib
for i := range stateIDs.AuthEventIDs { for i := range stateIDs.AuthEventIDs {
ev, ok := t.haveEvents[stateIDs.AuthEventIDs[i]] ev, ok := t.haveEvents[stateIDs.AuthEventIDs[i]]
if !ok { if !ok {
logrus.Warnf("Missing auth event in createRespStateFromStateIDs: %s", stateIDs.AuthEventIDs[i]) logrus.Tracef("Missing auth event in createRespStateFromStateIDs: %s", stateIDs.AuthEventIDs[i])
continue continue
} }
respState.AuthEvents = append(respState.AuthEvents, ev.Unwrap()) respState.AuthEvents = append(respState.AuthEvents, ev.Unwrap())
@ -718,7 +718,7 @@ func (t *missingStateReq) lookupEvent(ctx context.Context, roomVersion gomatrixs
} }
event, err = gomatrixserverlib.NewEventFromUntrustedJSON(txn.PDUs[0], roomVersion) event, err = gomatrixserverlib.NewEventFromUntrustedJSON(txn.PDUs[0], roomVersion)
if err != nil { if err != nil {
util.GetLogger(ctx).WithError(err).WithField("event_id", missingEventID).Warnf("Transaction: Failed to parse event JSON of event") util.GetLogger(ctx).WithError(err).WithField("event_id", missingEventID).Warnf("Failed to parse event JSON of event returned from /event")
continue continue
} }
found = true found = true
@ -729,7 +729,7 @@ func (t *missingStateReq) lookupEvent(ctx context.Context, roomVersion gomatrixs
return nil, fmt.Errorf("wasn't able to find event via %d server(s)", len(t.servers)) return nil, fmt.Errorf("wasn't able to find event via %d server(s)", len(t.servers))
} }
if err := event.VerifyEventSignatures(ctx, t.keys); err != nil { if err := event.VerifyEventSignatures(ctx, t.keys); err != nil {
util.GetLogger(ctx).WithError(err).Warnf("Transaction: Couldn't validate signature of event %q", event.EventID()) util.GetLogger(ctx).WithError(err).Warnf("Couldn't validate signature of event %q from /event", event.EventID())
return nil, verifySigError{event.EventID(), err} return nil, verifySigError{event.EventID(), err}
} }
return t.cacheAndReturn(event.Headered(roomVersion)), nil return t.cacheAndReturn(event.Headered(roomVersion)), nil

View file

@ -51,13 +51,15 @@ func (r *Joiner) PerformJoin(
req *rsAPI.PerformJoinRequest, req *rsAPI.PerformJoinRequest,
res *rsAPI.PerformJoinResponse, res *rsAPI.PerformJoinResponse,
) { ) {
roomID, joinedVia, err := r.performJoin(context.Background(), req) logger := logrus.WithContext(ctx).WithFields(logrus.Fields{
if err != nil {
logrus.WithContext(ctx).WithFields(logrus.Fields{
"room_id": req.RoomIDOrAlias, "room_id": req.RoomIDOrAlias,
"user_id": req.UserID, "user_id": req.UserID,
"servers": req.ServerNames, "servers": req.ServerNames,
}).WithError(err).Error("Failed to join room") })
logger.Info("User requested to room join")
roomID, joinedVia, err := r.performJoin(context.Background(), req)
if err != nil {
logger.WithError(err).Error("Failed to join room")
sentry.CaptureException(err) sentry.CaptureException(err)
perr, ok := err.(*rsAPI.PerformError) perr, ok := err.(*rsAPI.PerformError)
if ok { if ok {
@ -67,7 +69,9 @@ func (r *Joiner) PerformJoin(
Msg: err.Error(), Msg: err.Error(),
} }
} }
return
} }
logger.Info("User joined room successfully")
res.RoomID = roomID res.RoomID = roomID
res.JoinedVia = joinedVia res.JoinedVia = joinedVia
} }

View file

@ -51,13 +51,17 @@ func (r *Leaver) PerformLeave(
if domain != r.Cfg.Matrix.ServerName { if domain != r.Cfg.Matrix.ServerName {
return nil, fmt.Errorf("user %q does not belong to this homeserver", req.UserID) return nil, fmt.Errorf("user %q does not belong to this homeserver", req.UserID)
} }
logger := logrus.WithContext(ctx).WithFields(logrus.Fields{
"room_id": req.RoomID,
"user_id": req.UserID,
})
logger.Info("User requested to leave join")
if strings.HasPrefix(req.RoomID, "!") { if strings.HasPrefix(req.RoomID, "!") {
output, err := r.performLeaveRoomByID(context.Background(), req, res) output, err := r.performLeaveRoomByID(context.Background(), req, res)
if err != nil { if err != nil {
logrus.WithContext(ctx).WithFields(logrus.Fields{ logger.WithError(err).Error("Failed to leave room")
"room_id": req.RoomID, } else {
"user_id": req.UserID, logger.Info("User left room successfully")
}).WithError(err).Error("Failed to leave room")
} }
return output, err return output, err
} }