-
Notifications
You must be signed in to change notification settings - Fork 2.1k
chore: Using IMeterFactory for metrics - ApplicationRequestInstruments #9656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ReubenBond
merged 6 commits into
dotnet:main
from
Meir017:chore/metrics-di-application-request-timeouts
Feb 15, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
026a4f9
chore: Refactors metrics instrumentation to use dependency injection …
Meir017 aba9909
Update src/Orleans.Core/Core/DefaultClientServices.cs
Meir017 94551e8
Fix OrleansInstruments DI fallback
ReubenBond 850c47e
Register IMeterFactory via AddMetrics
ReubenBond c4f90b6
Address PR feedback on metrics DI
ReubenBond 07c899c
Remove manual Orleans.Core API edit
ReubenBond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 24 additions & 17 deletions
41
src/Orleans.Core/Diagnostics/Metrics/ApplicationRequestInstruments.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,41 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.Metrics; | ||
|
|
||
| namespace Orleans.Runtime; | ||
|
|
||
| internal static class ApplicationRequestInstruments | ||
| internal class ApplicationRequestInstruments | ||
| { | ||
| internal static Counter<long> TimedOutRequestsCounter = Instruments.Meter.CreateCounter<long>(InstrumentNames.APP_REQUESTS_TIMED_OUT); | ||
| internal static Counter<long> CanceledRequestsCounter = Instruments.Meter.CreateCounter<long>(InstrumentNames.APP_REQUESTS_CANCELED); | ||
| private readonly Counter<long> _timedOutRequestsCounter; | ||
| private readonly Counter<long> _canceledRequestsCounter; | ||
|
|
||
| private static readonly long[] AppRequestsLatencyHistogramBuckets = new long[] { 1, 2, 4, 6, 8, 10, 50, 100, 200, 400, 800, 1_000, 1_500, 2_000, 5_000, 10_000, 15_000 }; | ||
| private static readonly HistogramAggregator AppRequestsLatencyHistogramAggregator = new(AppRequestsLatencyHistogramBuckets, Array.Empty<KeyValuePair<string, object>>(), value => new ("duration", $"{value}ms")); | ||
| private static readonly ObservableCounter<long> AppRequestsLatencyHistogramBucket = Instruments.Meter.CreateObservableCounter<long>(InstrumentNames.APP_REQUESTS_LATENCY_HISTOGRAM + "-bucket", AppRequestsLatencyHistogramAggregator.CollectBuckets); | ||
| private static readonly ObservableCounter<long> AppRequestsLatencyHistogramCount = Instruments.Meter.CreateObservableCounter<long>(InstrumentNames.APP_REQUESTS_LATENCY_HISTOGRAM + "-count", AppRequestsLatencyHistogramAggregator.CollectCount); | ||
| private static readonly ObservableCounter<long> AppRequestsLatencyHistogramSum = Instruments.Meter.CreateObservableCounter<long>(InstrumentNames.APP_REQUESTS_LATENCY_HISTOGRAM + "-sum", AppRequestsLatencyHistogramAggregator.CollectSum); | ||
| private static readonly long[] AppRequestsLatencyHistogramBuckets = [1, 2, 4, 6, 8, 10, 50, 100, 200, 400, 800, 1_000, 1_500, 2_000, 5_000, 10_000, 15_000]; | ||
| private readonly HistogramAggregator _appRequestsLatencyHistogramAggregator; | ||
| private readonly ObservableCounter<long> _appRequestsLatencyHistogramBucket; | ||
| private readonly ObservableCounter<long> _appRequestsLatencyHistogramCount; | ||
| private readonly ObservableCounter<long> _appRequestsLatencyHistogramSum; | ||
|
|
||
| internal ApplicationRequestInstruments(OrleansInstruments instruments) | ||
| { | ||
| _timedOutRequestsCounter = instruments.Meter.CreateCounter<long>(InstrumentNames.APP_REQUESTS_TIMED_OUT); | ||
| _canceledRequestsCounter = instruments.Meter.CreateCounter<long>(InstrumentNames.APP_REQUESTS_CANCELED); | ||
| _appRequestsLatencyHistogramAggregator = new(AppRequestsLatencyHistogramBuckets, [], value => new("duration", $"{value}ms")); | ||
| _appRequestsLatencyHistogramBucket = instruments.Meter.CreateObservableCounter(InstrumentNames.APP_REQUESTS_LATENCY_HISTOGRAM + "-bucket", _appRequestsLatencyHistogramAggregator.CollectBuckets); | ||
| _appRequestsLatencyHistogramCount = instruments.Meter.CreateObservableCounter(InstrumentNames.APP_REQUESTS_LATENCY_HISTOGRAM + "-count", _appRequestsLatencyHistogramAggregator.CollectCount); | ||
| _appRequestsLatencyHistogramSum = instruments.Meter.CreateObservableCounter(InstrumentNames.APP_REQUESTS_LATENCY_HISTOGRAM + "-sum", _appRequestsLatencyHistogramAggregator.CollectSum); | ||
| } | ||
|
|
||
| internal static void OnAppRequestsEnd(long durationMilliseconds) | ||
| internal void OnAppRequestsEnd(long durationMilliseconds) | ||
| { | ||
| if (AppRequestsLatencyHistogramSum.Enabled) | ||
| AppRequestsLatencyHistogramAggregator.Record(durationMilliseconds); | ||
| if (_appRequestsLatencyHistogramSum.Enabled) | ||
| _appRequestsLatencyHistogramAggregator.Record(durationMilliseconds); | ||
| } | ||
|
|
||
| internal static void OnAppRequestsTimedOut() | ||
| internal void OnAppRequestsTimedOut() | ||
| { | ||
| TimedOutRequestsCounter.Add(1); | ||
| _timedOutRequestsCounter.Add(1); | ||
| } | ||
|
|
||
| internal static void OnAppRequestsCanceled() | ||
| internal void OnAppRequestsCanceled() | ||
| { | ||
| CanceledRequestsCounter.Add(1); | ||
| _canceledRequestsCounter.Add(1); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/Orleans.Core/Diagnostics/Metrics/OrleansInstruments.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using System; | ||
| using System.Diagnostics.Metrics; | ||
|
|
||
| namespace Orleans.Runtime; | ||
|
|
||
| /// <summary> | ||
| /// Provides the <see cref="Meter"/> used by Orleans runtime metrics. | ||
| /// </summary> | ||
| /// <param name="meterFactory">The meter factory used to create the Orleans meter.</param> | ||
| public class OrleansInstruments(IMeterFactory meterFactory) | ||
| { | ||
| /// <summary> | ||
| /// Gets the Orleans runtime meter. | ||
| /// </summary> | ||
| public Meter Meter { get; } = (meterFactory ?? throw new ArgumentNullException(nameof(meterFactory))).Create("Microsoft.Orleans"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.