Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add metric to count lazy member sync requests
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Oct 9, 2018
1 parent 9eb1a79 commit bdc27d6
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

from six import iteritems, itervalues

from prometheus_client import Counter

from twisted.internet import defer

from synapse.api.constants import EventTypes, Membership
Expand All @@ -36,6 +38,13 @@

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
Expand Down Expand Up @@ -227,14 +236,19 @@ def wait_for_sync_for_user(self, sync_config, since_token=None, timeout=0,
@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
Expand Down

0 comments on commit bdc27d6

Please sign in to comment.