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

Config refactor - fix struct/class T nullable ref issues, and allow "raw" access to ConfigurationResult #5715

Merged
merged 3 commits into from
Jun 28, 2024

Conversation

andrewlock
Copy link
Member

@andrewlock andrewlock commented Jun 20, 2024

Summary of changes

  • Fixes bugs related to nullable reference types when used with generics
  • Allow retrieving the "raw" ConfigurationResult<> directly from a configuration builder.

Reason for change

The first issue is the method T? GetAs<T>(key) doesn't behave as we (previously) believed. If you call GetAs<int>(somekey) we previously were expecting it to return null, but it doesn't - the best you can do is return default i.e. 0.

There's no technical way around this limitation AFAIK other than having separate methods, or having methods that are guaranteed non-null returning. So in this PR we have both.

Additionally, there are some cases where it's useful to provide access to the "raw" ConfigurationResut<T>. One example is shown in this PR where the security settings want to know both whether the value was set and what the value is, while also providing a default. It will also be useful in subsequent PRs for refactoring the OTel config.

Implementation details

  • Expose additional Get*Result() methods on ConfigurationBuilder, e.g. GetBoolResult() returns a StructConfigurationResultWithKey<bool>, GetStringResult() returns a ClassConfigurationResultWithKey<bool>,
  • You can use this to inspect the result to see if the key was present (for example)
  • You can then call WithDefault(T default) on this to get the correct value (and record the default in telemetry correctly)

Test coverage

Mostly a refactor, should be covered by existing tests

Other details

This is part of a big stack of config refactoring PRs:

@datadog-ddstaging
Copy link

datadog-ddstaging bot commented Jun 20, 2024

Datadog Report

Branch report: andrew/config-refactor/3-extra-abstractions
Commit report: f14db42
Test service: dd-trace-dotnet

✅ 0 Failed, 340030 Passed, 1641 Skipped, 13h 50m 30.22s Total Time
⌛ 1 Performance Regression

⌛ Performance Regressions vs Default Branch (1)

  • CallTarget+Inlining+NGEN - Samples.FakeDbCommand.windows.net462.json.scenarios 1.01s (+21.31ms, +2%) - Details

@andrewlock
Copy link
Member Author

andrewlock commented Jun 20, 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 (5715) - mean (75ms)  : 66, 84
     .   : milestone, 75,
    master - mean (73ms)  : 64, 82
     .   : milestone, 73,

    section CallTarget+Inlining+NGEN
    This PR (5715) - mean (1,011ms)  : 976, 1047
     .   : milestone, 1011,
    master - mean (989ms)  : 970, 1009
     .   : milestone, 989,

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

    section CallTarget+Inlining+NGEN
    This PR (5715) - mean (708ms)  : 686, 729
     .   : milestone, 708,
    master - mean (699ms)  : 677, 721
     .   : milestone, 699,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5715) - mean (93ms)  : 90, 95
     .   : milestone, 93,
    master - mean (93ms)  : 90, 96
     .   : milestone, 93,

    section CallTarget+Inlining+NGEN
    This PR (5715) - mean (669ms)  : 646, 693
     .   : milestone, 669,
    master - mean (658ms)  : 628, 687
     .   : milestone, 658,

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

    section CallTarget+Inlining+NGEN
    This PR (5715) - mean (1,104ms)  : 1079, 1129
     .   : milestone, 1104,
    master - mean (1,093ms)  : 1068, 1117
     .   : milestone, 1093,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5715) - mean (278ms)  : 272, 283
     .   : milestone, 278,
    master - mean (278ms)  : 273, 283
     .   : milestone, 278,

    section CallTarget+Inlining+NGEN
    This PR (5715) - mean (880ms)  : 860, 900
     .   : milestone, 880,
    master - mean (884ms)  : 859, 909
     .   : milestone, 884,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5715) - mean (266ms)  : 262, 269
     .   : milestone, 266,
    master - mean (267ms)  : 262, 272
     .   : milestone, 267,

    section CallTarget+Inlining+NGEN
    This PR (5715) - mean (866ms)  : 842, 889
     .   : milestone, 866,
    master - mean (862ms)  : 833, 891
     .   : milestone, 862,

Loading

@andrewlock andrewlock force-pushed the andrew/config-refactor/2-extra-converters branch from 09c39c4 to d50c73d Compare June 20, 2024 14:01
@andrewlock andrewlock force-pushed the andrew/config-refactor/3-extra-abstractions branch from f1eccb9 to 50b3ac7 Compare June 20, 2024 14:01
@andrewlock
Copy link
Member Author

andrewlock commented Jun 20, 2024

Benchmarks Report for appsec 🐌

Benchmarks for #5715 compared to master:

  • All benchmarks have the same speed
  • 2 benchmarks have fewer allocations
  • 1 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 71μs 93.8ns 351ns 0.0707 0 0 6 KB
master AllCycleSimpleBody netcoreapp3.1 61.4μs 75.9ns 294ns 0.0925 0 0 6.94 KB
master AllCycleSimpleBody net472 47.2μs 81.6ns 316ns 1.32 0 0 8.33 KB
master AllCycleMoreComplexBody net6.0 76.6μs 157ns 608ns 0.115 0 0 9.5 KB
master AllCycleMoreComplexBody netcoreapp3.1 69.5μs 138ns 534ns 0.137 0 0 10.36 KB
master AllCycleMoreComplexBody net472 54.6μs 118ns 456ns 1.87 0.027 0 11.84 KB
master ObjectExtractorSimpleBody net6.0 142ns 0.158ns 0.61ns 0.00395 0 0 280 B
master ObjectExtractorSimpleBody netcoreapp3.1 200ns 0.153ns 0.572ns 0.00375 0 0 272 B
master ObjectExtractorSimpleBody net472 179ns 0.216ns 0.838ns 0.0446 0 0 281 B
master ObjectExtractorMoreComplexBody net6.0 3.1μs 1.78ns 6.67ns 0.0526 0 0 3.78 KB
master ObjectExtractorMoreComplexBody netcoreapp3.1 4.05μs 1.54ns 5.75ns 0.0506 0 0 3.69 KB
master ObjectExtractorMoreComplexBody net472 3.8μs 2.98ns 11.6ns 0.602 0.0057 0 3.8 KB
#5715 AllCycleSimpleBody net6.0 72μs 92.5ns 358ns 0.0721 0 0 6 KB
#5715 AllCycleSimpleBody netcoreapp3.1 61.6μs 86.7ns 336ns 0.091 0 0 6.94 KB
#5715 AllCycleSimpleBody net472 47.5μs 39.7ns 143ns 1.31 0 0 8.33 KB
#5715 AllCycleMoreComplexBody net6.0 78.3μs 172ns 620ns 0.117 0 0 9.5 KB
#5715 AllCycleMoreComplexBody netcoreapp3.1 69.2μs 56.4ns 218ns 0.137 0 0 10.36 KB
#5715 AllCycleMoreComplexBody net472 54.9μs 67.4ns 261ns 1.86 0.0273 0 11.84 KB
#5715 ObjectExtractorSimpleBody net6.0 150ns 0.206ns 0.798ns 0.00393 0 0 280 B
#5715 ObjectExtractorSimpleBody netcoreapp3.1 191ns 0.0889ns 0.333ns 0.00374 0 0 272 B
#5715 ObjectExtractorSimpleBody net472 171ns 0.229ns 0.888ns 0.0446 0 0 281 B
#5715 ObjectExtractorMoreComplexBody net6.0 3.01μs 1.15ns 4.15ns 0.0529 0 0 3.78 KB
#5715 ObjectExtractorMoreComplexBody netcoreapp3.1 3.94μs 2.77ns 10.4ns 0.0491 0 0 3.69 KB
#5715 ObjectExtractorMoreComplexBody net472 3.84μs 2.97ns 11.5ns 0.603 0.00574 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 38.2μs 27.4ns 106ns 0.453 0 0 32.4 KB
master EncodeArgs netcoreapp3.1 54.6μs 28.5ns 107ns 0.436 0 0 32.4 KB
master EncodeArgs net472 66.4μs 53.8ns 201ns 5.14 0.0663 0 32.5 KB
master EncodeLegacyArgs net6.0 73.7μs 68.1ns 255ns 0 0 0 2.14 KB
master EncodeLegacyArgs netcoreapp3.1 108μs 85.1ns 330ns 0 0 0 2.14 KB
master EncodeLegacyArgs net472 157μs 47.5ns 178ns 0.311 0 0 2.15 KB
#5715 EncodeArgs net6.0 38.3μs 17.4ns 67.6ns 0.455 0 0 32.4 KB
#5715 EncodeArgs netcoreapp3.1 55.3μs 45.7ns 171ns 0.439 0 0 32.4 KB
#5715 EncodeArgs net472 66.7μs 40.9ns 153ns 5.15 0.0664 0 32.5 KB
#5715 EncodeLegacyArgs net6.0 73.9μs 43.7ns 169ns 0 0 0 2.14 KB
#5715 EncodeLegacyArgs netcoreapp3.1 104μs 52.3ns 203ns 0 0 0 2.14 KB
#5715 EncodeLegacyArgs net472 158μs 108ns 419ns 0.314 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 181μs 55.2ns 206ns 0 0 0 2.42 KB
master RunWafRealisticBenchmark netcoreapp3.1 196μs 351ns 1.36μs 0 0 0 2.37 KB
master RunWafRealisticBenchmark net472 207μs 83.2ns 322ns 0.311 0 0 2.43 KB
master RunWafRealisticBenchmarkWithAttack net6.0 121μs 98.5ns 382ns 0 0 0 1.46 KB
master RunWafRealisticBenchmarkWithAttack netcoreapp3.1 131μs 168ns 650ns 0 0 0 1.45 KB
master RunWafRealisticBenchmarkWithAttack net472 139μs 50.2ns 195ns 0.208 0 0 1.48 KB
#5715 RunWafRealisticBenchmark net6.0 183μs 133ns 513ns 0 0 0 2.42 KB
#5715 RunWafRealisticBenchmark netcoreapp3.1 195μs 287ns 1.11μs 0 0 0 2.37 KB
#5715 RunWafRealisticBenchmark net472 208μs 101ns 390ns 0.312 0 0 2.43 KB
#5715 RunWafRealisticBenchmarkWithAttack net6.0 123μs 62.4ns 242ns 0 0 0 1.46 KB
#5715 RunWafRealisticBenchmarkWithAttack netcoreapp3.1 129μs 92.3ns 346ns 0 0 0 1.45 KB
#5715 RunWafRealisticBenchmarkWithAttack net472 140μs 202ns 781ns 0.209 0 0 1.48 KB
Benchmarks.Trace.Iast.StringAspectsBenchmark - Same speed ✔️ More allocations ⚠️

More allocations ⚠️ in #5715

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑netcoreapp3.1 253.71 KB 255.78 KB 2.07 KB 0.82%

Fewer allocations 🎉 in #5715

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark‑net472 59.51 KB 59.21 KB -304 B -0.51%
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net6.0 265.94 KB 255.98 KB -9.96 KB -3.75%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StringConcatBenchmark net6.0 59.4μs 599ns 5.93μs 0 0 0 43.44 KB
master StringConcatBenchmark netcoreapp3.1 54.4μs 275ns 1.23μs 0 0 0 42.64 KB
master StringConcatBenchmark net472 38.4μs 107ns 384ns 0 0 0 59.51 KB
master StringConcatAspectBenchmark net6.0 307μs 1.73μs 11.6μs 0 0 0 265.94 KB
master StringConcatAspectBenchmark netcoreapp3.1 312μs 4.51μs 43.7μs 0 0 0 253.71 KB
master StringConcatAspectBenchmark net472 280μs 4.34μs 42μs 0 0 0 278.53 KB
#5715 StringConcatBenchmark net6.0 62.2μs 769ns 7.65μs 0 0 0 43.44 KB
#5715 StringConcatBenchmark netcoreapp3.1 63.1μs 882ns 8.77μs 0 0 0 42.64 KB
#5715 StringConcatBenchmark net472 38.1μs 108ns 404ns 0 0 0 59.21 KB
#5715 StringConcatAspectBenchmark net6.0 285μs 5.61μs 54.7μs 0 0 0 255.98 KB
#5715 StringConcatAspectBenchmark netcoreapp3.1 355μs 1.93μs 10.6μs 0 0 0 255.78 KB
#5715 StringConcatAspectBenchmark net472 304μs 6.99μs 67.7μs 0 0 0 278.53 KB

@andrewlock
Copy link
Member Author

andrewlock commented Jun 20, 2024

Benchmarks Report for tracer 🐌

Benchmarks for #5715 compared to master:

  • 1 benchmarks are faster, with geometric mean 1.152
  • 1 benchmarks are slower, with geometric mean 1.152
  • All benchmarks have the same 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.63μs 41.4ns 248ns 0.0151 0.00756 0 5.42 KB
master StartStopWithChild netcoreapp3.1 9.91μs 50.4ns 294ns 0.0247 0.00988 0 5.62 KB
master StartStopWithChild net472 16.2μs 29.5ns 102ns 1.01 0.301 0.0871 6.06 KB
#5715 StartStopWithChild net6.0 7.71μs 43ns 268ns 0.0143 0.00716 0 5.43 KB
#5715 StartStopWithChild netcoreapp3.1 10.1μs 51.5ns 318ns 0.0142 0.00475 0 5.62 KB
#5715 StartStopWithChild net472 16.1μs 48.9ns 189ns 0.997 0.298 0.0804 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 484μs 271ns 1.01μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 645μs 176ns 636ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 827μs 234ns 905ns 0.411 0 0 3.3 KB
#5715 WriteAndFlushEnrichedTraces net6.0 474μs 366ns 1.42μs 0 0 0 2.7 KB
#5715 WriteAndFlushEnrichedTraces netcoreapp3.1 637μs 1.08μs 4.17μs 0 0 0 2.7 KB
#5715 WriteAndFlushEnrichedTraces net472 823μs 243ns 941ns 0.414 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 173μs 179ns 695ns 0.174 0 0 18.44 KB
master SendRequest netcoreapp3.1 193μs 264ns 1.02μs 0.193 0 0 20.6 KB
master SendRequest net472 0.000558ns 0.000219ns 0.000819ns 0 0 0 0 b
#5715 SendRequest net6.0 172μs 215ns 833ns 0.259 0 0 18.44 KB
#5715 SendRequest netcoreapp3.1 195μs 448ns 1.73μs 0.192 0 0 20.6 KB
#5715 SendRequest net472 0.000402ns 0.00021ns 0.000784ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 556μs 854ns 3.31μs 0.543 0 0 41.76 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 657μs 650ns 2.34μs 0.324 0 0 41.72 KB
master WriteAndFlushEnrichedTraces net472 862μs 4.41μs 20.7μs 8.39 2.52 0.419 53.23 KB
#5715 WriteAndFlushEnrichedTraces net6.0 535μs 1.67μs 6.47μs 0.543 0 0 41.76 KB
#5715 WriteAndFlushEnrichedTraces netcoreapp3.1 667μs 1.43μs 5.54μs 0.338 0 0 41.79 KB
#5715 WriteAndFlushEnrichedTraces net472 861μs 3.83μs 14.3μs 8.22 2.47 0.411 53.25 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 988ns 0.248ns 0.927ns 0.0114 0 0 808 B
master ExecuteNonQuery netcoreapp3.1 1.41μs 0.709ns 2.65ns 0.0106 0 0 808 B
master ExecuteNonQuery net472 1.78μs 3.02ns 11.7ns 0.122 0 0 770 B
#5715 ExecuteNonQuery net6.0 1.06μs 0.317ns 1.23ns 0.0112 0 0 808 B
#5715 ExecuteNonQuery netcoreapp3.1 1.51μs 3.23ns 12.5ns 0.0105 0 0 808 B
#5715 ExecuteNonQuery net472 1.71μs 3.55ns 13.8ns 0.122 0 0 770 B
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.19μs 1.05ns 4.06ns 0.0137 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.54μs 1.34ns 5.2ns 0.0133 0 0 976 B
master CallElasticsearch net472 2.56μs 2.02ns 7.82ns 0.157 0.00128 0 995 B
master CallElasticsearchAsync net6.0 1.28μs 0.414ns 1.6ns 0.0135 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.62μs 0.467ns 1.81ns 0.0138 0 0 1.02 KB
master CallElasticsearchAsync net472 2.63μs 1.83ns 6.83ns 0.167 0.00132 0 1.05 KB
#5715 CallElasticsearch net6.0 1.2μs 0.281ns 1.01ns 0.0138 0 0 976 B
#5715 CallElasticsearch netcoreapp3.1 1.59μs 0.968ns 3.75ns 0.0135 0 0 976 B
#5715 CallElasticsearch net472 2.53μs 3.04ns 11.8ns 0.157 0.00126 0 995 B
#5715 CallElasticsearchAsync net6.0 1.38μs 0.582ns 2.26ns 0.0131 0 0 952 B
#5715 CallElasticsearchAsync netcoreapp3.1 1.63μs 0.496ns 1.72ns 0.0139 0 0 1.02 KB
#5715 CallElasticsearchAsync net472 2.72μs 2.67ns 10.3ns 0.167 0.00134 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.36μs 0.388ns 1.45ns 0.013 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.55μs 0.805ns 2.9ns 0.0124 0 0 952 B
master ExecuteAsync net472 1.84μs 1.68ns 6.49ns 0.145 0 0 915 B
#5715 ExecuteAsync net6.0 1.24μs 3.23ns 12.5ns 0.0136 0 0 952 B
#5715 ExecuteAsync netcoreapp3.1 1.66μs 0.801ns 3.1ns 0.0125 0 0 952 B
#5715 ExecuteAsync net472 1.82μs 1.09ns 4.2ns 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.35μs 1.45ns 5.43ns 0.0306 0 0 2.22 KB
master SendAsync netcoreapp3.1 5.05μs 1.42ns 5.49ns 0.0354 0 0 2.76 KB
master SendAsync net472 7.59μs 1.83ns 7.08ns 0.5 0 0 3.15 KB
#5715 SendAsync net6.0 4.21μs 1.97ns 7.64ns 0.0316 0 0 2.22 KB
#5715 SendAsync netcoreapp3.1 5.06μs 2.5ns 9.67ns 0.0354 0 0 2.76 KB
#5715 SendAsync net472 7.58μs 4.59ns 17.2ns 0.496 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.47μs 0.529ns 1.98ns 0.0226 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.18μs 1.63ns 6.3ns 0.0222 0 0 1.64 KB
master EnrichedLog net472 2.57μs 1.55ns 6.02ns 0.249 0 0 1.57 KB
#5715 EnrichedLog net6.0 1.49μs 0.618ns 2.31ns 0.0232 0 0 1.64 KB
#5715 EnrichedLog netcoreapp3.1 2.27μs 0.902ns 3.37ns 0.0217 0 0 1.64 KB
#5715 EnrichedLog net472 2.44μs 0.788ns 2.95ns 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 113μs 64.3ns 232ns 0.0566 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 117μs 95.7ns 358ns 0 0 0 4.28 KB
master EnrichedLog net472 146μs 51.1ns 184ns 0.657 0.219 0 4.46 KB
#5715 EnrichedLog net6.0 115μs 173ns 669ns 0 0 0 4.28 KB
#5715 EnrichedLog netcoreapp3.1 119μs 125ns 486ns 0 0 0 4.28 KB
#5715 EnrichedLog net472 146μs 41.8ns 162ns 0.657 0.219 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.2μs 1.01ns 3.65ns 0.0306 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.11μs 1.4ns 5.23ns 0.0287 0 0 2.2 KB
master EnrichedLog net472 4.88μs 2.21ns 8.54ns 0.32 0 0 2.02 KB
#5715 EnrichedLog net6.0 3μs 0.987ns 3.82ns 0.0317 0 0 2.2 KB
#5715 EnrichedLog netcoreapp3.1 4.24μs 2.37ns 9.18ns 0.0297 0 0 2.2 KB
#5715 EnrichedLog net472 4.78μs 2.47ns 9.55ns 0.319 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.32μs 0.769ns 2.88ns 0.0158 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.8μs 1.22ns 4.73ns 0.0154 0 0 1.14 KB
master SendReceive net472 1.97μs 0.883ns 3.42ns 0.183 0.000983 0 1.16 KB
#5715 SendReceive net6.0 1.35μs 0.968ns 3.62ns 0.0157 0 0 1.14 KB
#5715 SendReceive netcoreapp3.1 1.77μs 2.08ns 8.04ns 0.015 0 0 1.14 KB
#5715 SendReceive net472 2.14μs 1.21ns 4.7ns 0.183 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.69μs 0.887ns 3.32ns 0.0215 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 4.07μs 1.86ns 6.96ns 0.0224 0 0 1.65 KB
master EnrichedLog net472 4.45μs 2.99ns 11.2ns 0.324 0 0 2.04 KB
#5715 EnrichedLog net6.0 2.73μs 1.11ns 4.15ns 0.0219 0 0 1.6 KB
#5715 EnrichedLog netcoreapp3.1 3.85μs 2.59ns 10ns 0.0213 0 0 1.65 KB
#5715 EnrichedLog net472 4.36μs 3.76ns 14.6ns 0.323 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #5715

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net6.0 1.152 397.67 458.10

Faster 🎉 in #5715

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑net6.0 1.152 550.31 477.66

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 397ns 0.541ns 2.1ns 0.00816 0 0 576 B
master StartFinishSpan netcoreapp3.1 641ns 0.304ns 1.18ns 0.00771 0 0 576 B
master StartFinishSpan net472 646ns 0.364ns 1.36ns 0.0918 0 0 578 B
master StartFinishScope net6.0 551ns 0.448ns 1.73ns 0.00968 0 0 696 B
master StartFinishScope netcoreapp3.1 755ns 0.695ns 2.41ns 0.00932 0 0 696 B
master StartFinishScope net472 797ns 0.682ns 2.64ns 0.105 0 0 658 B
#5715 StartFinishSpan net6.0 458ns 0.209ns 0.755ns 0.00809 0 0 576 B
#5715 StartFinishSpan netcoreapp3.1 580ns 0.374ns 1.4ns 0.00787 0 0 576 B
#5715 StartFinishSpan net472 622ns 0.844ns 3.27ns 0.0915 0 0 578 B
#5715 StartFinishScope net6.0 478ns 0.142ns 0.551ns 0.00967 0 0 696 B
#5715 StartFinishScope netcoreapp3.1 697ns 0.266ns 0.996ns 0.00939 0 0 696 B
#5715 StartFinishScope net472 854ns 0.432ns 1.67ns 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 690ns 0.199ns 0.744ns 0.0097 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 946ns 0.382ns 1.48ns 0.00949 0 0 696 B
master RunOnMethodBegin net472 1.09μs 0.668ns 2.59ns 0.104 0 0 658 B
#5715 RunOnMethodBegin net6.0 676ns 0.294ns 1.14ns 0.00983 0 0 696 B
#5715 RunOnMethodBegin netcoreapp3.1 936ns 0.262ns 0.981ns 0.00935 0 0 696 B
#5715 RunOnMethodBegin net472 1.1μs 0.465ns 1.8ns 0.104 0 0 658 B

@andrewlock andrewlock force-pushed the andrew/config-refactor/2-extra-converters branch from d50c73d to a10baba Compare June 21, 2024 15:08
@andrewlock andrewlock force-pushed the andrew/config-refactor/3-extra-abstractions branch from 50b3ac7 to 6669900 Compare June 21, 2024 15:08
@andrewlock andrewlock force-pushed the andrew/config-refactor/2-extra-converters branch from a10baba to 85e3f37 Compare June 21, 2024 16:19
@andrewlock andrewlock force-pushed the andrew/config-refactor/3-extra-abstractions branch from 6669900 to 324b11a Compare June 21, 2024 16:19
@andrewlock
Copy link
Member Author

andrewlock commented Jun 21, 2024

Throughput/Crank Report:zap:

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 (5715) (11.621M)   : 0, 11621419
    master (11.593M)   : 0, 11593369
    benchmarks/2.9.0 (11.542M)   : 0, 11542126

    section Automatic
    This PR (5715) (7.879M)   : 0, 7878831
    master (7.827M)   : 0, 7827212
    benchmarks/2.9.0 (8.263M)   : 0, 8262905

    section Trace stats
    master (8.118M)   : 0, 8118390

    section Manual
    This PR (5715) (9.984M)   : 0, 9983744
    master (9.920M)   : 0, 9920204

    section Manual + Automatic
    This PR (5715) (7.405M)   : 0, 7404774
    master (7.358M)   : 0, 7357979

    section Version Conflict
    master (6.635M)   : 0, 6634804

Loading
gantt
    title Throughput Linux arm64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (5715) (9.499M)   : 0, 9498763
    master (9.689M)   : 0, 9688586
    benchmarks/2.9.0 (9.596M)   : 0, 9596140

    section Automatic
    This PR (5715) (6.758M)   : 0, 6758328
    master (6.298M)   : 0, 6298066

    section Trace stats
    master (6.862M)   : 0, 6861645

    section Manual
    This PR (5715) (8.322M)   : 0, 8322285
    master (8.028M)   : 0, 8028063

    section Manual + Automatic
    This PR (5715) (6.281M)   : 0, 6280596
    master (6.139M)   : 0, 6139377

    section Version Conflict
    master (5.667M)   : 0, 5667497

Loading
gantt
    title Throughput Windows x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (5715) (10.047M)   : 0, 10046646
    master (10.241M)   : 0, 10241408
    benchmarks/2.9.0 (10.213M)   : 0, 10213239

    section Automatic
    This PR (5715) (7.088M)   : 0, 7087621
    master (7.186M)   : 0, 7186302
    benchmarks/2.9.0 (7.482M)   : 0, 7482023

    section Trace stats
    master (7.568M)   : 0, 7568098

    section Manual
    This PR (5715) (8.847M)   : 0, 8847057
    master (9.213M)   : 0, 9213352

    section Manual + Automatic
    This PR (5715) (6.863M)   : 0, 6863162
    master (7.004M)   : 0, 7004280

    section Version Conflict
    master (6.289M)   : 0, 6288694

Loading

@andrewlock andrewlock force-pushed the andrew/config-refactor/2-extra-converters branch from 85e3f37 to 6ddca1c Compare June 24, 2024 07:30
@andrewlock andrewlock force-pushed the andrew/config-refactor/3-extra-abstractions branch from 324b11a to 7b76743 Compare June 24, 2024 07:30
Comment on lines +80 to +82
// Note: Calling GetAsClass<string>() here instead of GetAsString() as we need to get the
// "serialized JToken", which in JsonConfigurationSource is different, as it allows for non-string tokens
SamplingRules = settings.WithKeys(ConfigurationKeys.CustomSamplingRules).GetAsClass<string>(validator: null, converter: s => s),
Copy link
Member

@lucaspimentel lucaspimentel Jun 24, 2024

Choose a reason for hiding this comment

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

Thanks! 😅

@@ -63,6 +63,55 @@ public ConfigurationBuilder(IConfigurationSource source, IConfigurationTelemetry

public HasKeys WithKeys(string key, string fallbackKey1, string fallbackKey2, string fallbackKey3) => new(_source, _telemetry, key, fallbackKey1, fallbackKey2, fallbackKey3);

private static bool TryHandleResult<T>(
Copy link
Collaborator

@zacharycmontoya zacharycmontoya Jun 24, 2024

Choose a reason for hiding this comment

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

nit: It looks like you call this in GetAs<T> knowing that the getDefaultValue argument is always non-null, and then in GetAsClass<T> / GetAsStruct<T> you always pass null. Could you break out TryHandleResult<T> into two overloads, one where it is present and one where it is not nullable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you break out TryHandleResult into two overloads, one where it is present and one where it is not nullable?

I definitely could, I was just trying to reduce the amount of duplication 😅 Maybe it's not worth the hassle 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

So the really annoying thing here is that I can't do that with method overloads. So we're need to call it something like TryHandleResultWithOptionalDefault or something 😅 and it still doesn't solve the need to use ! because of the weirdness with nullables and struct/classes, so I'm not sure it gains a lot overall 🤔

Copy link
Collaborator

@zacharycmontoya zacharycmontoya left a comment

Choose a reason for hiding this comment

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

LGTM with one small comment!

@andrewlock andrewlock force-pushed the andrew/config-refactor/2-extra-converters branch from 6ddca1c to e26f946 Compare June 25, 2024 09:45
@andrewlock andrewlock force-pushed the andrew/config-refactor/3-extra-abstractions branch from 7b76743 to 248be76 Compare June 25, 2024 09:45
@andrewlock andrewlock force-pushed the andrew/config-refactor/2-extra-converters branch from e26f946 to 28a3186 Compare June 26, 2024 12:24
@andrewlock andrewlock force-pushed the andrew/config-refactor/3-extra-abstractions branch from 248be76 to b2d6f5a Compare June 26, 2024 12:24
andrewlock added a commit that referenced this pull request Jun 28, 2024
…5713)

## Summary of changes

- Changes `ITelemetredConfigurationSource` methods to return
`ConfigurationResult<T>` instead of `ConfigurationResult<T>?`
- Add additional properties to `ConfigurationResult<>` to distinguish
between "key not found" and "value not parsable"

## Reason for change

In #5661, we added
support for mapping standard OTel configuration to DD equivalents.
Unfortunately, doing this correctly required distinguishing between "key
not found" and "value not parsable". As a workaround, an addition method
`IsPresent(key)` was added, but this essentially duplicates a lot of the
work we're already doing when loading keys "normally".

The changes in this PR are a first step to simplifying and unifying the
support for Otel

## Implementation details

- Change all `ITelemeteredConfigurationSource.Get*` methods to return
`ConfigurationResult` instead of a potentially null value. Update all
sources as appropriate.
- Update `ConfigurationResult`
  - Add `bool IsPresent()`
- Add `LoadResult` enum which can be one of `Valid`, `NotFound`,
`ParsingError`, or `ValidationFailure `. Previously we effectively had a
bool of just `Valid` or `ValidationFailure`, and "is null" meant
`NotFound` _or_ `ParsingError`
  - Add helper method `ShouldFallBack`
- Refactor `ConfigurationBuilder`
- Extract common "cascading fallbacks" code to private `GetResult`
methods. By extracting static lambdas we can reuse a lot of the logic
for multiple types
  - Refactor code to use the new properties where possible. 
- `ITelemeteredConfigurationSource.IsPresent` is still used in Otel
paths currently - removed in a subsequent PR

## Test coverage

This is just a refactor, so all covered by existing tests

## Other details

This is part of a big stack of config refactoring PRs:

- #5713 (this PR)
- #5714
- #5715
- #5716
- #5717

<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->
@andrewlock andrewlock force-pushed the andrew/config-refactor/2-extra-converters branch from 28a3186 to 811d98d Compare June 28, 2024 09:13
@andrewlock andrewlock force-pushed the andrew/config-refactor/3-extra-abstractions branch from b2d6f5a to 5f72dbc Compare June 28, 2024 09:13
andrewlock added a commit that referenced this pull request Jun 28, 2024
…5714)

## Summary of changes

Allow providing additional "converters" for types other than the generic
`T`, such as `int` and `bool`

## Reason for change

The otel-specific code introduced in
#5661 requires performing
non-standard conversions to some primitive types. For example, for a
`bool` the required values might be `"none"`=`true`, which requires
using `GetAs<>` to handle the conversion.

This PR adds additional overloads so that you can call `GetAsBool` which
makes the usages more obvious (and simplifies some things in subsequent
PRs)

## Implementation details

Add additional, optional, "converter" arguments (`Func<string,
ParsingResult<bool>>`) to the methods that don't already have them

## Test coverage

Add unit tests for the new conversion behaviour

## Other details

This is part of a big stack of config refactoring PRs:


- #5713
- #5714 (this PR)
- #5715
- #5716
- #5717

<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->
Base automatically changed from andrew/config-refactor/2-extra-converters to master June 28, 2024 10:59
@andrewlock andrewlock force-pushed the andrew/config-refactor/3-extra-abstractions branch from 5f72dbc to f14db42 Compare June 28, 2024 11:00
@andrewlock andrewlock merged commit bd869dc into master Jun 28, 2024
53 of 58 checks passed
@andrewlock andrewlock deleted the andrew/config-refactor/3-extra-abstractions branch June 28, 2024 13:13
@github-actions github-actions bot added this to the vNext-v2 milestone Jun 28, 2024
andrewlock added a commit that referenced this pull request Jul 2, 2024
…figurationBuilder` (#5716)

## Summary of changes

- Removes all the `ConfigurationBuilder` method overloads that contained
otel-specific code
- Refactor the otel-specific code to be in the caller (e.g.
`TracerSettings`) not `ConfigurationBuilder`

## Reason for change

`ConfigurationBuilder` is used _anywhere_ that we need to load config,
which can be very early in the startup process. That limits what we can
safely do in there (e.g. logging).

Also, having otel-specific functions for remapping keys and changing
behaviour in `ConfigurationBuilder` felt wrong. With these changes we
still encapsulate the _general_ "override" concept (where a value could
come from two very different source key/values), while removing the
_specifics_ to the callee. This should allow us to more easily support
additional use cases in the future.

## Implementation details

- Remove all the "otel-specific" overloads in `ConfigurationBuilder`
- Add `OverrideWith()` to `StructConfigurationResultWithKey` and
`ClassConfigurationResultWithKey`
- Extract the "override" method to be a single, instead of multiply
implemented in several places.
- Replace all the OTel methods with their equivalent

Unfortunately, loading sample rates is still pretty complicated, so the
logic for that has _mostly_ just been moved into `TracerSettings`
without much simplification.

## Test coverage

This is all covered by existing `TracerSettingsTests` and
`GlobalSettingsTests`!

## Other details

This is part of a big stack of config refactoring PRs:


- #5713
- #5714
- #5715
- #5716 (this PR)
- #5717

<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->
andrewlock added a commit that referenced this pull request Aug 8, 2024
## Summary of changes

Records logs and metrics for when otel config is overriden by datadog
config, or when it's invalid

## Reason for change

This was originally part of
#5661, but wasn't
possible due to concerns with the fact `ConfigurationBuilder` is used in
critical "startup" paths for the tracer, so can result in recursion if
we're not careful.

## Implementation details

The crux of the implementation is that we "store" error and metrics for
writing at the point we know it's safe. This is _similar_ to what we
already do for configuration telemetry.

(Technically I think we _Could_ directly access the
`TelemetryFactory.Metrics`, but this is "safer", and makes it easier to
test we're sending the right metrics

## Test coverage

Added unit tests to all of the existing settings tests where we override
configuration to confirm that it works as expected

## Other details

The metrics etc are all ported from
#5661, but there are
currently some issues with the proposed values:

- [x] The metrics aren't added to the intake yet, so need updating there
(and copying here)
- [x] The tag names aren't "valid" for standard telemetry metrics, they
should be lowercase, and shouldn't use `.`. I would suggest changing
these to be lowercase and replacing `.` with `_`, but either way this
should happen after they've been OK'd in the intake.

Part of a big ole stack:


- #5713
- #5714
- #5715
- #5716
- #5717 (this PR)

<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->

---------

Co-authored-by: Zach Montoya <zach.montoya@datadoghq.com>
andrewlock added a commit that referenced this pull request Aug 8, 2024
Records logs and metrics for when otel config is overriden by datadog
config, or when it's invalid

This was originally part of
#5661, but wasn't
possible due to concerns with the fact `ConfigurationBuilder` is used in
critical "startup" paths for the tracer, so can result in recursion if
we're not careful.

The crux of the implementation is that we "store" error and metrics for
writing at the point we know it's safe. This is _similar_ to what we
already do for configuration telemetry.

(Technically I think we _Could_ directly access the
`TelemetryFactory.Metrics`, but this is "safer", and makes it easier to
test we're sending the right metrics

Added unit tests to all of the existing settings tests where we override
configuration to confirm that it works as expected

The metrics etc are all ported from
#5661, but there are
currently some issues with the proposed values:

- [x] The metrics aren't added to the intake yet, so need updating there
(and copying here)
- [x] The tag names aren't "valid" for standard telemetry metrics, they
should be lowercase, and shouldn't use `.`. I would suggest changing
these to be lowercase and replacing `.` with `_`, but either way this
should happen after they've been OK'd in the intake.

Part of a big ole stack:

- #5713
- #5714
- #5715
- #5716
- #5717 (this PR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) type:refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants