From a588f9061b8349c9a88b9ed3443d3dcd894e8d79 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 6 Jan 2021 16:54:27 +0000 Subject: [PATCH] Log tweaks, typing fixed? --- syncapi/storage/shared/stream_pdu.go | 1 + syncapi/storage/shared/stream_typing.go | 5 ++++- syncapi/sync/request.go | 11 +++++++++++ syncapi/sync/requestpool.go | 13 ++----------- syncapi/types/provider.go | 5 +++-- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/syncapi/storage/shared/stream_pdu.go b/syncapi/storage/shared/stream_pdu.go index 7d58ebbc0..e77ff063b 100644 --- a/syncapi/storage/shared/stream_pdu.go +++ b/syncapi/storage/shared/stream_pdu.go @@ -79,6 +79,7 @@ func (p *PDUStreamProvider) CompleteSync( return to } req.Response.Rooms.Join[roomID] = *jr + req.Rooms[roomID] = gomatrixserverlib.Join } // Add peeked rooms. diff --git a/syncapi/storage/shared/stream_typing.go b/syncapi/storage/shared/stream_typing.go index cae21d151..ba8c59cc2 100644 --- a/syncapi/storage/shared/stream_typing.go +++ b/syncapi/storage/shared/stream_typing.go @@ -16,7 +16,10 @@ func (p *TypingStreamProvider) CompleteSync( ctx context.Context, req *types.SyncRequest, ) types.StreamPosition { - return p.IncrementalSync(ctx, req, 0, p.LatestPosition(ctx)) + // It isn't beneficial to send previous typing notifications + // after a complete sync, so just return the latest position + // and otherwise do nothing. + return p.LatestPosition(ctx) } func (p *TypingStreamProvider) IncrementalSync( diff --git a/syncapi/sync/request.go b/syncapi/sync/request.go index 1c50bb061..dba5fff7f 100644 --- a/syncapi/sync/request.go +++ b/syncapi/sync/request.go @@ -25,6 +25,7 @@ import ( userapi "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" + "github.com/sirupsen/logrus" ) const defaultSyncTimeout = time.Duration(0) @@ -74,10 +75,20 @@ func newSyncRequest(req *http.Request, device userapi.Device, syncDB storage.Dat } } } + // TODO: Additional query params: set_presence, filter + logger := util.GetLogger(req.Context()).WithFields(logrus.Fields{ + "user_id": device.UserID, + "device_id": device.ID, + "since": since, + "timeout": timeout, + "limit": timelineLimit, + }) + return &types.SyncRequest{ Context: req.Context(), // + Log: logger, // Device: &device, // Response: types.NewResponse(), // Populated by all streams Filter: gomatrixserverlib.DefaultEventFilter(), // diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 61aa4868c..17386440c 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -35,7 +35,6 @@ import ( userapi "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/util" "github.com/prometheus/client_golang/prometheus" - log "github.com/sirupsen/logrus" ) // RequestPool manages HTTP long-poll connections for /sync @@ -156,14 +155,6 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi. } } - logger := util.GetLogger(req.Context()).WithFields(log.Fields{ - "user_id": device.UserID, - "device_id": device.ID, - "since": syncReq.Since, - "timeout": syncReq.Timeout, - "limit": syncReq.Limit, - }) - activeSyncRequests.Inc() defer activeSyncRequests.Dec() @@ -197,10 +188,10 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi. case <-rp.deviceListStream.NotifyAfter(waitctx, syncReq.Since.DeviceListPosition): } - logger.Println("Responding to sync after wakeup") + syncReq.Log.Println("Responding to sync after wakeup") waitcancel() } else { - logger.Println("Responding to sync immediately") + syncReq.Log.Println("Responding to sync immediately") } if syncReq.Since.IsEmpty() { diff --git a/syncapi/types/provider.go b/syncapi/types/provider.go index 44dfb5a8b..018dc16eb 100644 --- a/syncapi/types/provider.go +++ b/syncapi/types/provider.go @@ -6,10 +6,12 @@ import ( userapi "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/gomatrixserverlib" + "github.com/sirupsen/logrus" ) type SyncRequest struct { Context context.Context + Log *logrus.Entry Device *userapi.Device Response *Response Filter gomatrixserverlib.EventFilter @@ -18,8 +20,7 @@ type SyncRequest struct { Timeout time.Duration WantFullState bool - // Below this line are items updated by the - // stream providers. Not thread-safe. + // Updated by the PDU stream. Rooms map[string]string }