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

[ASP.NET Core] Set http.request.method as per spec #5001

Merged

Conversation

vishweshbankwar
Copy link
Member

@vishweshbankwar vishweshbankwar commented Oct 27, 2023

Towards #4994
Design discussion issue #

Changes

Fixes http.request.method attribute value on activity and metric as per spec. For details, see the linked issue.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

Merging #5001 (6cb1267) into main (b45b8a9) will decrease coverage by 0.19%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5001      +/-   ##
==========================================
- Coverage   83.59%   83.40%   -0.19%     
==========================================
  Files         295      296       +1     
  Lines       12343    12380      +37     
==========================================
+ Hits        10318    10326       +8     
- Misses       2025     2054      +29     
Flag Coverage Δ
unittests 83.40% <100.00%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...tation.AspNetCore/Implementation/HttpInListener.cs 91.79% <100.00%> (+0.12%) ⬆️
...AspNetCore/Implementation/HttpInMetricsListener.cs 87.03% <100.00%> (+0.24%) ⬆️
...ation.AspNetCore/MeterProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...tion.AspNetCore/TracerProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
src/Shared/RequestMethodHelper.cs 100.00% <100.00%> (ø)

... and 6 files with indirect coverage changes

@vishweshbankwar vishweshbankwar marked this pull request as ready for review October 30, 2023 22:27
@vishweshbankwar vishweshbankwar requested a review from a team as a code owner October 30, 2023 22:27
static RequestMethodHelper()
{
#if NET8_0_OR_GREATER
KnownMethods = FrozenDictionary.ToFrozenDictionary(
Copy link
Contributor

@utpilla utpilla Oct 30, 2023

Choose a reason for hiding this comment

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

Nice! We should identify other places in the repo that can use Frozen collections.

Copy link
Contributor

@utpilla utpilla left a comment

Choose a reason for hiding this comment

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

Left a few suggestions. You could work on them in a follow-up PR as well if you'd like.


public static bool TryResolveHttpMethod(string method, out string resolvedMethod)
{
if (KnownMethods.TryGetValue(method, out resolvedMethod))
Copy link
Member

Choose a reason for hiding this comment

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

@vishweshbankwar Would you do a bit of benchmarking here? I think a switch (method) might actually be the fastest thing to do here (even faster than frozen dictionary).

Check out: https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-8/#frozen-collections

If you scroll down from that anchor to the "IsMostPopular" example, the compiler generates really smart logic for a string switch. I'm guessing it will be faster because it is customized for the known values and done inline, plus it also doesn't need the processing at startup FrozenDictionary needs.

Copy link
Contributor

Choose a reason for hiding this comment

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

@CodeBlanch We need a case insensitive search here. I think we would end up doing either ToUpper or ToLower if we want to use a switch case. That could again add to the cost.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense however I still feel like we could solve it in a way that would be faster. Given there are only a handful of values and we know them all upfront. Perf challenge for anyone willing to take it on 😄

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

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

LGTM

I dropped a comment about doing some benchmarking but that can be a follow-up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants