Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics for sliding sync processing time #17593

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/17593.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add histogram metrics for sliding sync processing time.
15 changes: 15 additions & 0 deletions synapse/handlers/sliding_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import attr
from immutabledict import immutabledict
from prometheus_client import Histogram
from typing_extensions import assert_never

from synapse.api.constants import (
Expand Down Expand Up @@ -104,6 +105,13 @@
logger = logging.getLogger(__name__)


sync_processing_time = Histogram(
"synapse_sliding_sync_processing_time",
"Time taken to generate a sliding sync response, ignoring wait times.",
["initial"],
)


class Sentinel(enum.Enum):
# defining a sentinel in this way allows mypy to correctly handle the
# type of a dictionary lookup and subsequent type narrowing.
Expand Down Expand Up @@ -571,6 +579,8 @@ async def current_sync_for_user(
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.
"""
start_time_s = self.clock.time()

user_id = sync_config.user.to_string()
app_service = self.store.get_app_service_by_user_id(user_id)
if app_service:
Expand Down Expand Up @@ -934,6 +944,11 @@ async def handle_room(room_id: str) -> None:
set_tag(SynapseTags.RESULT_PREFIX + "result", bool(sliding_sync_result))
set_tag(SynapseTags.FUNC_ARG_PREFIX + "sync_config.user", user_id)

end_time_s = self.clock.time()
sync_processing_time.labels(from_token is not None).observe(
end_time_s - start_time_s
)

return sliding_sync_result

@trace
Expand Down
Loading