Conversation
gfoidl
reviewed
Aug 16, 2023
|
|
||
| ## Test metrics in ASP.NET Core apps | ||
|
|
||
| It's possible to test metrics in ASP.NET Core apps. |
Member
There was a problem hiding this comment.
Suggested change
| It's possible to test metrics in ASP.NET Core apps. | |
| It's possible to test metrics in ASP.NET Core apps with the `MetricCollector<T>`. |
?
The MetricCollector is the heart here for testing, so I'd like to see that type given in a prominent place.
Rick-Anderson
approved these changes
Aug 16, 2023
| The proceeding test: | ||
|
|
||
| * Bootstraps a web app in memory with <xref:Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory%601>. `Program` in the factory's generic argument specifies the web app. | ||
| * Collects metrics values with <xref:Microsoft.Extensions.Telemetry.Testing.Metering.MetricCollector<T>>. |
Contributor
There was a problem hiding this comment.
That's a valid link but is breaking the build for some reason. @tdykstra ?
you could use
[`MetricCollector<T>`](/dotnet/api/microsoft.extensions.telemetry.testing.metering.metriccollector-1.-ctor?view=dotnet-plat-ext-8.0#microsoft-extensions-telemetry-testing-metering-metriccollector-1-ctor(system-diagnostics-metrics-instrument((-0))-system-timeprovider))
Contributor
There was a problem hiding this comment.
It wasn't a valid link -- it needed %601 instead of <T>
tdykstra
reviewed
Aug 17, 2023
12 tasks
noahfalk
reviewed
Aug 18, 2023
| // Assert | ||
| Assert.Equal("Hello World!", await response.Content.ReadAsStringAsync()); | ||
|
|
||
| await collector.WaitForMeasurementsAsync(minCount: 1); |
Member
There was a problem hiding this comment.
If the code under test does not produce the intended metric, is this just going to hang indefinitely until some higher level test timeout occurs?
| * Requires a package reference to `Microsoft.Extensions.Telemetry.Testing`. | ||
| * The `MetricCollector` is created using the web app's `IMeterFactory`. This allows the collector to only report metrics values recorded by test. | ||
| * Includes the meter name, `Microsoft.AspNetCore.Hosting`, and counter name, `http.server.request.duration` to collect. | ||
| * Makes a HTTP request to the app web. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses dotnet/aspnetcore#33387
Internal previews