summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-10-09 14:15:49 +0100
committerErik Johnston <erik@matrix.org>2018-10-09 14:17:52 +0100
commitbdc27d6716d14128e25737865cc36c8adf42aeaa (patch)
tree954f11fa035de5bd1f0b1db6ae9169ffb1205641 /synapse
parentMerge pull request #4008 from matrix-org/erikj/log_looping_exceptions (diff)
downloadsynapse-bdc27d6716d14128e25737865cc36c8adf42aeaa.tar.xz
Add metric to count lazy member sync requests
Diffstat (limited to 'synapse')
-rw-r--r--synapse/handlers/sync.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index 67b8ca28c7..58edf21472 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -20,6 +20,8 @@ import logging
 
 from six import iteritems, itervalues
 
+from prometheus_client import Counter
+
 from twisted.internet import defer
 
 from synapse.api.constants import EventTypes, Membership
@@ -36,6 +38,13 @@ from synapse.visibility import filter_events_for_client
 
 logger = logging.getLogger(__name__)
 
+
+# Counts the number of times we got asked for a lazy loaded sync. Type is one of
+# initial_sync, full_sate_sync or incremental_sync
+lazy_member_sync_counter = Counter(
+    "synapse_handlers_sync_lazy_member_sync", "", ["type"],
+)
+
 # Store the cache that tracks which lazy-loaded members have been sent to a given
 # client for no more than 30 minutes.
 LAZY_LOADED_MEMBERS_CACHE_MAX_AGE = 30 * 60 * 1000
@@ -227,14 +236,19 @@ class SyncHandler(object):
     @defer.inlineCallbacks
     def _wait_for_sync_for_user(self, sync_config, since_token, timeout,
                                 full_state):
+        if since_token is None:
+            sync_type = "initial_sync"
+        elif full_state:
+            sync_type = "full_state_sync"
+        else:
+            sync_type = "incremental_sync"
+
         context = LoggingContext.current_context()
         if context:
-            if since_token is None:
-                context.tag = "initial_sync"
-            elif full_state:
-                context.tag = "full_state_sync"
-            else:
-                context.tag = "incremental_sync"
+            context.tag = sync_type
+
+        if sync_config.filter_collection.lazy_load_members():
+            lazy_member_sync_counter.labels(sync_type).inc()
 
         if timeout == 0 or since_token is None or full_state:
             # we are going to return immediately, so don't bother calling