Skip to content

Commit 6ab5ff8

Browse files
committed
Update
1 parent 677c456 commit 6ab5ff8

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

src/Identity/Core/src/SignInManagerMetrics.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Diagnostics;
55
using System.Diagnostics.Metrics;
6+
using Microsoft.AspNetCore.Http;
67
using Microsoft.Extensions.Internal;
78

89
namespace Microsoft.AspNetCore.Identity;
@@ -30,12 +31,36 @@ public SignInManagerMetrics(IMeterFactory meterFactory)
3031
{
3132
_meter = meterFactory.Create(MeterName);
3233

33-
_authenticateDuration = _meter.CreateHistogram<double>(AuthenticateDurationName, "s", "The duration of authenticate attempts. The authenticate metrics is recorded by sign in methods such as PasswordSignInAsync and TwoFactorSignInAsync.");
34-
_rememberTwoFactorClientCounter = _meter.CreateCounter<long>(RememberedTwoFactorCounterName, "{client}", "The number of two factor clients remembered.");
35-
_forgetTwoFactorCounter = _meter.CreateCounter<long>(ForgottenTwoFactorCounterName, "{client}", "The number of two factor clients forgotten.");
36-
_checkPasswordCounter = _meter.CreateCounter<long>(CheckPasswordAttemptsCounterName, "{attempt}", "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.");
37-
_signInsCounter = _meter.CreateCounter<long>(SignInsCounterName, "{sign_in}", "The number of calls to sign in user principals.");
38-
_signOutsCounter = _meter.CreateCounter<long>(SignOutsCounterName, "{sign_out}", "The number of calls to sign out user principals.");
34+
_authenticateDuration = _meter.CreateHistogram<double>(
35+
AuthenticateDurationName,
36+
unit: "s",
37+
description: "The duration of authenticate attempts. The authenticate metrics is recorded by sign in methods such as PasswordSignInAsync and TwoFactorSignInAsync.",
38+
advice: new() { HistogramBucketBoundaries = MetricsConstants.ShortSecondsBucketBoundaries });
39+
40+
_rememberTwoFactorClientCounter = _meter.CreateCounter<long>(
41+
RememberedTwoFactorCounterName,
42+
unit: "{client}",
43+
description: "The total number of two factor clients remembered.");
44+
45+
_forgetTwoFactorCounter = _meter.CreateCounter<long>(
46+
ForgottenTwoFactorCounterName,
47+
unit: "{client}",
48+
description: "The total number of two factor clients forgotten.");
49+
50+
_checkPasswordCounter = _meter.CreateCounter<long>(
51+
CheckPasswordAttemptsCounterName,
52+
unit: "{attempt}",
53+
description: "The total 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.");
54+
55+
_signInsCounter = _meter.CreateCounter<long>(
56+
SignInsCounterName,
57+
unit: "{sign_in}",
58+
description: "The total number of calls to sign in user principals.");
59+
60+
_signOutsCounter = _meter.CreateCounter<long>(
61+
SignOutsCounterName,
62+
unit: "{sign_out}",
63+
description: "The total number of calls to sign out user principals.");
3964
}
4065

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

src/Identity/Extensions.Core/src/Microsoft.Extensions.Identity.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<Reference Include="Microsoft.Extensions.Logging" />
1616
<Reference Include="Microsoft.Extensions.Options" />
1717

18+
<Compile Include="$(SharedSourceRoot)Metrics\MetricsConstants.cs" LinkBase="Shared" />
1819
<Compile Include="$(SharedSourceRoot)TrimmingAttributes.cs" LinkBase="Shared" />
1920
<Compile Include="$(SharedSourceRoot)ValueStopwatch\ValueStopwatch.cs" LinkBase="Shared" />
2021
<Compile Include="$(SharedSourceRoot)ThrowHelpers\ArgumentNullThrowHelper.cs" LinkBase="Shared" />

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

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics.Metrics;
77
using System.Linq;
88
using System.Threading.Tasks;
9+
using Microsoft.AspNetCore.Http;
910
using Microsoft.Extensions.Internal;
1011
using static Microsoft.AspNetCore.Identity.UserManagerMetrics;
1112

@@ -33,12 +34,39 @@ internal sealed class UserManagerMetrics : IDisposable
3334
public UserManagerMetrics(IMeterFactory meterFactory)
3435
{
3536
_meter = meterFactory.Create(MeterName);
36-
_createDuration = _meter.CreateHistogram<double>(CreateDurationName, "s", "The duration of user creation operations.");
37-
_updateDuration = _meter.CreateHistogram<double>(UpdateDurationName, "s", "The duration of user update operations.");
38-
_deleteDuration = _meter.CreateHistogram<double>(DeleteDurationName, "s", "The duration of user deletion operations.");
39-
_checkPasswordAttemptsCounter = _meter.CreateCounter<long>(CheckPasswordAttemptsCounterName, "{attempt}", "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.");
40-
_verifyTokenAttemptsCounter = _meter.CreateCounter<long>(VerifyTokenAttemptsCounterName, "{attempt}", "The number of token verification attempts.");
41-
_generateTokensCounter = _meter.CreateCounter<long>(GenerateTokensCounterName, "{count}", "The number of token generations.");
37+
38+
_createDuration = _meter.CreateHistogram<double>(
39+
CreateDurationName,
40+
unit: "s",
41+
description: "The duration of user creation operations.",
42+
advice: new() { HistogramBucketBoundaries = MetricsConstants.ShortSecondsBucketBoundaries });
43+
44+
_updateDuration = _meter.CreateHistogram<double>(
45+
UpdateDurationName,
46+
unit: "s",
47+
description: "The duration of user update operations.",
48+
advice: new() { HistogramBucketBoundaries = MetricsConstants.ShortSecondsBucketBoundaries });
49+
50+
_deleteDuration = _meter.CreateHistogram<double>(
51+
DeleteDurationName,
52+
unit: "s",
53+
description: "The duration of user deletion operations.",
54+
advice: new() { HistogramBucketBoundaries = MetricsConstants.ShortSecondsBucketBoundaries });
55+
56+
_checkPasswordAttemptsCounter = _meter.CreateCounter<long>(
57+
CheckPasswordAttemptsCounterName,
58+
unit: "{attempt}",
59+
description: "The total 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.");
60+
61+
_verifyTokenAttemptsCounter = _meter.CreateCounter<long>(
62+
VerifyTokenAttemptsCounterName,
63+
unit: "{attempt}",
64+
description: "The total number of token verification attempts.");
65+
66+
_generateTokensCounter = _meter.CreateCounter<long>(
67+
GenerateTokensCounterName,
68+
unit: "{count}",
69+
description: "The total number of token generations.");
4270
}
4371

4472
internal void CreateUser(string userType, IdentityResult? result, long startTimestamp, Exception? exception = null)

0 commit comments

Comments
 (0)