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

Fix the auth provider on the logins metric #9573

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/9573.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add prometheus metrics for number of users successfully registering and logging in.
46 changes: 30 additions & 16 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""Contains functions for registering clients."""

import logging
from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Tuple

from prometheus_client import Counter

Expand Down Expand Up @@ -82,6 +82,7 @@ def __init__(self, hs: "HomeServer"):
)
else:
self.device_handler = hs.get_device_handler()
self._register_device_client = self.register_device_inner
self.pusher_pool = hs.get_pusherpool()

self.session_lifetime = hs.config.session_lifetime
Expand Down Expand Up @@ -678,17 +679,35 @@ async def register_device(
Returns:
Tuple of device ID and access token
"""
res = await self._register_device_client(
user_id=user_id,
device_id=device_id,
initial_display_name=initial_display_name,
is_guest=is_guest,
is_appservice_ghost=is_appservice_ghost,
)

if self.hs.config.worker_app:
r = await self._register_device_client(
user_id=user_id,
device_id=device_id,
initial_display_name=initial_display_name,
is_guest=is_guest,
is_appservice_ghost=is_appservice_ghost,
)
return r["device_id"], r["access_token"]
login_counter.labels(
guest=is_guest,
auth_provider=(auth_provider_id or ""),
).inc()

return res["device_id"], res["access_token"]

async def register_device_inner(
self,
user_id: str,
device_id: Optional[str],
initial_display_name: Optional[str],
is_guest: bool = False,
is_appservice_ghost: bool = False,
) -> Dict[str, str]:
"""Helper for register_device

Does the bits that need doing on the main process. Not for use outside this
class and RegisterDeviceReplicationServlet.
"""
assert not self.hs.config.worker_app
valid_until_ms = None
if self.session_lifetime is not None:
if is_guest:
Expand All @@ -713,12 +732,7 @@ async def register_device(
is_appservice_ghost=is_appservice_ghost,
)

login_counter.labels(
guest=is_guest,
auth_provider=(auth_provider_id or ""),
).inc()

return (registered_device_id, access_token)
return {"device_id": registered_device_id, "access_token": access_token}

async def post_registration_actions(
self, user_id: str, auth_result: dict, access_token: Optional[str]
Expand Down
4 changes: 2 additions & 2 deletions synapse/replication/http/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ async def _handle_request(self, request, user_id):
is_guest = content["is_guest"]
is_appservice_ghost = content["is_appservice_ghost"]

device_id, access_token = await self.registration_handler.register_device(
res = await self.registration_handler.register_device_inner(
user_id,
device_id,
initial_display_name,
is_guest,
is_appservice_ghost=is_appservice_ghost,
)

return 200, {"device_id": device_id, "access_token": access_token}
return 200, res


def register_servlets(hs, http_server):
Expand Down