diff --git a/changelog.d/18816.misc b/changelog.d/18816.misc new file mode 100644 index 000000000..d06c710bb --- /dev/null +++ b/changelog.d/18816.misc @@ -0,0 +1 @@ +Tag Sliding Sync traces when we `wait_for_events`. diff --git a/synapse/handlers/sliding_sync/__init__.py b/synapse/handlers/sliding_sync/__init__.py index a9573ba0f..071a271ab 100644 --- a/synapse/handlers/sliding_sync/__init__.py +++ b/synapse/handlers/sliding_sync/__init__.py @@ -116,7 +116,7 @@ class SlidingSyncHandler: sync_config: SlidingSyncConfig, from_token: Optional[SlidingSyncStreamToken] = None, timeout_ms: int = 0, - ) -> SlidingSyncResult: + ) -> Tuple[SlidingSyncResult, bool]: """ Get the sync for a client if we have new data for it now. Otherwise wait for new data to arrive on the server. If the timeout expires, then @@ -128,9 +128,16 @@ class SlidingSyncHandler: from_token: The point in the stream to sync from. Token of the end of the previous batch. May be `None` if this is the initial sync request. timeout_ms: The time in milliseconds to wait for new data to arrive. If 0, - we will immediately but there might not be any new data so we just return an - empty response. + we will respond immediately but there might not be any new data so we just + return an empty response. + + Returns: + A tuple containing the `SlidingSyncResult` and whether we waited for new + activity before responding. Knowing whether we waited is useful in traces + to filter out long-running requests where we were just waiting. """ + did_wait = False + # If the user is not part of the mau group, then check that limits have # not been exceeded (if not part of the group by this point, almost certain # auth_blocking will occur) @@ -149,7 +156,7 @@ class SlidingSyncHandler: logger.warning( "Timed out waiting for worker to catch up. Returning empty response" ) - return SlidingSyncResult.empty(from_token) + return SlidingSyncResult.empty(from_token), did_wait # If we've spent significant time waiting to catch up, take it off # the timeout. @@ -185,8 +192,9 @@ class SlidingSyncHandler: current_sync_callback, from_token=from_token.stream_token, ) + did_wait = True - return result + return result, did_wait @trace async def current_sync_for_user( diff --git a/synapse/rest/client/sync.py b/synapse/rest/client/sync.py index c9fb9dc4d..b6789a059 100644 --- a/synapse/rest/client/sync.py +++ b/synapse/rest/client/sync.py @@ -994,12 +994,18 @@ class SlidingSyncRestServlet(RestServlet): extensions=body.extensions, ) - sliding_sync_results = await self.sliding_sync_handler.wait_for_sync_for_user( + ( + sliding_sync_results, + did_wait, + ) = await self.sliding_sync_handler.wait_for_sync_for_user( requester, sync_config, from_token, timeout, ) + # Knowing whether we waited is useful in traces to filter out long-running + # requests where we were just waiting. + set_tag("sliding_sync.did_wait", str(did_wait)) # The client may have disconnected by now; don't bother to serialize the # response if so.