18
18
import logging
19
19
from typing import TYPE_CHECKING , Iterable , List , Optional , Tuple
20
20
21
+ from prometheus_client import Counter
22
+
21
23
from synapse import types
22
24
from synapse .api .constants import MAX_USERID_LENGTH , EventTypes , JoinRules , LoginType
23
25
from synapse .api .errors import AuthError , Codes , ConsentNotGivenError , SynapseError
41
43
logger = logging .getLogger (__name__ )
42
44
43
45
46
+ registration_counter = Counter (
47
+ "synapse_user_registrations_total" ,
48
+ "Number of new users registered (since restart)" ,
49
+ ["guest" , "shadow_banned" , "auth_provider" ],
50
+ )
51
+
52
+ login_counter = Counter (
53
+ "synapse_user_logins_total" ,
54
+ "Number of user logins (since restart)" ,
55
+ ["guest" , "auth_provider" ],
56
+ )
57
+
58
+
44
59
class RegistrationHandler (BaseHandler ):
45
60
def __init__ (self , hs : "HomeServer" ):
46
61
super ().__init__ (hs )
@@ -156,6 +171,7 @@ async def register_user(
156
171
bind_emails : Iterable [str ] = [],
157
172
by_admin : bool = False ,
158
173
user_agent_ips : Optional [List [Tuple [str , str ]]] = None ,
174
+ auth_provider_id : Optional [str ] = None ,
159
175
) -> str :
160
176
"""Registers a new client on the server.
161
177
@@ -181,8 +197,10 @@ async def register_user(
181
197
admin api, otherwise False.
182
198
user_agent_ips: Tuples of IP addresses and user-agents used
183
199
during the registration process.
200
+ auth_provider_id: The SSO IdP the user used, if any (just used for the
201
+ prometheus metrics).
184
202
Returns:
185
- The registere user_id.
203
+ The registered user_id.
186
204
Raises:
187
205
SynapseError if there was a problem registering.
188
206
"""
@@ -280,6 +298,12 @@ async def register_user(
280
298
# if user id is taken, just generate another
281
299
fail_count += 1
282
300
301
+ registration_counter .labels (
302
+ guest = make_guest ,
303
+ shadow_banned = shadow_banned ,
304
+ auth_provider = (auth_provider_id or "" ),
305
+ ).inc ()
306
+
283
307
if not self .hs .config .user_consent_at_registration :
284
308
if not self .hs .config .auto_join_rooms_for_guests and make_guest :
285
309
logger .info (
@@ -638,6 +662,7 @@ async def register_device(
638
662
initial_display_name : Optional [str ],
639
663
is_guest : bool = False ,
640
664
is_appservice_ghost : bool = False ,
665
+ auth_provider_id : Optional [str ] = None ,
641
666
) -> Tuple [str , str ]:
642
667
"""Register a device for a user and generate an access token.
643
668
@@ -648,7 +673,8 @@ async def register_device(
648
673
device_id: The device ID to check, or None to generate a new one.
649
674
initial_display_name: An optional display name for the device.
650
675
is_guest: Whether this is a guest account
651
-
676
+ auth_provider_id: The SSO IdP the user used, if any (just used for the
677
+ prometheus metrics).
652
678
Returns:
653
679
Tuple of device ID and access token
654
680
"""
@@ -687,6 +713,11 @@ async def register_device(
687
713
is_appservice_ghost = is_appservice_ghost ,
688
714
)
689
715
716
+ login_counter .labels (
717
+ guest = is_guest ,
718
+ auth_provider = (auth_provider_id or "" ),
719
+ ).inc ()
720
+
690
721
return (registered_device_id , access_token )
691
722
692
723
async def post_registration_actions (
0 commit comments