Add metrics for sliding sync processing time (#17593)

This should let us see how quickly we actually process things in
practice.
This commit is contained in:
Erik Johnston 2024-08-20 12:36:49 +01:00 committed by GitHub
parent 6eb98a4f1c
commit 10428046e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

1
changelog.d/17593.misc Normal file
View File

@ -0,0 +1 @@
Add histogram metrics for sliding sync processing time.

View File

@ -45,6 +45,7 @@ from typing import (
import attr import attr
from immutabledict import immutabledict from immutabledict import immutabledict
from prometheus_client import Histogram
from typing_extensions import assert_never from typing_extensions import assert_never
from synapse.api.constants import ( from synapse.api.constants import (
@ -104,6 +105,13 @@ if TYPE_CHECKING:
logger = logging.getLogger(__name__) 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): class Sentinel(enum.Enum):
# defining a sentinel in this way allows mypy to correctly handle the # defining a sentinel in this way allows mypy to correctly handle the
# type of a dictionary lookup and subsequent type narrowing. # type of a dictionary lookup and subsequent type narrowing.
@ -571,6 +579,8 @@ class SlidingSyncHandler:
from_token: The point in the stream to sync from. Token of the end of the 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. 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() user_id = sync_config.user.to_string()
app_service = self.store.get_app_service_by_user_id(user_id) app_service = self.store.get_app_service_by_user_id(user_id)
if app_service: if app_service:
@ -934,6 +944,11 @@ class SlidingSyncHandler:
set_tag(SynapseTags.RESULT_PREFIX + "result", bool(sliding_sync_result)) set_tag(SynapseTags.RESULT_PREFIX + "result", bool(sliding_sync_result))
set_tag(SynapseTags.FUNC_ARG_PREFIX + "sync_config.user", user_id) 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 return sliding_sync_result
@trace @trace