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

[ASM] Send cookie values as single string to the WAF #6164

Merged
merged 6 commits into from
Oct 22, 2024

Conversation

NachoEchevarria
Copy link
Contributor

@NachoEchevarria NachoEchevarria commented Oct 18, 2024

Summary of changes

This PR sends the request cookies to the WAF as a single string when there is only one cookie value. Previously, we would send the value in a list. This makes the WAF to ignore these cookies when calculating the session fingerprint.

The code for header and cookies collection has been moved to securitycoordinator.cs in order to avoid duplicated code. It also helps to have a consistent behavior between frameworks. For instance, when we had no cookies, we would send an empty dictionary to the WAF in .net framework and we would send nothing for other frameworks.

As a result, the fingerprint generations have changed. A new cookie has been added to some integration tests to make sure that the hash is calculated.

Reason for change

Implementation details

Test coverage

Other details

Copy link
Contributor

github-actions bot commented Oct 18, 2024

Snapshots difference summary

The following differences have been observed in committed snapshots. It is meant to help the reviewer.
The diff is simplistic, so please check some files anyway while we improve it.

18 occurrences of :

+      _dd.appsec.fp.session: ssn--bd9bce81-d0fff5a7-,

20 occurrences of :

-      _dd.appsec.fp.session: ssn----,
+      _dd.appsec.fp.session: ssn--bd9bce81-d0fff5a7-,

6 occurrences of :

-      _dd.appsec.s.req.cookies: [{"cookie-key":[[[8]],{"len":1}]}],
+      _dd.appsec.s.req.cookies: [{"cookie-key":[8]}],

@datadog-ddstaging
Copy link

datadog-ddstaging bot commented Oct 18, 2024

Datadog Report

Branch report: nacho/SendCookiesAsStringWaf
Commit report: 85635e6
Test service: dd-trace-dotnet

✅ 0 Failed, 367978 Passed, 2080 Skipped, 16h 1m 38.12s Total Time
❄️ 2 New Flaky

New Flaky Tests (2)

  • OnSupportedFrameworkInSsi_CallsForwarderWithExpectedTelemetry - Datadog.Trace.ClrProfiler.IntegrationTests.InstrumentationTests - Last Failure

    Expand for error
     Expected File.Exists(_appPath) to be true, but found False.
    
  • OnSupportedFrameworkInSsi_CallsForwarderWithExpectedTelemetry - Datadog.Trace.ClrProfiler.IntegrationTests.InstrumentationTests - Last Failure

    Expand for error
     Expected File.Exists(echoLogFileName) to be true, but found False.
    

@andrewlock
Copy link
Member

andrewlock commented Oct 18, 2024

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing the following branches/commits:

Execution-time benchmarks measure the whole time it takes to execute a program. And are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are shown in red. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6164) - mean (70ms)  : 68, 72
     .   : milestone, 70,
    master - mean (70ms)  : 67, 72
     .   : milestone, 70,

    section CallTarget+Inlining+NGEN
    This PR (6164) - mean (1,116ms)  : 1094, 1137
     .   : milestone, 1116,
    master - mean (1,106ms)  : 1086, 1127
     .   : milestone, 1106,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6164) - mean (109ms)  : 106, 113
     .   : milestone, 109,
    master - mean (109ms)  : 106, 112
     .   : milestone, 109,

    section CallTarget+Inlining+NGEN
    This PR (6164) - mean (766ms)  : 750, 783
     .   : milestone, 766,
    master - mean (772ms)  : 755, 788
     .   : milestone, 772,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6164) - mean (92ms)  : 90, 94
     .   : milestone, 92,
    master - mean (92ms)  : 89, 94
     .   : milestone, 92,

    section CallTarget+Inlining+NGEN
    This PR (6164) - mean (722ms)  : 708, 736
     .   : milestone, 722,
    master - mean (726ms)  : 707, 746
     .   : milestone, 726,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6164) - mean (191ms)  : 187, 194
     .   : milestone, 191,
    master - mean (191ms)  : 188, 194
     .   : milestone, 191,

    section CallTarget+Inlining+NGEN
    This PR (6164) - mean (1,207ms)  : 1181, 1233
     .   : milestone, 1207,
    master - mean (1,202ms)  : 1175, 1230
     .   : milestone, 1202,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6164) - mean (276ms)  : 271, 280
     .   : milestone, 276,
    master - mean (276ms)  : 271, 280
     .   : milestone, 276,

    section CallTarget+Inlining+NGEN
    This PR (6164) - mean (944ms)  : 927, 962
     .   : milestone, 944,
    master - mean (947ms)  : 929, 964
     .   : milestone, 947,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6164) - mean (265ms)  : 261, 269
     .   : milestone, 265,
    master - mean (265ms)  : 261, 268
     .   : milestone, 265,

    section CallTarget+Inlining+NGEN
    This PR (6164) - mean (926ms)  : 906, 947
     .   : milestone, 926,
    master - mean (932ms)  : 910, 953
     .   : milestone, 932,

Loading

@NachoEchevarria NachoEchevarria changed the title Nacho/send cookies as string waf [ASM] Send cookie values as single string to the WAF Oct 18, 2024
@andrewlock
Copy link
Member

andrewlock commented Oct 18, 2024

Benchmarks Report for appsec 🐌

Benchmarks for #6164 compared to master:

  • 1 benchmarks are slower, with geometric mean 1.811
  • 2 benchmarks have more allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.Asm.AppSecBodyBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master AllCycleSimpleBody net6.0 72.6μs 146ns 564ns 0.0721 0 0 6.01 KB
master AllCycleSimpleBody netcoreapp3.1 62.8μs 75.7ns 293ns 0.094 0 0 6.95 KB
master AllCycleSimpleBody net472 49.3μs 69.4ns 269ns 1.31 0 0 8.34 KB
master AllCycleMoreComplexBody net6.0 80μs 55.3ns 192ns 0.12 0 0 9.51 KB
master AllCycleMoreComplexBody netcoreapp3.1 69.7μs 96.2ns 373ns 0.14 0 0 10.37 KB
master AllCycleMoreComplexBody net472 55.8μs 65.2ns 252ns 1.87 0.0276 0 11.85 KB
master ObjectExtractorSimpleBody net6.0 146ns 0.248ns 0.961ns 0.00393 0 0 280 B
master ObjectExtractorSimpleBody netcoreapp3.1 214ns 0.103ns 0.4ns 0.00371 0 0 272 B
master ObjectExtractorSimpleBody net472 163ns 0.305ns 1.18ns 0.0446 0 0 281 B
master ObjectExtractorMoreComplexBody net6.0 3.01μs 1.6ns 6.21ns 0.0527 0 0 3.78 KB
master ObjectExtractorMoreComplexBody netcoreapp3.1 3.9μs 2.15ns 8.06ns 0.0492 0 0 3.69 KB
master ObjectExtractorMoreComplexBody net472 4.39μs 6.43ns 24.9ns 0.603 0.0066 0 3.8 KB
#6164 AllCycleSimpleBody net6.0 72.4μs 51ns 191ns 0.0724 0 0 6 KB
#6164 AllCycleSimpleBody netcoreapp3.1 62.6μs 83.6ns 324ns 0.0934 0 0 6.95 KB
#6164 AllCycleSimpleBody net472 48.6μs 47.8ns 185ns 1.32 0 0 8.33 KB
#6164 AllCycleMoreComplexBody net6.0 78.7μs 79.4ns 297ns 0.119 0 0 9.51 KB
#6164 AllCycleMoreComplexBody netcoreapp3.1 69.9μs 94.8ns 367ns 0.14 0 0 10.37 KB
#6164 AllCycleMoreComplexBody net472 55.9μs 92.1ns 357ns 1.87 0.0279 0 11.85 KB
#6164 ObjectExtractorSimpleBody net6.0 141ns 0.171ns 0.664ns 0.00392 0 0 280 B
#6164 ObjectExtractorSimpleBody netcoreapp3.1 212ns 0.281ns 1.05ns 0.00379 0 0 272 B
#6164 ObjectExtractorSimpleBody net472 167ns 0.156ns 0.564ns 0.0446 0 0 281 B
#6164 ObjectExtractorMoreComplexBody net6.0 3.05μs 2.36ns 8.83ns 0.0535 0 0 3.78 KB
#6164 ObjectExtractorMoreComplexBody netcoreapp3.1 3.87μs 1.97ns 7.36ns 0.0505 0 0 3.69 KB
#6164 ObjectExtractorMoreComplexBody net472 4.42μs 2.89ns 11.2ns 0.602 0.00661 0 3.8 KB
Benchmarks.Trace.Asm.AppSecEncoderBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EncodeArgs net6.0 37.3μs 18.5ns 69.3ns 0.447 0 0 32.4 KB
master EncodeArgs netcoreapp3.1 54.7μs 33.9ns 131ns 0.435 0 0 32.4 KB
master EncodeArgs net472 65.2μs 60.7ns 227ns 5.15 0.0652 0 32.5 KB
master EncodeLegacyArgs net6.0 74.5μs 14.5ns 56.2ns 0 0 0 2.14 KB
master EncodeLegacyArgs netcoreapp3.1 106μs 336ns 1.3μs 0 0 0 2.14 KB
master EncodeLegacyArgs net472 152μs 46.2ns 166ns 0.305 0 0 2.15 KB
#6164 EncodeArgs net6.0 37.5μs 12.5ns 46.7ns 0.45 0 0 32.4 KB
#6164 EncodeArgs netcoreapp3.1 54.7μs 26.5ns 103ns 0.438 0 0 32.4 KB
#6164 EncodeArgs net472 67.2μs 73ns 283ns 5.16 0.067 0 32.5 KB
#6164 EncodeLegacyArgs net6.0 69μs 34.3ns 133ns 0 0 0 2.14 KB
#6164 EncodeLegacyArgs netcoreapp3.1 106μs 64.8ns 242ns 0 0 0 2.14 KB
#6164 EncodeLegacyArgs net472 151μs 105ns 405ns 0.303 0 0 2.15 KB
Benchmarks.Trace.Asm.AppSecWafBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunWafRealisticBenchmark net6.0 187μs 171ns 641ns 0 0 0 2.44 KB
master RunWafRealisticBenchmark netcoreapp3.1 198μs 359ns 1.39μs 0 0 0 2.39 KB
master RunWafRealisticBenchmark net472 210μs 85.1ns 329ns 0.315 0 0 2.46 KB
master RunWafRealisticBenchmarkWithAttack net6.0 124μs 52.9ns 205ns 0 0 0 1.47 KB
master RunWafRealisticBenchmarkWithAttack netcoreapp3.1 130μs 154ns 577ns 0 0 0 1.46 KB
master RunWafRealisticBenchmarkWithAttack net472 140μs 48.2ns 180ns 0.209 0 0 1.49 KB
#6164 RunWafRealisticBenchmark net6.0 187μs 309ns 1.2μs 0 0 0 2.44 KB
#6164 RunWafRealisticBenchmark netcoreapp3.1 196μs 171ns 663ns 0 0 0 2.39 KB
#6164 RunWafRealisticBenchmark net472 209μs 86.4ns 335ns 0.315 0 0 2.46 KB
#6164 RunWafRealisticBenchmarkWithAttack net6.0 122μs 45.7ns 158ns 0 0 0 1.47 KB
#6164 RunWafRealisticBenchmarkWithAttack netcoreapp3.1 131μs 105ns 407ns 0 0 0 1.46 KB
#6164 RunWafRealisticBenchmarkWithAttack net472 139μs 57.2ns 222ns 0.208 0 0 1.49 KB
Benchmarks.Trace.Iast.StringAspectsBenchmark - Slower ⚠️ More allocations ⚠️

Slower ⚠️ in #6164

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑netcoreapp3.1 1.811 330,700.00 598,900.00 bimodal

More allocations ⚠️ in #6164

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑netcoreapp3.1 255.62 KB 314.84 KB 59.22 KB 23.17%
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark‑net472 57.26 KB 59.44 KB 2.18 KB 3.81%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StringConcatBenchmark net6.0 59μs 714ns 7.1μs 0 0 0 43.44 KB
master StringConcatBenchmark netcoreapp3.1 62.4μs 777ns 7.73μs 0 0 0 42.64 KB
master StringConcatBenchmark net472 37.3μs 191ns 856ns 0 0 0 57.26 KB
master StringConcatAspectBenchmark net6.0 308μs 1.7μs 9.78μs 0 0 0 254.14 KB
master StringConcatAspectBenchmark netcoreapp3.1 335μs 1.73μs 13.7μs 0 0 0 255.62 KB
master StringConcatAspectBenchmark net472 299μs 6.78μs 66.1μs 0 0 0 278.53 KB
#6164 StringConcatBenchmark net6.0 60.2μs 706ns 7.02μs 0 0 0 43.44 KB
#6164 StringConcatBenchmark netcoreapp3.1 63.7μs 1.11μs 11μs 0 0 0 42.64 KB
#6164 StringConcatBenchmark net472 36.8μs 67.5ns 243ns 0 0 0 59.44 KB
#6164 StringConcatAspectBenchmark net6.0 306μs 1.68μs 9.48μs 0 0 0 253.39 KB
#6164 StringConcatAspectBenchmark netcoreapp3.1 571μs 7.14μs 71μs 0 0 0 314.84 KB
#6164 StringConcatAspectBenchmark net472 270μs 6μs 57.2μs 0 0 0 278.53 KB

@andrewlock
Copy link
Member

andrewlock commented Oct 18, 2024

Throughput/Crank Report ⚡

Throughput results for AspNetCoreSimpleController comparing the following branches/commits:

Cases where throughput results for the PR are worse than latest master (5% drop or greater), results are shown in red.

Note that these results are based on a single point-in-time result for each branch. For full results, see one of the many, many dashboards!

gantt
    title Throughput Linux x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6164) (11.121M)   : 0, 11120634
    master (11.147M)   : 0, 11146507
    benchmarks/2.9.0 (11.081M)   : 0, 11080577

    section Automatic
    This PR (6164) (7.397M)   : 0, 7396654
    master (7.346M)   : 0, 7346161
    benchmarks/2.9.0 (7.732M)   : 0, 7732233

    section Trace stats
    master (7.696M)   : 0, 7695552

    section Manual
    master (11.000M)   : 0, 11000138

    section Manual + Automatic
    This PR (6164) (6.846M)   : 0, 6846346
    master (6.847M)   : 0, 6847370

    section DD_TRACE_ENABLED=0
    master (10.226M)   : 0, 10225834

Loading
gantt
    title Throughput Linux arm64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6164) (9.593M)   : 0, 9593394
    master (9.607M)   : 0, 9606697
    benchmarks/2.9.0 (9.798M)   : 0, 9798067

    section Automatic
    This PR (6164) (6.412M)   : 0, 6412013
    master (6.391M)   : 0, 6390624

    section Trace stats
    master (6.768M)   : 0, 6767573

    section Manual
    master (9.365M)   : 0, 9364877

    section Manual + Automatic
    This PR (6164) (6.167M)   : 0, 6166936
    master (6.038M)   : 0, 6038189

    section DD_TRACE_ENABLED=0
    master (8.878M)   : 0, 8877751

Loading
gantt
    title Throughput Windows x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6164) (9.866M)   : 0, 9865639
    master (10.185M)   : 0, 10184870
    benchmarks/2.9.0 (10.067M)   : 0, 10067315

    section Automatic
    This PR (6164) (6.486M)   : 0, 6486234
    master (6.539M)   : 0, 6539096
    benchmarks/2.9.0 (7.552M)   : 0, 7552193

    section Trace stats
    master (7.311M)   : 0, 7310576

    section Manual
    master (9.936M)   : 0, 9936096

    section Manual + Automatic
    This PR (6164) (5.984M)   : 0, 5984040
    master (6.250M)   : 0, 6249990

    section DD_TRACE_ENABLED=0
    master (9.355M)   : 0, 9355348

Loading

@andrewlock
Copy link
Member

andrewlock commented Oct 18, 2024

Benchmarks Report for tracer 🐌

Benchmarks for #6164 compared to master:

  • 1 benchmarks are faster, with geometric mean 1.199
  • 1 benchmarks are slower, with geometric mean 1.217
  • 1 benchmarks have fewer allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.ActivityBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartStopWithChild net6.0 7.67μs 43.8ns 350ns 0.0176 0.00704 0 5.43 KB
master StartStopWithChild netcoreapp3.1 9.83μs 50.4ns 242ns 0.0205 0.0103 0 5.61 KB
master StartStopWithChild net472 16.2μs 32.9ns 123ns 1.01 0.3 0.0893 6.06 KB
#6164 StartStopWithChild net6.0 7.93μs 45.3ns 339ns 0.0149 0.00372 0 5.43 KB
#6164 StartStopWithChild netcoreapp3.1 9.86μs 48.6ns 253ns 0.0245 0.00978 0 5.62 KB
#6164 StartStopWithChild net472 16.5μs 59.5ns 223ns 1.02 0.302 0.0924 6.07 KB
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 457μs 186ns 669ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 632μs 308ns 1.19μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 838μs 486ns 1.88μs 0.417 0 0 3.3 KB
#6164 WriteAndFlushEnrichedTraces net6.0 469μs 330ns 1.24μs 0 0 0 2.7 KB
#6164 WriteAndFlushEnrichedTraces netcoreapp3.1 629μs 401ns 1.55μs 0 0 0 2.7 KB
#6164 WriteAndFlushEnrichedTraces net472 832μs 399ns 1.49μs 0.417 0 0 3.3 KB
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendRequest net6.0 204μs 1.41μs 14.1μs 0.221 0 0 18.45 KB
master SendRequest netcoreapp3.1 235μs 1.38μs 13.5μs 0.228 0 0 20.61 KB
master SendRequest net472 0.00213ns 0.000591ns 0.00213ns 0 0 0 0 b
#6164 SendRequest net6.0 203μs 1.55μs 15.5μs 0.196 0 0 18.45 KB
#6164 SendRequest netcoreapp3.1 220μs 1.28μs 11μs 0.225 0 0 20.61 KB
#6164 SendRequest net472 0.000392ns 0.000311ns 0.00121ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #6164

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces‑net6.0 41.85 KB 41.56 KB -291 B -0.70%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 577μs 2.08μs 7.52μs 0.573 0 0 41.85 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 670μs 3.69μs 21.2μs 0.327 0 0 41.63 KB
master WriteAndFlushEnrichedTraces net472 875μs 3.31μs 12.8μs 8.08 2.55 0.425 53.38 KB
#6164 WriteAndFlushEnrichedTraces net6.0 588μs 2.89μs 13.2μs 0.592 0 0 41.56 KB
#6164 WriteAndFlushEnrichedTraces netcoreapp3.1 681μs 3.12μs 13.6μs 0.332 0 0 41.65 KB
#6164 WriteAndFlushEnrichedTraces net472 876μs 4.29μs 17.2μs 8.75 2.5 0.417 53.29 KB
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.31μs 1.14ns 4.41ns 0.0144 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.75μs 1.34ns 5.17ns 0.0132 0 0 1.02 KB
master ExecuteNonQuery net472 2.07μs 1.65ns 6.4ns 0.156 0 0 987 B
#6164 ExecuteNonQuery net6.0 1.28μs 1.07ns 4.01ns 0.0146 0 0 1.02 KB
#6164 ExecuteNonQuery netcoreapp3.1 1.8μs 2.22ns 8.59ns 0.0135 0 0 1.02 KB
#6164 ExecuteNonQuery net472 2.16μs 3.4ns 13.2ns 0.156 0 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Faster 🎉 Same allocations ✔️

Faster 🎉 in #6164

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch‑net6.0 1.199 1,289.36 1,075.58

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.29μs 2.24ns 8.38ns 0.0133 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.48μs 3.7ns 14.3ns 0.0134 0 0 976 B
master CallElasticsearch net472 2.56μs 1.81ns 6.26ns 0.158 0.00128 0 995 B
master CallElasticsearchAsync net6.0 1.28μs 1.18ns 4.56ns 0.0128 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.63μs 0.853ns 3.3ns 0.0139 0 0 1.02 KB
master CallElasticsearchAsync net472 2.57μs 2.21ns 8.28ns 0.167 0 0 1.05 KB
#6164 CallElasticsearch net6.0 1.08μs 0.41ns 1.53ns 0.014 0 0 976 B
#6164 CallElasticsearch netcoreapp3.1 1.49μs 1ns 3.75ns 0.0134 0 0 976 B
#6164 CallElasticsearch net472 2.47μs 3.5ns 13.6ns 0.158 0 0 995 B
#6164 CallElasticsearchAsync net6.0 1.3μs 0.665ns 2.49ns 0.013 0 0 952 B
#6164 CallElasticsearchAsync netcoreapp3.1 1.62μs 0.679ns 2.54ns 0.0137 0 0 1.02 KB
#6164 CallElasticsearchAsync net472 2.66μs 3.24ns 12.5ns 0.167 0 0 1.05 KB
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net6.0 1.29μs 0.992ns 3.84ns 0.0129 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.57μs 2.1ns 7.87ns 0.0126 0 0 952 B
master ExecuteAsync net472 1.72μs 2.29ns 8.55ns 0.145 0 0 915 B
#6164 ExecuteAsync net6.0 1.22μs 0.833ns 3.12ns 0.0135 0 0 952 B
#6164 ExecuteAsync netcoreapp3.1 1.68μs 1.1ns 4.1ns 0.0128 0 0 952 B
#6164 ExecuteAsync net472 1.71μs 1.32ns 5.11ns 0.145 0 0 915 B
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendAsync net6.0 4.19μs 2.13ns 8.23ns 0.0315 0 0 2.22 KB
master SendAsync netcoreapp3.1 5.12μs 2.73ns 10.2ns 0.0357 0 0 2.76 KB
master SendAsync net472 7.72μs 5.05ns 19.6ns 0.499 0 0 3.15 KB
#6164 SendAsync net6.0 4.07μs 5.36ns 20.8ns 0.0304 0 0 2.22 KB
#6164 SendAsync netcoreapp3.1 5.28μs 2.32ns 9ns 0.0368 0 0 2.76 KB
#6164 SendAsync net472 7.92μs 3.08ns 11.9ns 0.499 0 0 3.15 KB
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 1.44μs 1.4ns 5.24ns 0.0231 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.2μs 1.52ns 5.68ns 0.0218 0 0 1.64 KB
master EnrichedLog net472 2.51μs 1.38ns 5.34ns 0.25 0 0 1.57 KB
#6164 EnrichedLog net6.0 1.5μs 1.05ns 3.8ns 0.0232 0 0 1.64 KB
#6164 EnrichedLog netcoreapp3.1 2.33μs 1.37ns 5.12ns 0.0222 0 0 1.64 KB
#6164 EnrichedLog net472 2.62μs 1.3ns 5.02ns 0.249 0 0 1.57 KB
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 116μs 223ns 833ns 0.0578 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 123μs 196ns 761ns 0 0 0 4.28 KB
master EnrichedLog net472 151μs 67.7ns 262ns 0.68 0.227 0 4.46 KB
#6164 EnrichedLog net6.0 116μs 55.9ns 202ns 0 0 0 4.28 KB
#6164 EnrichedLog netcoreapp3.1 122μs 174ns 672ns 0 0 0 4.28 KB
#6164 EnrichedLog net472 152μs 183ns 709ns 0.679 0.226 0 4.46 KB
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 3.08μs 1.85ns 7.15ns 0.031 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.12μs 1.69ns 6.32ns 0.029 0 0 2.2 KB
master EnrichedLog net472 4.93μs 1.36ns 5.27ns 0.319 0 0 2.02 KB
#6164 EnrichedLog net6.0 3.02μs 1.13ns 4.36ns 0.0317 0 0 2.2 KB
#6164 EnrichedLog netcoreapp3.1 4.17μs 2.63ns 10.2ns 0.0293 0 0 2.2 KB
#6164 EnrichedLog net472 4.86μs 5.55ns 21.5ns 0.32 0 0 2.02 KB
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendReceive net6.0 1.36μs 0.578ns 2.16ns 0.0164 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.73μs 0.845ns 3.27ns 0.0155 0 0 1.14 KB
master SendReceive net472 2.14μs 1.11ns 4.16ns 0.183 0.00106 0 1.16 KB
#6164 SendReceive net6.0 1.42μs 1.17ns 4.39ns 0.0163 0 0 1.14 KB
#6164 SendReceive netcoreapp3.1 1.79μs 0.761ns 2.95ns 0.0152 0 0 1.14 KB
#6164 SendReceive net472 2.05μs 0.987ns 3.82ns 0.184 0 0 1.16 KB
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.6μs 1.48ns 5.74ns 0.0221 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.88μs 1.38ns 5.33ns 0.0212 0 0 1.65 KB
master EnrichedLog net472 4.59μs 8.63ns 32.3ns 0.322 0 0 2.04 KB
#6164 EnrichedLog net6.0 2.78μs 1.54ns 5.95ns 0.0222 0 0 1.6 KB
#6164 EnrichedLog netcoreapp3.1 3.92μs 1.74ns 6.26ns 0.0221 0 0 1.65 KB
#6164 EnrichedLog net472 4.43μs 6.2ns 24ns 0.323 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6164

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑net6.0 1.217 473.23 575.84

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 400ns 0.244ns 0.944ns 0.00811 0 0 576 B
master StartFinishSpan netcoreapp3.1 598ns 0.626ns 2.34ns 0.00779 0 0 576 B
master StartFinishSpan net472 705ns 1.12ns 4.34ns 0.0918 0 0 578 B
master StartFinishScope net6.0 473ns 0.362ns 1.4ns 0.00975 0 0 696 B
master StartFinishScope netcoreapp3.1 700ns 0.844ns 3.27ns 0.00952 0 0 696 B
master StartFinishScope net472 912ns 1.29ns 4.98ns 0.104 0 0 658 B
#6164 StartFinishSpan net6.0 415ns 0.387ns 1.5ns 0.00799 0 0 576 B
#6164 StartFinishSpan netcoreapp3.1 623ns 0.237ns 0.918ns 0.00779 0 0 576 B
#6164 StartFinishSpan net472 713ns 0.996ns 3.73ns 0.0917 0 0 578 B
#6164 StartFinishScope net6.0 576ns 0.223ns 0.864ns 0.0098 0 0 696 B
#6164 StartFinishScope netcoreapp3.1 674ns 0.344ns 1.29ns 0.00944 0 0 696 B
#6164 StartFinishScope net472 889ns 0.84ns 3.03ns 0.104 0 0 658 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net6.0 628ns 0.275ns 1.07ns 0.00971 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 990ns 0.951ns 3.68ns 0.00903 0 0 696 B
master RunOnMethodBegin net472 1.21μs 0.739ns 2.86ns 0.104 0 0 658 B
#6164 RunOnMethodBegin net6.0 668ns 0.288ns 1.08ns 0.00979 0 0 696 B
#6164 RunOnMethodBegin netcoreapp3.1 964ns 0.383ns 1.48ns 0.00925 0 0 696 B
#6164 RunOnMethodBegin net472 1.16μs 0.716ns 2.77ns 0.105 0 0 658 B

@NachoEchevarria NachoEchevarria marked this pull request as ready for review October 21, 2024 08:41
@NachoEchevarria NachoEchevarria requested a review from a team as a code owner October 21, 2024 08:41
internal static Dictionary<string, object> ExtractCookiesFromRequest(HttpRequest request)
{
var cookies = RequestDataHelper.GetCookies(request);
var cookiesDic = new Dictionary<string, object>();
Copy link
Contributor

Choose a reason for hiding this comment

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

we could instantiate it inside clause cookies != null to avoid an allocation in some cases and have a Dictionary<string, object>? as return type, especially that I see you check for null when the method is called

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Thanks!

#endif
if (!cookiesDic.TryGetValue(keyForDictionary, out var value))
{
cookiesDic.Add(keyForDictionary, cookie.Value ?? string.Empty);
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it was like this before, but wondering if we really want to send cookies with a null key and/or null value to the waf 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think that we should exclude cookies with null keys or values. I have updated the code.

{
if (value is string stringValue)
{
cookiesDic[keyForDictionary] = new List<string> { stringValue, cookie.Value ?? string.Empty };
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, does it make sense to send an empty value to the list, especially if there are other actual values in the list already?

{
for (var i = 0; i < cookies.Count; i++)
{
#if NETCOREAPP || NETSTANDARD
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we could use both SecurityCoordinator.Core and SecurityCoordinator.Framework to avoid these ifs?

@NachoEchevarria NachoEchevarria merged commit 1d066ee into master Oct 22, 2024
73 of 74 checks passed
@NachoEchevarria NachoEchevarria deleted the nacho/SendCookiesAsStringWaf branch October 22, 2024 16:39
@github-actions github-actions bot added this to the vNext-v3 milestone Oct 22, 2024
@NachoEchevarria
Copy link
Contributor Author

Thanks for your reviews!!!

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

Successfully merging this pull request may close these issues.

4 participants