From 69830fdfd16aace8893d5f8dc902b0fae9084dbc Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 3 Nov 2020 14:10:28 +0000 Subject: [PATCH 1/4] Add metrics for tracking 3PID /requestToken requests. The main use case is to see how many requests are being made, and how many are second/third/etc attempts. If there are large number of retries then that likely indicates a delivery problem. --- synapse/metrics/__init__.py | 10 ++++++++++ synapse/rest/client/v2_alpha/account.py | 13 +++++++++++++ synapse/rest/client/v2_alpha/register.py | 9 +++++++++ 3 files changed, 32 insertions(+) diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py index b8d2a8e8a9bf..f4576c42c3c0 100644 --- a/synapse/metrics/__init__.py +++ b/synapse/metrics/__init__.py @@ -502,6 +502,16 @@ def collect(self): last_ticked = time.time() +# 3PID send info +threepid_send_requests = Histogram( + "synapse_threepid_send_requests_with_tries", + documentation="Number of requests for a 3pid token by retry count. Note if" + " there is a request with rerty count of 4, then there would have been one" + " each for 1, 2 and 3", + buckets=(1, 2, 3, 4, 5, 10), + labelnames=("type", "reason"), +) + class ReactorLastSeenMetric: def collect(self): diff --git a/synapse/rest/client/v2_alpha/account.py b/synapse/rest/client/v2_alpha/account.py index 51effc4d8e7c..a54e1011f750 100644 --- a/synapse/rest/client/v2_alpha/account.py +++ b/synapse/rest/client/v2_alpha/account.py @@ -38,6 +38,7 @@ parse_json_object_from_request, parse_string, ) +from synapse.metrics import threepid_send_requests from synapse.push.mailer import Mailer from synapse.util.msisdn import phone_number_to_msisdn from synapse.util.stringutils import assert_valid_client_secret, random_string @@ -143,6 +144,10 @@ async def on_POST(self, request): # Wrap the session id in a JSON object ret = {"sid": sid} + threepid_send_requests.labels(type="email", reason="password_reset").observe( + send_attempt + ) + return 200, ret @@ -411,6 +416,10 @@ async def on_POST(self, request): # Wrap the session id in a JSON object ret = {"sid": sid} + threepid_send_requests.labels(type="email", reason="add_threepid").observe( + send_attempt + ) + return 200, ret @@ -481,6 +490,10 @@ async def on_POST(self, request): next_link, ) + threepid_send_requests.labels(type="msisdn", reason="add_threepid").observe( + send_attempt + ) + return 200, ret diff --git a/synapse/rest/client/v2_alpha/register.py b/synapse/rest/client/v2_alpha/register.py index 8f2c8cd991ec..ea6811402650 100644 --- a/synapse/rest/client/v2_alpha/register.py +++ b/synapse/rest/client/v2_alpha/register.py @@ -45,6 +45,7 @@ parse_json_object_from_request, parse_string, ) +from synapse.metrics import threepid_send_requests from synapse.push.mailer import Mailer from synapse.util.msisdn import phone_number_to_msisdn from synapse.util.ratelimitutils import FederationRateLimiter @@ -163,6 +164,10 @@ async def on_POST(self, request): # Wrap the session id in a JSON object ret = {"sid": sid} + threepid_send_requests.labels(type="email", reason="register").observe( + send_attempt + ) + return 200, ret @@ -234,6 +239,10 @@ async def on_POST(self, request): next_link, ) + threepid_send_requests.labels(type="msisdn", reason="register").observe( + send_attempt + ) + return 200, ret From 8193350e0c6a28147a1a979143420149e4470f5a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 3 Nov 2020 14:15:23 +0000 Subject: [PATCH 2/4] Newsfile --- changelog.d/8712.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/8712.misc diff --git a/changelog.d/8712.misc b/changelog.d/8712.misc new file mode 100644 index 000000000000..0218e9524de1 --- /dev/null +++ b/changelog.d/8712.misc @@ -0,0 +1 @@ +Add metrics for tracking 3PID `/requestToken` requests. From 5570f1deae79c4d700d8e084eba4826f0fa8c839 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 13 Nov 2020 10:51:12 +0000 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- changelog.d/8712.misc | 2 +- synapse/metrics/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/changelog.d/8712.misc b/changelog.d/8712.misc index 0218e9524de1..90d63a9a237e 100644 --- a/changelog.d/8712.misc +++ b/changelog.d/8712.misc @@ -1 +1 @@ -Add metrics for tracking 3PID `/requestToken` requests. +Add metrics the allow the local sysadmin to track 3PID `/requestToken` requests. diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py index f4576c42c3c0..7468f1e20cae 100644 --- a/synapse/metrics/__init__.py +++ b/synapse/metrics/__init__.py @@ -505,8 +505,8 @@ def collect(self): # 3PID send info threepid_send_requests = Histogram( "synapse_threepid_send_requests_with_tries", - documentation="Number of requests for a 3pid token by retry count. Note if" - " there is a request with rerty count of 4, then there would have been one" + documentation="Number of requests for a 3pid token by try count. Note if" + " there is a request with retry count of 4, then there would have been one" " each for 1, 2 and 3", buckets=(1, 2, 3, 4, 5, 10), labelnames=("type", "reason"), From e51176543bc733820f1a08a148a064087129d39f Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 13 Nov 2020 12:03:37 +0000 Subject: [PATCH 4/4] Update synapse/metrics/__init__.py Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- synapse/metrics/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py index 7468f1e20cae..cbf0dbb871e7 100644 --- a/synapse/metrics/__init__.py +++ b/synapse/metrics/__init__.py @@ -506,7 +506,7 @@ def collect(self): threepid_send_requests = Histogram( "synapse_threepid_send_requests_with_tries", documentation="Number of requests for a 3pid token by try count. Note if" - " there is a request with retry count of 4, then there would have been one" + " there is a request with try count of 4, then there would have been one" " each for 1, 2 and 3", buckets=(1, 2, 3, 4, 5, 10), labelnames=("type", "reason"),