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

Commit

Permalink
replacing portions
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl committed May 22, 2018
1 parent c60e0d5 commit df9f72d
Show file tree
Hide file tree
Showing 23 changed files with 268 additions and 414 deletions.
2 changes: 1 addition & 1 deletion synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, hs):
self.TOKEN_NOT_FOUND_HTTP_STATUS = 401

self.token_cache = LruCache(CACHE_SIZE_FACTOR * 10000)
register_cache("token_cache", self.token_cache)
register_cache("cache", "token_cache", self.token_cache)

@defer.inlineCallbacks
def check_from_context(self, event, context, do_sig_check=True):
Expand Down
17 changes: 7 additions & 10 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,17 @@
FederationBase,
event_from_pdu_json,
)
import synapse.metrics
from synapse.util import logcontext, unwrapFirstError
from synapse.util.caches.expiringcache import ExpiringCache
from synapse.util.logcontext import make_deferred_yieldable, run_in_background
from synapse.util.logutils import log_function
from synapse.util.retryutils import NotRetryingDestination

logger = logging.getLogger(__name__)

from prometheus_client import Counter

# synapse.federation.federation_client is a silly name
metrics = synapse.metrics.get_metrics_for("synapse.federation.client")
logger = logging.getLogger(__name__)

sent_queries_counter = metrics.register_counter("sent_queries", labels=["type"])
sent_queries_counter = Counter("synapse_federation_client_sent_queries", "", ["type"])


PDU_RETRY_TIME_MS = 1 * 60 * 1000
Expand Down Expand Up @@ -108,7 +105,7 @@ def make_query(self, destination, query_type, args,
a Deferred which will eventually yield a JSON object from the
response
"""
sent_queries_counter.inc(query_type)
sent_queries_counter.labels(query_type).inc()

return self.transport_layer.make_query(
destination, query_type, args, retry_on_dns_fail=retry_on_dns_fail,
Expand All @@ -127,7 +124,7 @@ def query_client_keys(self, destination, content, timeout):
a Deferred which will eventually yield a JSON object from the
response
"""
sent_queries_counter.inc("client_device_keys")
sent_queries_counter.labels("client_device_keys").inc()
return self.transport_layer.query_client_keys(
destination, content, timeout
)
Expand All @@ -137,7 +134,7 @@ def query_user_devices(self, destination, user_id, timeout=30000):
"""Query the device keys for a list of user ids hosted on a remote
server.
"""
sent_queries_counter.inc("user_devices")
sent_queries_counter.labels("user_devices").inc()
return self.transport_layer.query_user_devices(
destination, user_id, timeout
)
Expand All @@ -154,7 +151,7 @@ def claim_client_keys(self, destination, content, timeout):
a Deferred which will eventually yield a JSON object from the
response
"""
sent_queries_counter.inc("client_one_time_keys")
sent_queries_counter.labels("client_one_time_keys").inc()
return self.transport_layer.claim_client_keys(
destination, content, timeout
)
Expand Down
16 changes: 7 additions & 9 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@

from synapse.federation.persistence import TransactionActions
from synapse.federation.units import Edu, Transaction
import synapse.metrics
from synapse.types import get_domain_from_id
from synapse.util import async
from synapse.util.caches.response_cache import ResponseCache
from synapse.util.logutils import log_function

from prometheus_client import Counter

from six import iteritems

# when processing incoming transactions, we try to handle multiple rooms in
Expand All @@ -41,14 +42,11 @@

logger = logging.getLogger(__name__)

# synapse.federation.federation_server is a silly name
metrics = synapse.metrics.get_metrics_for("synapse.federation.server")

received_pdus_counter = metrics.register_counter("received_pdus")
received_pdus_counter = Counter("synapse_federation_server_received_pdus", "")

received_edus_counter = metrics.register_counter("received_edus")
received_edus_counter = Counter("synapse_federation_server_received_edus", "")

received_queries_counter = metrics.register_counter("received_queries", labels=["type"])
received_queries_counter = Counter("synapse_federation_server_received_queries", "", ["type"])


class FederationServer(FederationBase):
Expand Down Expand Up @@ -131,7 +129,7 @@ def _handle_incoming_transaction(self, transaction, request_time):

logger.debug("[%s] Transaction is new", transaction.transaction_id)

received_pdus_counter.inc_by(len(transaction.pdus))
received_pdus_counter.inc(len(transaction.pdus))

pdus_by_room = {}

Expand Down Expand Up @@ -292,7 +290,7 @@ def on_pull_request(self, origin, versions):

@defer.inlineCallbacks
def on_query_request(self, query_type, args):
received_queries_counter.inc(query_type)
received_queries_counter.labels(query_type).inc()
resp = yield self.registry.on_query(query_type, args)
defer.returnValue((200, resp))

Expand Down
8 changes: 2 additions & 6 deletions synapse/federation/send_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from synapse.storage.presence import UserPresenceState
from synapse.util.metrics import Measure
import synapse.metrics
from synapse.metrics import LaterGauge

from blist import sorteddict
from collections import namedtuple
Expand All @@ -45,9 +45,6 @@
logger = logging.getLogger(__name__)


metrics = synapse.metrics.get_metrics_for(__name__)


class FederationRemoteSendQueue(object):
"""A drop in replacement for TransactionQueue"""

Expand Down Expand Up @@ -77,8 +74,7 @@ def __init__(self, hs):
# lambda binds to the queue rather than to the name of the queue which
# changes. ARGH.
def register(name, queue):
metrics.register_callback(
queue_name + "_size",
LaterGauge("synapse_federation_send_queue_%s_size" % (queue_name,), "",
lambda: len(queue),
)

Expand Down
47 changes: 19 additions & 28 deletions synapse/federation/transaction_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,18 @@
from synapse.util.metrics import measure_func
from synapse.handlers.presence import format_user_presence_state, get_interested_remotes
import synapse.metrics
from synapse.metrics import LaterGauge
from synapse.metrics import (
sent_edus_counter, sent_transactions_counter, events_processed_counter)

from prometheus_client import Counter

import logging


logger = logging.getLogger(__name__)

metrics = synapse.metrics.get_metrics_for(__name__)

client_metrics = synapse.metrics.get_metrics_for("synapse.federation.client")
sent_pdus_destination_dist = client_metrics.register_distribution(
"sent_pdu_destinations"
)
sent_edus_counter = client_metrics.register_counter("sent_edus")

sent_transactions_counter = client_metrics.register_counter("sent_transactions")

events_processed_counter = client_metrics.register_counter("events_processed")
sent_pdus_destination_dist = Counter("synapse_federation_client_sent_pdu_destinations", "")


class TransactionQueue(object):
Expand All @@ -69,8 +64,7 @@ def __init__(self, hs):
# done
self.pending_transactions = {}

metrics.register_callback(
"pending_destinations",
LaterGauge("pending_destinations", "", [],
lambda: len(self.pending_transactions),
)

Expand All @@ -94,12 +88,12 @@ def __init__(self, hs):
# Map of destination -> (edu_type, key) -> Edu
self.pending_edus_keyed_by_dest = edus_keyed = {}

metrics.register_callback(
"pending_pdus",
LaterGauge(
"pending_pdus", "", [],
lambda: sum(map(len, pdus.values())),
)
metrics.register_callback(
"pending_edus",
LaterGauge(
"pending_edus", "", [],
lambda: (
sum(map(len, edus.values()))
+ sum(map(len, presence.values()))
Expand Down Expand Up @@ -241,18 +235,15 @@ def handle_room_events(events):
now = self.clock.time_msec()
ts = yield self.store.get_received_ts(events[-1].event_id)

synapse.metrics.event_processing_lag.set(
now - ts, "federation_sender",
)
synapse.metrics.event_processing_last_ts.set(
ts, "federation_sender",
)
synapse.metrics.event_processing_lag.labels(
"federation_sender").set(now - ts)
synapse.metrics.event_processing_last_ts.labels(
"federation_sender").set(ts)

events_processed_counter.inc_by(len(events))
events_processed_counter.inc(len(events))

synapse.metrics.event_processing_positions.set(
next_token, "federation_sender",
)
synapse.metrics.event_processing_positions.labels(
"federation_sender").set(next_token)

finally:
self._is_processing = False
Expand All @@ -275,7 +266,7 @@ def _send_pdu(self, pdu, destinations):
if not destinations:
return

sent_pdus_destination_dist.inc_by(len(destinations))
sent_pdus_destination_dist.inc(len(destinations))

for destination in destinations:
self.pending_pdus_by_dest.setdefault(destination, []).append(
Expand Down
19 changes: 6 additions & 13 deletions synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
from synapse.util.logcontext import (
make_deferred_yieldable, run_in_background,
)
from prometheus_client import Counter

import logging

logger = logging.getLogger(__name__)

metrics = synapse.metrics.get_metrics_for(__name__)

events_processed_counter = metrics.register_counter("events_processed")
events_processed_counter = Counter("synapse_handlers_appservice_events_processed", "")


def log_failure(failure):
Expand Down Expand Up @@ -128,18 +127,12 @@ def handle_room_events(events):
now = self.clock.time_msec()
ts = yield self.store.get_received_ts(events[-1].event_id)

synapse.metrics.event_processing_positions.set(
upper_bound, "appservice_sender",
)
synapse.metrics.event_processing_positions.labels("appservice_sender").set(upper_bound)

events_processed_counter.inc_by(len(events))
events_processed_counter.inc(len(events))

synapse.metrics.event_processing_lag.set(
now - ts, "appservice_sender",
)
synapse.metrics.event_processing_last_ts.set(
ts, "appservice_sender",
)
synapse.metrics.event_processing_lag.labels("appservice_sender").set(now - ts)
synapse.metrics.event_processing_last_ts.labels("appservice_sender").set(ts)
finally:
self.is_processing = False

Expand Down
Loading

0 comments on commit df9f72d

Please sign in to comment.