Refacto: Make ContainerMetadata an instance class#7898
Conversation
|
BenchmarksBenchmark execution time: 2025-12-31 16:24:11 Comparing candidate commit 9e538ec in PR branch Found 4 performance improvements and 6 performance regressions! Performance is the same for 161 metrics, 15 unstable metrics. scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net6.0
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472
scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1
scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0
scenario:Benchmarks.Trace.NLogBenchmark.EnrichedLog netcoreapp3.1
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope netcoreapp3.1
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (7898) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-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 highlighted in **red**. The following thresholds were used for comparing the execution times:
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). Duration chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7898) - mean (69ms) : 68, 71
master - mean (68ms) : 67, 70
section Bailout
This PR (7898) - mean (73ms) : 72, 74
master - mean (72ms) : 71, 74
section CallTarget+Inlining+NGEN
This PR (7898) - mean (1,014ms) : 968, 1061
master - mean (1,007ms) : 968, 1047
FakeDbCommand (.NET Core 3.1)gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7898) - mean (106ms) : 104, 108
master - mean (106ms) : 103, 109
section Bailout
This PR (7898) - mean (107ms) : 106, 108
master - mean (107ms) : 105, 108
section CallTarget+Inlining+NGEN
This PR (7898) - mean (737ms) : 666, 809
master - mean (743ms) : 680, 805
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7898) - mean (94ms) : 92, 95
master - mean (93ms) : 91, 96
section Bailout
This PR (7898) - mean (94ms) : 94, 95
master - mean (94ms) : 93, 95
section CallTarget+Inlining+NGEN
This PR (7898) - mean (715ms) : 694, 736
master - mean (715ms) : 682, 748
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7898) - mean (92ms) : 90, 94
master - mean (92ms) : 90, 94
section Bailout
This PR (7898) - mean (93ms) : 92, 94
master - mean (93ms) : 92, 95
section CallTarget+Inlining+NGEN
This PR (7898) - mean (633ms) : 614, 651
master - mean (629ms) : 615, 644
HttpMessageHandler (.NET Framework 4.8)gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7898) - mean (195ms) : 191, 199
master - mean (194ms) : 190, 198
section Bailout
This PR (7898) - mean (198ms) : 194, 202
master - mean (198ms) : 194, 201
section CallTarget+Inlining+NGEN
This PR (7898) - mean (1,113ms) : 1064, 1162
master - mean (1,123ms) : 1045, 1201
HttpMessageHandler (.NET Core 3.1)gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7898) - mean (278ms) : 273, 283
master - mean (277ms) : 270, 283
section Bailout
This PR (7898) - mean (279ms) : 272, 286
master - mean (277ms) : 274, 280
section CallTarget+Inlining+NGEN
This PR (7898) - mean (929ms) : 877, 981
master - mean (926ms) : 877, 975
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7898) - mean (271ms) : 266, 276
master - mean (271ms) : 266, 276
section Bailout
This PR (7898) - mean (271ms) : 267, 274
master - mean (270ms) : 267, 274
section CallTarget+Inlining+NGEN
This PR (7898) - mean (927ms) : 884, 970
master - mean (931ms) : 905, 958
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7898) - mean (270ms) : 266, 274
master - mean (269ms) : 265, 273
section Bailout
This PR (7898) - mean (270ms) : 266, 275
master - mean (270ms) : 267, 274
section CallTarget+Inlining+NGEN
This PR (7898) - mean (828ms) : 811, 844
master - mean (826ms) : 805, 847
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tracer/test/Datadog.Trace.IntegrationTests/ContainerTaggingTests.cs
Outdated
Show resolved
Hide resolved
tracer/src/Datadog.Trace/PlatformHelpers/ContainerMetadata.NetFramework.cs
Outdated
Show resolved
Hide resolved
| }; | ||
|
|
||
| if (ContainerMetadata.GetContainerId() is { } containerId) | ||
| if (ContainerMetadata.Instance.ContainerId is { } containerId) |
There was a problem hiding this comment.
don't use global instance here
There was a problem hiding this comment.
so, after discussing, I think we can use the global here because it's an integration test. I could remove it in favor of the one in JsonTelemetryTransportTests, but this one tests more things, so I wasn't comfortable in doing so.
Another way to avoid using the global in the test, would be to change the assert to check that the key is set with a non-empty value, but don't assert on the value itself.
There was a problem hiding this comment.
If we're just going to use the global here, may as well use it in the ContainerTaggingTests too I guess, and not bother deleting that? That said, you have a unit test, which is just as good so meh 🤷♂️
There was a problem hiding this comment.
I think it's still nice to be able to get rid of an itest in favor of a utest, independently of this all
|
@codex review |
| public string? EntityId { get; } | ||
| } | ||
|
|
||
| internal static class ContainerMetadataHelper |
There was a problem hiding this comment.
nit: prob should just move this to its own class
| }; | ||
|
|
||
| if (ContainerMetadata.GetContainerId() is { } containerId) | ||
| if (ContainerMetadata.Instance.ContainerId is { } containerId) |
There was a problem hiding this comment.
If we're just going to use the global here, may as well use it in the ContainerTaggingTests too I guess, and not bother deleting that? That said, you have a unit test, which is just as good so meh 🤷♂️
| [CombinatorialValues(null, "my-entity-id")] | ||
| string entityId) | ||
| { | ||
| var responseMock = new Mock<IApiResponse>(); |
There was a problem hiding this comment.
Just FYI, we have TestApiRequest and TestApiResponse which are much easier to work with than Moq IMO. The Moq in here predates those. No need to have to change, just an FYI
There was a problem hiding this comment.
ooooh ok, I just took inspiration from the other tests in the same class ^^
Summary of changes
Everything in that class is public static, and it makes more sense to have it as an instance for testability.
Reason for change
Implementation details
Kept the backing fields as static lazy values, to avoid building them twice. In the context of tests, one would create an override/mock and set the values that way.
I didn't really inject it anywhere though, it'd only make sense in the context of tests.
I could take the opportunity to add tests, but also, I'm doing this to add an extra field to the container metadata, so I can do the work then ?
Test coverage
existing tests
Other details