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

[Test Optimization] - Code refactor #6709

Merged
merged 22 commits into from
Feb 26, 2025
Merged

Conversation

tonyredondo
Copy link
Member

@tonyredondo tonyredondo commented Feb 24, 2025

Summary of changes

https://datadoghq.atlassian.net/browse/SDTEST-1423

This PR introduces a complete refactor of the existing two classes:

  • CIVisibility.cs
  • IntelligentTestRunnerClient.cs

Alsos rename the following classes:

  • TestOptimizationTracerManager.cs
  • TestOptimizationTracerManagerFactory.cs
  • TestOptimizationSettings.cs

With the refactor the following changes were made:

CIVisibility.cs

  • Removed the static CIVisibility class.
  • Added the following abstractions:
  • ITestOptimization.cs
  • ITestOptimizationHostInfo.cs
  • ITestOptimizationTracerManagement.cs
  • ITestOptimizationFeature.cs
  • ITestOptimizationEarlyFlakeDetectionFeature.cs
  • ITestOptimizationFlakyRetryFeature.cs
  • ITestOptimizationImpactedTestsDetectionFeature.cs
  • ITestOptimizationSkippableFeature.cs
  • Also added an implementation to the abstractions, and removed the static approach with a singleton, similar to the tracer class.

IntelligentTestRunnerClient.cs

  • Removed the IntelligentTestRunnerClient.cs class
  • Added the following files:
  • ITestOptimizationClient.cs : an abstraction for the http client for all test optimization transactions.
  • NoopTestOptimizationClient.cs: a NoOp implementation of the client.
  • CachedTestOptimizationClient.cs: a cache layer over an ITestOptimizationClient.cs
  • TestOptimizationClient.cs: the default implementation partial class, this part handles the basic http operations with retries code.
  • TestOptimizationClient.GetCommitsAsync.cs: the default implementation partial class, this part handles the GetCommitsAsync transaction.
  • TestOptimizationClient.GetEarlyFlakeDetectionTestsAsync.cs: the default implementation partial class, this part handles the GetEarlyFlakeDetectionTestsAsync transaction.
  • TestOptimizationClient.GetImpactedTestsDetectionFilesAsync.cs: the default implementation partial class, this part handles the GetImpactedTestsDetectionFilesAsync transaction.
  • TestOptimizationClient.GetSettingsAsync.cs: the default implementation partial class, this part handles the GetSettingsAsync transaction.
  • TestOptimizationClient.GetSkippableTestsAsync.cs: the default implementation partial class, this part handles the GetSkippableTestsAsync transaction.
  • TestOptimizationClient.SendPackFilesAsync.cs: the default implementation partial class, this part handles the SendPackFilesAsync transaction.
  • TestOptimizationClient.UploadRepositoryChangesAsync.cs: the default implementation partial class, this part handles the UploadRepositoryChangesAsync transaction.

Reason for change

The current code is already complex and hard to maintain, all features are included in only two classes. Before introducing more features in the product (KnownTests, FlakyTestManagement) we need to improve the existing code and make our life easier.

Implementation details

It's the same code sparse in different files with a better structure for both adding new features and testing.

Test coverage

Same tests must behave the same we are not looking for a change of the current behavior.

Other details

@tonyredondo tonyredondo changed the title Tony/test optimization refactor [Test Optimization] - Code refactor Feb 26, 2025
@DataDog DataDog deleted a comment from andrewlock Feb 26, 2025
@DataDog DataDog deleted a comment from andrewlock Feb 26, 2025
@DataDog DataDog deleted a comment from datadog-datadog-prod-us1 bot Feb 26, 2025
@tonyredondo tonyredondo marked this pull request as ready for review February 26, 2025 12:00
@tonyredondo tonyredondo requested review from a team as code owners February 26, 2025 12:00
@DataDog DataDog deleted a comment from andrewlock Feb 26, 2025
@andrewlock
Copy link
Member

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 (6709) - mean (75ms)  : 70, 80
     .   : milestone, 75,
    master - mean (70ms)  : 66, 73
     .   : milestone, 70,

    section CallTarget+Inlining+NGEN
    This PR (6709) - mean (1,041ms)  : 1011, 1071
     .   : milestone, 1041,
    master - mean (1,006ms)  : 978, 1033
     .   : milestone, 1006,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6709) - mean (110ms)  : 105, 114
     .   : milestone, 110,
    master - mean (102ms)  : 100, 105
     .   : milestone, 102,

    section CallTarget+Inlining+NGEN
    This PR (6709) - mean (706ms)  : 685, 727
     .   : milestone, 706,
    master - mean (677ms)  : 661, 692
     .   : milestone, 677,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6709) - mean (96ms)  : 92, 100
     .   : milestone, 96,
    master - mean (90ms)  : 88, 91
     .   : milestone, 90,

    section CallTarget+Inlining+NGEN
    This PR (6709) - mean (664ms)  : 644, 683
     .   : milestone, 664,
    master - mean (637ms)  : 618, 656
     .   : milestone, 637,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6709) - mean (192ms)  : 187, 196
     .   : milestone, 192,
    master - mean (190ms)  : 186, 195
     .   : milestone, 190,

    section CallTarget+Inlining+NGEN
    This PR (6709) - mean (1,104ms)  : 1082, 1126
     .   : milestone, 1104,
    master - mean (1,109ms)  : 1078, 1139
     .   : milestone, 1109,

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

    section CallTarget+Inlining+NGEN
    This PR (6709) - mean (863ms)  : 841, 885
     .   : milestone, 863,
    master - mean (880ms)  : 814, 946
     .   : milestone, 880,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6709) - mean (263ms)  : 258, 267
     .   : milestone, 263,
    master - mean (262ms)  : 257, 267
     .   : milestone, 262,

    section CallTarget+Inlining+NGEN
    This PR (6709) - mean (848ms)  : 815, 881
     .   : milestone, 848,
    master - mean (849ms)  : 821, 878
     .   : milestone, 849,

Loading

@andrewlock
Copy link
Member

Benchmarks Report for tracer 🐌

Benchmarks for #6709 compared to master:

  • 2 benchmarks are faster, with geometric mean 1.151
  • 1 benchmarks are slower, with geometric mean 1.126
  • 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 8.2μs 47.3ns 375ns 0.0131 0.00437 0 5.61 KB
master StartStopWithChild netcoreapp3.1 10.6μs 59.1ns 405ns 0.0148 0.00492 0 5.8 KB
master StartStopWithChild net472 16.2μs 51ns 198ns 1.03 0.297 0.0882 6.21 KB
#6709 StartStopWithChild net6.0 8.3μs 46.2ns 379ns 0.015 0.00748 0 5.61 KB
#6709 StartStopWithChild netcoreapp3.1 10.3μs 56.9ns 422ns 0.0197 0.00987 0 5.81 KB
#6709 StartStopWithChild net472 16.1μs 71.9ns 279ns 1.04 0.3 0.0973 6.21 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 481μs 177ns 684ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 637μs 249ns 966ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 858μs 498ns 1.93μs 0.428 0 0 3.3 KB
#6709 WriteAndFlushEnrichedTraces net6.0 493μs 414ns 1.55μs 0 0 0 2.7 KB
#6709 WriteAndFlushEnrichedTraces netcoreapp3.1 655μs 2.01μs 7.77μs 0 0 0 2.7 KB
#6709 WriteAndFlushEnrichedTraces net472 858μs 1.25μs 4.49μs 0.425 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 132μs 510ns 1.98μs 0.131 0 0 14.47 KB
master SendRequest netcoreapp3.1 149μs 235ns 911ns 0.15 0 0 17.27 KB
master SendRequest net472 0.00481ns 0.000682ns 0.00264ns 0 0 0 0 b
#6709 SendRequest net6.0 131μs 503ns 1.95μs 0.199 0 0 14.47 KB
#6709 SendRequest netcoreapp3.1 147μs 222ns 832ns 0.221 0 0 17.27 KB
#6709 SendRequest net472 0ns 0ns 0ns 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 592μs 3.35μs 23.9μs 0.581 0 0 41.61 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 695μs 3.67μs 19.8μs 0.336 0 0 41.74 KB
master WriteAndFlushEnrichedTraces net472 842μs 3.23μs 12.5μs 8.33 2.5 0.417 53.29 KB
#6709 WriteAndFlushEnrichedTraces net6.0 569μs 3.15μs 19.7μs 0.532 0 0 41.56 KB
#6709 WriteAndFlushEnrichedTraces netcoreapp3.1 684μs 3.79μs 22.1μs 0.327 0 0 41.76 KB
#6709 WriteAndFlushEnrichedTraces net472 872μs 4.15μs 16.6μs 8.25 2.6 0.434 53.3 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.45μs 1.12ns 4.33ns 0.0145 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.76μs 0.919ns 3.31ns 0.0132 0 0 1.02 KB
master ExecuteNonQuery net472 1.97μs 1.66ns 6.44ns 0.156 0.000983 0 987 B
#6709 ExecuteNonQuery net6.0 1.33μs 1.27ns 4.91ns 0.0139 0 0 1.02 KB
#6709 ExecuteNonQuery netcoreapp3.1 1.75μs 2.53ns 9.79ns 0.0139 0 0 1.02 KB
#6709 ExecuteNonQuery net472 2.06μs 1.39ns 5.4ns 0.156 0.00103 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Faster 🎉 Same allocations ✔️

Faster 🎉 in #6709

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch‑net6.0 1.184 1,410.15 1,190.66

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.41μs 0.567ns 2.12ns 0.0141 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.56μs 0.45ns 1.68ns 0.0133 0 0 976 B
master CallElasticsearch net472 2.59μs 2.28ns 8.53ns 0.158 0 0 995 B
master CallElasticsearchAsync net6.0 1.38μs 0.521ns 1.95ns 0.0132 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.63μs 0.91ns 3.53ns 0.0131 0 0 1.02 KB
master CallElasticsearchAsync net472 2.63μs 1.44ns 5.59ns 0.166 0 0 1.05 KB
#6709 CallElasticsearch net6.0 1.19μs 0.941ns 3.64ns 0.0135 0 0 976 B
#6709 CallElasticsearch netcoreapp3.1 1.54μs 0.548ns 2.05ns 0.013 0 0 976 B
#6709 CallElasticsearch net472 2.44μs 3.01ns 11.7ns 0.158 0 0 995 B
#6709 CallElasticsearchAsync net6.0 1.35μs 0.794ns 2.97ns 0.0128 0 0 952 B
#6709 CallElasticsearchAsync netcoreapp3.1 1.62μs 1.43ns 5.15ns 0.0139 0 0 1.02 KB
#6709 CallElasticsearchAsync net472 2.62μs 1.14ns 4.41ns 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.27μs 0.549ns 2.06ns 0.0134 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.69μs 0.743ns 2.88ns 0.0128 0 0 952 B
master ExecuteAsync net472 1.87μs 0.472ns 1.77ns 0.145 0 0 915 B
#6709 ExecuteAsync net6.0 1.24μs 1.67ns 6.48ns 0.0136 0 0 952 B
#6709 ExecuteAsync netcoreapp3.1 1.58μs 1.23ns 4.76ns 0.0129 0 0 952 B
#6709 ExecuteAsync net472 1.82μs 0.54ns 2.09ns 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.42μs 3.19ns 12ns 0.0331 0 0 2.31 KB
master SendAsync netcoreapp3.1 5.42μs 2.36ns 9.13ns 0.0379 0 0 2.85 KB
master SendAsync net472 7.43μs 1.57ns 6.07ns 0.493 0 0 3.12 KB
#6709 SendAsync net6.0 4.56μs 1.91ns 7.41ns 0.032 0 0 2.31 KB
#6709 SendAsync netcoreapp3.1 5.34μs 4.25ns 15.3ns 0.0373 0 0 2.85 KB
#6709 SendAsync net472 7.52μs 1.56ns 6.03ns 0.496 0 0 3.12 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.51μs 0.885ns 3.31ns 0.0227 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.14μs 3ns 11.6ns 0.0216 0 0 1.64 KB
master EnrichedLog net472 2.6μs 1.16ns 4.34ns 0.25 0 0 1.57 KB
#6709 EnrichedLog net6.0 1.63μs 0.94ns 3.25ns 0.0228 0 0 1.64 KB
#6709 EnrichedLog netcoreapp3.1 2.23μs 4.52ns 16.9ns 0.022 0 0 1.64 KB
#6709 EnrichedLog net472 2.6μs 1.33ns 5.15ns 0.25 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 112μs 57.1ns 214ns 0.0559 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 117μs 213ns 824ns 0 0 0 4.28 KB
master EnrichedLog net472 151μs 120ns 466ns 0.679 0.226 0 4.46 KB
#6709 EnrichedLog net6.0 113μs 201ns 777ns 0.0561 0 0 4.28 KB
#6709 EnrichedLog netcoreapp3.1 117μs 146ns 565ns 0.058 0 0 4.28 KB
#6709 EnrichedLog net472 150μs 198ns 766ns 0.671 0.224 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.1μs 0.965ns 3.74ns 0.031 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.18μs 4.19ns 16.2ns 0.029 0 0 2.2 KB
master EnrichedLog net472 4.81μs 0.499ns 1.87ns 0.318 0 0 2.02 KB
#6709 EnrichedLog net6.0 3.22μs 0.58ns 2.17ns 0.0305 0 0 2.2 KB
#6709 EnrichedLog netcoreapp3.1 4.2μs 1.65ns 5.94ns 0.0294 0 0 2.2 KB
#6709 EnrichedLog net472 4.81μs 1.63ns 6.33ns 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.866ns 3.36ns 0.0159 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.79μs 1.19ns 4.62ns 0.0152 0 0 1.14 KB
master SendReceive net472 2.12μs 0.528ns 1.9ns 0.183 0 0 1.16 KB
#6709 SendReceive net6.0 1.4μs 0.827ns 3.2ns 0.0161 0 0 1.14 KB
#6709 SendReceive netcoreapp3.1 1.75μs 1.36ns 5.25ns 0.0157 0 0 1.14 KB
#6709 SendReceive net472 2.14μs 1.48ns 5.73ns 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.76μs 1.16ns 4.48ns 0.0221 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.84μs 1.57ns 6.07ns 0.021 0 0 1.65 KB
master EnrichedLog net472 4.24μs 2.57ns 9.63ns 0.322 0 0 2.04 KB
#6709 EnrichedLog net6.0 2.76μs 0.624ns 2.42ns 0.022 0 0 1.6 KB
#6709 EnrichedLog netcoreapp3.1 3.88μs 1.48ns 5.73ns 0.0212 0 0 1.65 KB
#6709 EnrichedLog net472 4.32μs 2.53ns 9.81ns 0.322 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6709

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net6.0 1.126 412.96 465.18

Faster 🎉 in #6709

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑net472 1.119 844.90 755.18

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 412ns 0.714ns 2.76ns 0.00808 0 0 576 B
master StartFinishSpan netcoreapp3.1 564ns 1.37ns 5.31ns 0.0076 0 0 576 B
master StartFinishSpan net472 563ns 1.15ns 4.45ns 0.0917 0 0 578 B
master StartFinishScope net6.0 472ns 1.04ns 3.9ns 0.00987 0 0 696 B
master StartFinishScope netcoreapp3.1 670ns 0.765ns 2.96ns 0.00926 0 0 696 B
master StartFinishScope net472 845ns 0.553ns 2ns 0.104 0 0 658 B
#6709 StartFinishSpan net6.0 465ns 0.637ns 2.47ns 0.00803 0 0 576 B
#6709 StartFinishSpan netcoreapp3.1 544ns 1.01ns 3.92ns 0.0078 0 0 576 B
#6709 StartFinishSpan net472 606ns 0.371ns 1.34ns 0.0916 0 0 578 B
#6709 StartFinishScope net6.0 486ns 0.85ns 3.18ns 0.00967 0 0 696 B
#6709 StartFinishScope netcoreapp3.1 708ns 1.43ns 5.54ns 0.00929 0 0 696 B
#6709 StartFinishScope net472 754ns 1.4ns 5.44ns 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 617ns 0.913ns 3.54ns 0.00965 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 896ns 1.7ns 6.6ns 0.00938 0 0 696 B
master RunOnMethodBegin net472 1.07μs 2ns 7.74ns 0.104 0 0 658 B
#6709 RunOnMethodBegin net6.0 656ns 1.18ns 4.56ns 0.00989 0 0 696 B
#6709 RunOnMethodBegin netcoreapp3.1 914ns 1.59ns 6.15ns 0.00932 0 0 696 B
#6709 RunOnMethodBegin net472 1.03μs 2.17ns 8.39ns 0.104 0 0 658 B

@tonyredondo tonyredondo merged commit 5ec6170 into master Feb 26, 2025
145 of 148 checks passed
@tonyredondo tonyredondo deleted the tony/test-optimization-refactor branch February 26, 2025 14:59
@github-actions github-actions bot added this to the vNext-v3 milestone Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants