Skip to content

Commit fc6ad96

Browse files
committed
Feedback from review
1 parent 58719a0 commit fc6ad96

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

src/Identity/Core/src/SignInManagerMetrics.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ internal sealed class SignInManagerMetrics : IDisposable
1414
public const string RememberTwoFactorCounterName = "aspnetcore.identity.sign_in.remember_two_factor";
1515
public const string ForgetTwoFactorCounterName = "aspnetcore.identity.sign_in.forget_two_factor";
1616
public const string CheckPasswordCounterName = "aspnetcore.identity.sign_in.check_password";
17-
public const string SignInUserPrincipalCounterName = "aspnetcore.identity.sign_in.sign_in_principal";
18-
public const string SignOutUserPrincipalCounterName = "aspnetcore.identity.sign_in.sign_out_principal";
17+
public const string SignInUserPrincipalCounterName = "aspnetcore.identity.sign_in.sign_in";
18+
public const string SignOutUserPrincipalCounterName = "aspnetcore.identity.sign_in.sign_out";
1919

2020
private readonly Meter _meter;
2121
private readonly Counter<long> _authenticateCounter;
@@ -29,12 +29,12 @@ public SignInManagerMetrics(IMeterFactory meterFactory)
2929
{
3030
_meter = meterFactory.Create(MeterName);
3131

32-
_authenticateCounter = _meter.CreateCounter<long>(AuthenticateCounterName, "count", "The number of authenticate attempts. The authenticate counter is incremented by sign in methods such as PasswordSignInAsync and TwoFactorSignInAsync.");
33-
_rememberTwoFactorClientCounter = _meter.CreateCounter<long>(RememberTwoFactorCounterName, "count", "The number of two factor clients remembered.");
34-
_forgetTwoFactorCounter = _meter.CreateCounter<long>(ForgetTwoFactorCounterName, "count", "The number of two factor clients forgotten.");
35-
_checkPasswordCounter = _meter.CreateCounter<long>(CheckPasswordCounterName, "count", "The number of check password attempts. Checks that the account is in a state that can log in and that the password is valid using the UserManager.CheckPasswordAsync method.");
36-
_signInUserPrincipalCounter = _meter.CreateCounter<long>(SignInUserPrincipalCounterName, "count", "The number of calls to sign in user principals.");
37-
_signOutUserPrincipalCounter = _meter.CreateCounter<long>(SignOutUserPrincipalCounterName, "count", "The number of calls to sign out user principals.");
32+
_authenticateCounter = _meter.CreateCounter<long>(AuthenticateCounterName, "{count}", "The number of authenticate attempts. The authenticate counter is incremented by sign in methods such as PasswordSignInAsync and TwoFactorSignInAsync.");
33+
_rememberTwoFactorClientCounter = _meter.CreateCounter<long>(RememberTwoFactorCounterName, "{count}", "The number of two factor clients remembered.");
34+
_forgetTwoFactorCounter = _meter.CreateCounter<long>(ForgetTwoFactorCounterName, "{count}", "The number of two factor clients forgotten.");
35+
_checkPasswordCounter = _meter.CreateCounter<long>(CheckPasswordCounterName, "{check}", "The number of check password attempts. Checks that the account is in a state that can log in and that the password is valid using the UserManager.CheckPasswordAsync method.");
36+
_signInUserPrincipalCounter = _meter.CreateCounter<long>(SignInUserPrincipalCounterName, "{sign_in}", "The number of calls to sign in user principals.");
37+
_signOutUserPrincipalCounter = _meter.CreateCounter<long>(SignOutUserPrincipalCounterName, "{sign_out}", "The number of calls to sign out user principals.");
3838
}
3939

4040
internal void CheckPasswordSignIn(string userType, SignInResult? result, Exception? exception = null)

src/Identity/Extensions.Core/src/UserManagerMetrics.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ internal sealed class UserManagerMetrics : IDisposable
3232
public UserManagerMetrics(IMeterFactory meterFactory)
3333
{
3434
_meter = meterFactory.Create(MeterName);
35-
_createCounter = _meter.CreateCounter<long>(CreateCounterName, "count", "The number of users created.");
36-
_updateCounter = _meter.CreateCounter<long>(UpdateCounterName, "count", "The number of user updates.");
37-
_deleteCounter = _meter.CreateCounter<long>(DeleteCounterName, "count", "The number of users deleted.");
38-
_checkPasswordCounter = _meter.CreateCounter<long>(CheckPasswordCounterName, "count", "The number of check password attempts. Only checks whether the password is valid and not whether the user account is in a state that can log in.");
39-
_verifyTokenCounter = _meter.CreateCounter<long>(VerifyTokenCounterName, "count", "The number of token verification attempts.");
40-
_generateTokenCounter = _meter.CreateCounter<long>(GenerateTokenCounterName, "count", "The number of token generation attempts.");
35+
_createCounter = _meter.CreateCounter<long>(CreateCounterName, "{create}", "The number of users created.");
36+
_updateCounter = _meter.CreateCounter<long>(UpdateCounterName, "{update}", "The number of user updates.");
37+
_deleteCounter = _meter.CreateCounter<long>(DeleteCounterName, "{delete}", "The number of users deleted.");
38+
_checkPasswordCounter = _meter.CreateCounter<long>(CheckPasswordCounterName, "{check}", "The number of check password attempts. Only checks whether the password is valid and not whether the user account is in a state that can log in.");
39+
_verifyTokenCounter = _meter.CreateCounter<long>(VerifyTokenCounterName, "{count}", "The number of token verification attempts.");
40+
_generateTokenCounter = _meter.CreateCounter<long>(GenerateTokenCounterName, "{count}", "The number of token generation attempts.");
4141
}
4242

4343
internal void CreateUser(string userType, IdentityResult? result, Exception? exception = null)
@@ -52,7 +52,7 @@ internal void CreateUser(string userType, IdentityResult? result, Exception? exc
5252
{ "aspnetcore.identity.user_type", userType }
5353
};
5454
AddIdentityResultTags(ref tags, result);
55-
AddExceptionTags(ref tags, exception);
55+
AddExceptionTags(ref tags, exception, result: result);
5656

5757
_createCounter.Add(1, tags);
5858
}
@@ -70,7 +70,7 @@ internal void UpdateUser(string userType, IdentityResult? result, UserUpdateType
7070
{ "aspnetcore.identity.user.update_type", GetUpdateType(updateType) },
7171
};
7272
AddIdentityResultTags(ref tags, result);
73-
AddExceptionTags(ref tags, exception);
73+
AddExceptionTags(ref tags, exception, result: result);
7474

7575
_updateCounter.Add(1, tags);
7676
}
@@ -87,7 +87,7 @@ internal void DeleteUser(string userType, IdentityResult? result, Exception? exc
8787
{ "aspnetcore.identity.user_type", userType }
8888
};
8989
AddIdentityResultTags(ref tags, result);
90-
AddExceptionTags(ref tags, exception);
90+
AddExceptionTags(ref tags, exception, result: result);
9191

9292
_deleteCounter.Add(1, tags);
9393
}
@@ -105,7 +105,7 @@ internal void CheckPassword(string userType, bool? userMissing, PasswordVerifica
105105
};
106106
if (userMissing != null || result != null)
107107
{
108-
tags.Add("aspnetcore.identity.user.password_result", GetPasswordResult(result, passwordMissing: null, userMissing));
108+
tags.Add("aspnetcore.identity.password_check_result", GetPasswordResult(result, passwordMissing: null, userMissing));
109109
}
110110
AddExceptionTags(ref tags, exception);
111111

@@ -183,15 +183,16 @@ private static void AddIdentityResultTags(ref TagList tags, IdentityResult? resu
183183
tags.Add("aspnetcore.identity.result", result.Succeeded ? "success" : "failure");
184184
if (!result.Succeeded && result.Errors.FirstOrDefault()?.Code is { Length: > 0 } code)
185185
{
186-
tags.Add("aspnetcore.identity.result_error_code", code);
186+
tags.Add("aspnetcore.identity.error_code", code);
187187
}
188188
}
189189

190-
private static void AddExceptionTags(ref TagList tags, Exception? exception)
190+
private static void AddExceptionTags(ref TagList tags, Exception? exception, IdentityResult? result = null)
191191
{
192-
if (exception != null)
192+
var value = exception?.GetType().FullName ?? result?.Errors.FirstOrDefault()?.Code;
193+
if (value != null)
193194
{
194-
tags.Add("error.type", exception.GetType().FullName!);
195+
tags.Add("error.type", value);
195196
}
196197
}
197198

src/Identity/test/Identity.Test/UserManagerTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public async Task DeleteCallsStore_Failure()
174174
[
175175
KeyValuePair.Create<string, object>("aspnetcore.identity.user_type", "Microsoft.AspNetCore.Identity.Test.PocoUser"),
176176
KeyValuePair.Create<string, object>("aspnetcore.identity.result", "failure"),
177-
KeyValuePair.Create<string, object>("aspnetcore.identity.result_error_code", "ConcurrencyFailure")
177+
KeyValuePair.Create<string, object>("aspnetcore.identity.error_code", "ConcurrencyFailure")
178178
]));
179179
}
180180

@@ -664,7 +664,7 @@ public async Task CheckPasswordWillRehashPasswordWhenNeeded()
664664
Assert.Collection(checkPassword.GetMeasurementSnapshot(),
665665
m => MetricsHelpers.AssertContainsTags(m.Tags,
666666
[
667-
KeyValuePair.Create<string, object>("aspnetcore.identity.user.password_result", "success_rehash_needed")
667+
KeyValuePair.Create<string, object>("aspnetcore.identity.password_check_result", "success_rehash_needed")
668668
]));
669669
}
670670

@@ -871,7 +871,7 @@ public async Task CheckPasswordWithNullUserReturnsFalse()
871871
Assert.Collection(checkPassword.GetMeasurementSnapshot(),
872872
m => MetricsHelpers.AssertContainsTags(m.Tags,
873873
[
874-
KeyValuePair.Create<string, object>("aspnetcore.identity.user.password_result", "user_missing")
874+
KeyValuePair.Create<string, object>("aspnetcore.identity.password_check_result", "user_missing")
875875
]));
876876
}
877877

0 commit comments

Comments
 (0)