Skip to content

Commit 8451391

Browse files
committed
Apply feedback
1 parent 4b64ee2 commit 8451391

File tree

4 files changed

+4
-32
lines changed

4 files changed

+4
-32
lines changed

src/Identity/Core/src/SignInManagerMetrics.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public SignInManagerMetrics(IMeterFactory meterFactory)
3131
{
3232
_meter = meterFactory.Create(MeterName);
3333

34-
_authenticateCounter = _meter.CreateCounter<long>(AuthenticateCounterName, "count", "The number of authenticate and sign in attempts.");
34+
_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.");
3535
_rememberTwoFactorClientCounter = _meter.CreateCounter<long>(RememberTwoFactorCounterName, "count", "The number of two factor clients remembered.");
3636
_forgetTwoFactorCounter = _meter.CreateCounter<long>(ForgetTwoFactorCounterName, "count", "The number of two factor clients forgotten.");
3737
_refreshCounter = _meter.CreateCounter<long>(RefreshCounterName, "count", "The number of refresh sign-in attempts.");
38-
_checkPasswordCounter = _meter.CreateCounter<long>(CheckPasswordCounterName, "count", "The number of check password attempts.");
38+
_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.");
3939
_signInUserPrincipalCounter = _meter.CreateCounter<long>(SignInUserPrincipalCounterName, "count", "The number of user principals signed in.");
4040
_signOutUserPrincipalCounter = _meter.CreateCounter<long>(SignOutUserPrincipalCounterName, "count", "The number of user principals signed out.");
4141
}
@@ -61,10 +61,7 @@ internal void AuthenticateSignIn(string userType, string authenticationScheme, S
6161
{ "aspnetcore.identity.sign_in.type", GetSignInType(signInType) },
6262
{ "aspnetcore.identity.sign_in.is_persistent", isPersistent },
6363
};
64-
if (result != null)
65-
{
66-
tags.Add("aspnetcore.identity.sign_in.result", GetSignInResult(result));
67-
}
64+
AddSignInResult(ref tags, result);
6865
AddExceptionTags(ref tags, exception);
6966

7067
_authenticateCounter.Add(1, tags);

src/Identity/Extensions.Core/src/UserManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,11 +936,9 @@ protected virtual async Task<PasswordVerificationResult> VerifyPasswordAsync(IUs
936936
var hash = await store.GetPasswordHashAsync(user, CancellationToken).ConfigureAwait(false);
937937
if (hash == null)
938938
{
939-
_metrics?.VerifyPassword(typeof(TUser).FullName!, passwordMissing: true, result: null);
940939
return PasswordVerificationResult.Failed;
941940
}
942941
var result = PasswordHasher.VerifyHashedPassword(user, hash, password);
943-
_metrics?.VerifyPassword(typeof(TUser).FullName!, passwordMissing: false, result);
944942

945943
return result;
946944
}

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ internal sealed class UserManagerMetrics : IDisposable
1818
public const string UpdateCounterName = "aspnetcore.identity.user.update";
1919
public const string DeleteCounterName = "aspnetcore.identity.user.delete";
2020
public const string CheckPasswordCounterName = "aspnetcore.identity.user.check_password";
21-
public const string VerifyPasswordCounterName = "aspnetcore.identity.user.verify_password";
2221
public const string VerifyTokenCounterName = "aspnetcore.identity.user.verify_token";
2322
public const string GenerateTokenCounterName = "aspnetcore.identity.user.generate_token";
2423

@@ -27,7 +26,6 @@ internal sealed class UserManagerMetrics : IDisposable
2726
private readonly Counter<long> _updateCounter;
2827
private readonly Counter<long> _deleteCounter;
2928
private readonly Counter<long> _checkPasswordCounter;
30-
private readonly Counter<long> _verifyPasswordCounter;
3129
private readonly Counter<long> _verifyTokenCounter;
3230
private readonly Counter<long> _generateTokenCounter;
3331

@@ -37,8 +35,7 @@ public UserManagerMetrics(IMeterFactory meterFactory)
3735
_createCounter = _meter.CreateCounter<long>(CreateCounterName, "count", "The number of users created.");
3836
_updateCounter = _meter.CreateCounter<long>(UpdateCounterName, "count", "The number of user updates.");
3937
_deleteCounter = _meter.CreateCounter<long>(DeleteCounterName, "count", "The number of users deleted.");
40-
_checkPasswordCounter = _meter.CreateCounter<long>(CheckPasswordCounterName, "count", "The number of check password attempts.");
41-
_verifyPasswordCounter = _meter.CreateCounter<long>(VerifyPasswordCounterName, "count", "The number of password verification attempts.");
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.");
4239
_verifyTokenCounter = _meter.CreateCounter<long>(VerifyTokenCounterName, "count", "The number of token verification attempts.");
4340
_generateTokenCounter = _meter.CreateCounter<long>(GenerateTokenCounterName, "count", "The number of token generation attempts.");
4441
}
@@ -115,20 +112,6 @@ internal void CheckPassword(string userType, bool? userMissing, PasswordVerifica
115112
}
116113
}
117114

118-
internal void VerifyPassword(string userType, bool passwordMissing, PasswordVerificationResult? result)
119-
{
120-
if (_verifyPasswordCounter.Enabled)
121-
{
122-
var tags = new TagList
123-
{
124-
{ "aspnetcore.identity.user_type", userType },
125-
{ "aspnetcore.identity.user.password_result", GetPasswordResult(result, passwordMissing, userMissing: null) },
126-
};
127-
128-
_verifyPasswordCounter.Add(1, tags);
129-
}
130-
}
131-
132115
internal void VerifyToken(string userType, bool? result, string purpose, Exception? exception = null)
133116
{
134117
var tags = new TagList

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,6 @@ public async Task CheckPasswordWillRehashPasswordWhenNeeded()
629629
var testMeterFactory = new TestMeterFactory();
630630
using var updateUser = new MetricCollector<long>(testMeterFactory, "Microsoft.AspNetCore.Identity", UserManagerMetrics.UpdateCounterName);
631631
using var checkPassword = new MetricCollector<long>(testMeterFactory, "Microsoft.AspNetCore.Identity", UserManagerMetrics.CheckPasswordCounterName);
632-
using var verifyPassword = new MetricCollector<long>(testMeterFactory, "Microsoft.AspNetCore.Identity", UserManagerMetrics.VerifyPasswordCounterName);
633632

634633
var store = new Mock<IUserPasswordStore<PocoUser>>();
635634
var hasher = new Mock<IPasswordHasher<PocoUser>>();
@@ -667,11 +666,6 @@ public async Task CheckPasswordWillRehashPasswordWhenNeeded()
667666
[
668667
KeyValuePair.Create<string, object>("aspnetcore.identity.user.password_result", "success_rehash_needed")
669668
]));
670-
Assert.Collection(verifyPassword.GetMeasurementSnapshot(),
671-
m => MetricsHelpers.AssertContainsTags(m.Tags,
672-
[
673-
KeyValuePair.Create<string, object>("aspnetcore.identity.user.password_result", "success_rehash_needed")
674-
]));
675669
}
676670

677671
[Fact]

0 commit comments

Comments
 (0)