-
Couldn't load subscription status.
- Fork 840
Add measures and tags with mediator object to the HttpClientLatencyLogEnricher #6783
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
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
af8d47a
new http latency mediator class
rainsxng 438fc0d
use mediator in the log enricher
rainsxng 5710343
fix tests, update docs
rainsxng ec58e85
restore original enricher behavior
rainsxng 0ec86fe
update the mediator logic, wip
rainsxng 932b361
update mediator usage
rainsxng 9c30569
latency mediator interface
rainsxng 6e3af1c
fix build and types
rainsxng 0afc077
fix mocks in tests
rainsxng 8628605
update optional compilation
rainsxng 879cd3e
resolve build errors
rainsxng 518b6dd
fix tetst, remove unusued interface
rainsxng 6291a92
fix build warnings
rainsxng 3efbc8d
fix PR comments
rainsxng 1e0e46b
latency mediator tests
rainsxng a56a570
remove conditional compilation
rainsxng 86f0e0c
fix warnings
rainsxng 9b8147f
fix build warnings
rainsxng 4890581
update latency listener
rainsxng 3eaee69
Merge branch 'main' into dbohdanov/measures-and-tags
rainsxng d9ffbd6
Merge branch 'main' into dbohdanov/measures-and-tags
rainsxng 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
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
39 changes: 39 additions & 0 deletions
39
src/Libraries/Microsoft.Extensions.Http.Diagnostics/Latency/Internal/HttpLatencyMediator.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,39 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #if NET | ||
| using System.Net.Http; | ||
| using Microsoft.Extensions.Diagnostics.Latency; | ||
|
|
||
| namespace Microsoft.Extensions.Http.Latency.Internal; | ||
|
|
||
| /// <summary> | ||
| /// Mediator for HTTP latency operations that coordinates recording HTTP metrics in a latency context. | ||
| /// </summary> | ||
| internal sealed class HttpLatencyMediator | ||
| { | ||
| private readonly MeasureToken _gcPauseTime; | ||
| private readonly TagToken _httpVersionTag; | ||
|
|
||
| public HttpLatencyMediator(ILatencyContextTokenIssuer tokenIssuer) | ||
| { | ||
| _gcPauseTime = tokenIssuer.GetMeasureToken(HttpMeasures.GCPauseTime); | ||
| _httpVersionTag = tokenIssuer.GetTagToken(HttpTags.HttpVersion); | ||
| } | ||
|
|
||
| public void RecordStart(ILatencyContext latencyContext) | ||
| { | ||
| latencyContext.RecordMeasure(_gcPauseTime, (long)System.GC.GetTotalPauseDuration().TotalMilliseconds * -1L); | ||
| } | ||
|
|
||
| public void RecordEnd(ILatencyContext latencyContext, HttpResponseMessage? response = null) | ||
| { | ||
| latencyContext.AddMeasure(_gcPauseTime, (long)System.GC.GetTotalPauseDuration().TotalMilliseconds); | ||
|
|
||
| if (response != null) | ||
| { | ||
| latencyContext.SetTag(_httpVersionTag, response.Version.ToString()); | ||
| } | ||
| } | ||
| } | ||
| #endif |
27 changes: 27 additions & 0 deletions
27
...aries/Microsoft.Extensions.Http.Diagnostics/Latency/Internal/HttpLatencyMediator.netfx.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,27 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| #if !NET | ||
|
|
||
| using System.Net.Http; | ||
| using Microsoft.Extensions.Diagnostics.Latency; | ||
|
|
||
| namespace Microsoft.Extensions.Http.Latency.Internal; | ||
|
|
||
| internal sealed class HttpLatencyMediator | ||
| { | ||
| private readonly TagToken _httpVersionTag; | ||
|
|
||
| public HttpLatencyMediator(ILatencyContextTokenIssuer tokenIssuer) | ||
| { | ||
| _httpVersionTag = tokenIssuer.GetTagToken(HttpTags.HttpVersion); | ||
| } | ||
|
|
||
| public void RecordEnd(ILatencyContext latencyContext, HttpResponseMessage? response = null) | ||
| { | ||
| if (response != null) | ||
| { | ||
| latencyContext?.SetTag(_httpVersionTag, response.Version.ToString()); | ||
| } | ||
| } | ||
| } | ||
| #endif |
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
16 changes: 16 additions & 0 deletions
16
src/Libraries/Microsoft.Extensions.Http.Diagnostics/Latency/Internal/HttpMeasures.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 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.Extensions.Http.Latency.Internal; | ||
|
|
||
| internal static class HttpMeasures | ||
| { | ||
| public const string GCPauseTime = "gcp"; | ||
| public const string ConnectionInitiated = "coni"; | ||
|
|
||
| public static readonly string[] Measures = | ||
| [ | ||
| GCPauseTime, | ||
| ConnectionInitiated | ||
| ]; | ||
| } |
Oops, something went wrong.
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.