From 604cff1a0610396432732592caaa43fc246e588c Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 5 Jun 2018 13:17:55 +0100 Subject: Add metrics to track appservice transactions --- synapse/appservice/api.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'synapse/appservice') diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py index 00efff1464..08fe67e19c 100644 --- a/synapse/appservice/api.py +++ b/synapse/appservice/api.py @@ -24,8 +24,27 @@ from synapse.types import ThirdPartyInstanceID import logging import urllib +from prometheus_client import Counter + logger = logging.getLogger(__name__) +sent_transactions_counter = Counter( + "synapse_appservice_api_sent_transactions", + "Number of /transactions/ requests sent", + ["service"] +) + +failed_transactions_counter = Counter( + "synapse_appservice_api_failed_transactions", + "Number of /transactions/ requests that failed to send", + ["service"] +) + +sent_events_counter = Counter( + "synapse_appservice_api_sent_events", + "Number of events sent to the AS", + ["service"] +) HOUR_IN_MS = 60 * 60 * 1000 @@ -219,12 +238,15 @@ class ApplicationServiceApi(SimpleHttpClient): args={ "access_token": service.hs_token }) + sent_transactions_counter.label(service.id).inc() + sent_events_counter.label(service.id).inc(len(events)) defer.returnValue(True) return except CodeMessageException as e: logger.warning("push_bulk to %s received %s", uri, e.code) except Exception as ex: logger.warning("push_bulk to %s threw exception %s", uri, ex) + failed_transactions_counter.label(service.id).inc() defer.returnValue(False) def _serialize(self, events): -- cgit 1.4.1 From d6e3c2c79baeb752bb1faa68042e0c43f5854c86 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 5 Jun 2018 17:30:45 +0100 Subject: Let's try labels instead of label, that might work --- synapse/appservice/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'synapse/appservice') diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py index 08fe67e19c..47251fb6ad 100644 --- a/synapse/appservice/api.py +++ b/synapse/appservice/api.py @@ -238,15 +238,15 @@ class ApplicationServiceApi(SimpleHttpClient): args={ "access_token": service.hs_token }) - sent_transactions_counter.label(service.id).inc() - sent_events_counter.label(service.id).inc(len(events)) + sent_transactions_counter.labels(service.id).inc() + sent_events_counter.labels(service.id).inc(len(events)) defer.returnValue(True) return except CodeMessageException as e: logger.warning("push_bulk to %s received %s", uri, e.code) except Exception as ex: logger.warning("push_bulk to %s threw exception %s", uri, ex) - failed_transactions_counter.label(service.id).inc() + failed_transactions_counter.labels(service.id).inc() defer.returnValue(False) def _serialize(self, events): -- cgit 1.4.1 From 592c16251614da7e055b3d864a5885c20cfd3cd0 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 6 Jun 2018 10:35:29 +0100 Subject: also redact __str__ of ApplicationService used for logging --- synapse/appservice/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'synapse/appservice') diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 5fdb579723..d1c598622a 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -292,4 +292,8 @@ class ApplicationService(object): return self.rate_limited def __str__(self): - return "ApplicationService: %s" % (self.__dict__,) + # copy dictionary and redact token fields so they don't get logged + dict_copy = self.__dict__.copy() + dict_copy["token"] = "" + dict_copy["hs_token"] = "" + return "ApplicationService: %s" % (dict_copy,) -- cgit 1.4.1