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

Commit

Permalink
Add metrics for tracking 3PID /requestToken requests. (#8712)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
erikjohnston authored Nov 13, 2020
1 parent 1b15a3d commit 427ede6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/8712.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add metrics the allow the local sysadmin to track 3PID `/requestToken` requests.
10 changes: 10 additions & 0 deletions synapse/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 try count. Note if"
" 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"),
)


class ReactorLastSeenMetric:
def collect(self):
Expand Down
13 changes: 13 additions & 0 deletions synapse/rest/client/v2_alpha/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down
9 changes: 9 additions & 0 deletions synapse/rest/client/v2_alpha/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 427ede6

Please sign in to comment.