Skip to content
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

Adding ProblemDetailsService #42384

Merged
merged 65 commits into from
Jul 14, 2022

Conversation

brunolins16
Copy link
Member

@brunolins16 brunolins16 commented Jun 23, 2022

Close #42212

@davidfowl
Copy link
Member

What does the performance of this look like? I see context objects and state machines that can't be avoided?

@brunolins16
Copy link
Member Author

brunolins16 commented Jul 12, 2022

What does the performance of this look like? I see context objects and state machines that can't be avoided?

I was expecting this question :) ... I ran crank and the results are here:
https://gist.github.com/brunolins16/5cc2286ac500706150ea4a957c9375b2

The benchmark was against a simple app.MapGet("statuscode", () => Results.StatusCode(415)); and, in general, adding the StatusCodePages degraded considerably the bad requests performance (it does not affect success requests), also, adding ProblemDetails, we end up with better memory allocation and almost the same RPS.

Also, having the default writers (when calling AddControllers) did not affect the numbers.

ExceptionHandler middleware performance is better but using ProblemsDetails increase a little bit the memory allocation with almost the same RPS.

I will open an issue to work on improvements of those middleware.

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

If we're always going to return HasStarted from TryWriteAsync, we might as well have it not even return a bool. I think it's fine to assume WriteAsync methods did in fact write something in our IProblemDetailsWriter implementations.

var httpContext = context.HttpContext;
var acceptHeader = httpContext.Request.Headers.Accept.GetList<MediaTypeHeaderValue>();

if (acceptHeader?.Any(h => _jsonMediaType.IsSubsetOf(h) || _problemDetailsJsonMediaType.IsSubsetOf(h)) == true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lambda probably allocates per call, we should hand write .Any

@brunolins16 brunolins16 merged commit ac67d32 into dotnet:main Jul 14, 2022
@ghost ghost added this to the 7.0-rc1 milestone Jul 14, 2022
@brunolins16
Copy link
Member Author

/backport to release/7.0-preview7

@ghost
Copy link

ghost commented Jul 14, 2022

Hi @brunolins16. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@github-actions
Copy link
Contributor

Started backporting to release/7.0-preview7: https://github.com/dotnet/aspnetcore/actions/runs/2668518163

@github-actions
Copy link
Contributor

@brunolins16 backporting to release/7.0-preview7 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: MVC Changes
Applying: ExceptionHandler changes
.git/rebase-apply/patch:126: trailing whitespace.
    /// 
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M	src/Middleware/Diagnostics/src/PublicAPI.Unshipped.txt
Falling back to patching base and 3-way merge...
Auto-merging src/Middleware/Diagnostics/src/PublicAPI.Unshipped.txt
CONFLICT (content): Merge conflict in src/Middleware/Diagnostics/src/PublicAPI.Unshipped.txt
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 ExceptionHandler changes
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

captainsafia pushed a commit that referenced this pull request Jul 19, 2022
* MVC Changes

* ExceptionHandler changes

* Routing changes

* Http.Extensions changes

* Minimal APi draft changes

* HttpResults changes

* New ProblemDetails project

* Using ProblemDetailsOptions in mvc

* ProblemDetails project simplification

* Using metadata

* Using metadata

* Latest version

* Removing changes

* Initial cleanup

* Clean up

* Public api clean up

* Updating public API

* More clean ups

* Adding initial unit tests

* Updating unit tests

* Adding more unit tests

* Cleanup

* Clean up

* clean up

* clean up

* Removing nullable

* Simplifying public api

* API Review feedback

* API review feedback

* Clean up

* Clean up

* clean up

* Reusing Endpoint & EndpointMetadataCollection

* Fix build issues

* Updates based on docs/Trimming.md

* Adding Functional tests

* Fix unittest

* Seal context

* Seal ProblemMetadata

* PR Feeback

* API Review

* Clean  up

* Fixing publicapi  warnings

* Clean up

* PR Feedback

* Fixing build

* Fix unit test

* Fix unit tests

* PR review

* Fixing JsonSerializationContext issues

* Adding statuscode 405

* Update src/Http/Http.Extensions/src/ProblemDetailsDefaultWriter.cs

Co-authored-by: Brennan <brecon@microsoft.com>

* PR review

* Apply suggestions from code review

Co-authored-by: Stephen Halter <halter73@gmail.com>

* Fixing bad merge

* Fix bad merge

* Adding analysis.NextMiddlewareName

* PR review

* Changing to CanWrite/WriteAsync

Co-authored-by: Brennan <brecon@microsoft.com>
Co-authored-by: Stephen Halter <halter73@gmail.com>
dougbu pushed a commit that referenced this pull request Jul 19, 2022
* MVC Changes

* ExceptionHandler changes

* Routing changes

* Http.Extensions changes

* Minimal APi draft changes

* HttpResults changes

* New ProblemDetails project

* Using ProblemDetailsOptions in mvc

* ProblemDetails project simplification

* Using metadata

* Using metadata

* Latest version

* Removing changes

* Initial cleanup

* Clean up

* Public api clean up

* Updating public API

* More clean ups

* Adding initial unit tests

* Updating unit tests

* Adding more unit tests

* Cleanup

* Clean up

* clean up

* clean up

* Removing nullable

* Simplifying public api

* API Review feedback

* API review feedback

* Clean up

* Clean up

* clean up

* Reusing Endpoint & EndpointMetadataCollection

* Fix build issues

* Updates based on docs/Trimming.md

* Adding Functional tests

* Fix unittest

* Seal context

* Seal ProblemMetadata

* PR Feeback

* API Review

* Clean  up

* Fixing publicapi  warnings

* Clean up

* PR Feedback

* Fixing build

* Fix unit test

* Fix unit tests

* PR review

* Fixing JsonSerializationContext issues

* Adding statuscode 405

* Update src/Http/Http.Extensions/src/ProblemDetailsDefaultWriter.cs

Co-authored-by: Brennan <brecon@microsoft.com>

* PR review

* Apply suggestions from code review

Co-authored-by: Stephen Halter <halter73@gmail.com>

* Fixing bad merge

* Fix bad merge

* Adding analysis.NextMiddlewareName

* PR review

* Changing to CanWrite/WriteAsync

Co-authored-by: Brennan <brecon@microsoft.com>
Co-authored-by: Stephen Halter <halter73@gmail.com>

Co-authored-by: Brennan <brecon@microsoft.com>
Co-authored-by: Stephen Halter <halter73@gmail.com>
@brunolins16 brunolins16 deleted the brunolins16/issues/32957 branch August 2, 2022 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
6 participants