Skip to content

Review Exporter Settings#2455

Closed
pierotibou wants to merge 12 commits into
masterfrom
pierre/uds-config
Closed

Review Exporter Settings#2455
pierotibou wants to merge 12 commits into
masterfrom
pierre/uds-config

Conversation

@pierotibou

@pierotibou pierotibou commented Feb 17, 2022

Copy link
Copy Markdown
Contributor

Summary of changes

I've removed DD_APM_RECEIVER_SOCKET as it should not have been added. As it is not documented, we agreed with Lucas that it was ok to break the public API. I've also cleaned the settings to reintroduce TraceAgentUri as the first parameter to take into account and make more explicit the order of precedence. Finally, I've removed the TCP Strategy as it wasn't used and as it doesn't seem we want to go further down that road.

Reason for change

A regression had been introduced as we were not using the Trace Agent Uri as the primary parameter to take into account. We've also seen that we may be able to improve how we configure the transport when Kevin developed the Agent checks in the CLI tool.

Implementation details

Regarding the settings refactoring:

  • I had to introduce a builder class to do build the immutable settings as it seemed clearer (I could have done everything from the .ctor though).
  • Removed DD_APM_RECEIVER_SOCKET
  • Reintroduced TraceAgentUri as the first parameter to take into account
  • made clearer the order of precedence of the parameters in the code
  • handled possible wrongly set parameters that would lead to throwing an exception
  • allow falling back on other configuration when fixing the issue would need to restart the app
  • moved the settings construction in ImmutableSettings (through a builder, unfortunately this class is public, I couldn't do all the changes I would have liked to do)
  • Added a bit of logs to explain the issues
  • Removed the TCP strategy

Testing

Tried to add as much testing as I could by testing both ExporterSettings, ImmutableExporterSettings checking both the modified values and the ones that should have stayed with their default values.

Fixes #2426 (hopefully:))

@andrewlock

Copy link
Copy Markdown
Member

Benchmarks Report 🐌

Benchmarks for #2455 compared to master:

  • All benchmarks have the same speed
  • 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.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net472 861μs 4.18μs 28.6μs 0 0 0 3.17 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 636μs 2.51μs 9.72μs 0 0 0 2.57 KB
#2455 WriteAndFlushEnrichedTraces net472 842μs 4μs 16μs 0 0 0 3.16 KB
#2455 WriteAndFlushEnrichedTraces netcoreapp3.1 667μs 3.5μs 20.7μs 0 0 0 2.57 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 net472 0ns 0ns 0ns 0 0 0 0 b
master SendRequest netcoreapp3.1 293μs 1.47μs 6.41μs 0.15 0 0 19.71 KB
#2455 SendRequest net472 0ns 0ns 0ns 0 0 0 0 b
#2455 SendRequest netcoreapp3.1 292μs 1.17μs 4.53μs 0.146 0 0 19.71 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 net472 1.63μs 5.56ns 21.5ns 0.0926 0.000798 0 586 B
master ExecuteNonQuery netcoreapp3.1 1.53μs 5.09ns 19.7ns 0.00826 0 0 624 B
#2455 ExecuteNonQuery net472 1.68μs 3.91ns 14.6ns 0.0931 0 0 586 B
#2455 ExecuteNonQuery netcoreapp3.1 1.51μs 5.61ns 21ns 0.00873 0 0 624 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 net472 2.45μs 9.84ns 36.8ns 0.125 0 0 794 B
master CallElasticsearch netcoreapp3.1 1.76μs 8.36ns 32.4ns 0.0111 0 0 784 B
master CallElasticsearchAsync net472 2.76μs 13.2ns 56.2ns 0.147 0.00137 0 931 B
master CallElasticsearchAsync netcoreapp3.1 1.78μs 6.55ns 25.4ns 0.0124 0 0 904 B
#2455 CallElasticsearch net472 2.59μs 8.31ns 31.1ns 0.126 0 0 794 B
#2455 CallElasticsearch netcoreapp3.1 1.78μs 3.36ns 12.1ns 0.0108 0 0 784 B
#2455 CallElasticsearchAsync net472 2.78μs 11.4ns 59.2ns 0.147 0.00285 0.00142 931 B
#2455 CallElasticsearchAsync netcoreapp3.1 1.85μs 6.72ns 24.2ns 0.0127 0 0 904 B
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net472 2.95μs 13.5ns 88.5ns 0.164 0 0 1.05 KB
master ExecuteAsync netcoreapp3.1 1.96μs 11.2ns 79.9ns 0.0137 0 0 1.02 KB
#2455 ExecuteAsync net472 2.93μs 14.6ns 87.3ns 0.164 0 0 1.05 KB
#2455 ExecuteAsync netcoreapp3.1 1.96μs 10.9ns 64.5ns 0.0136 0 0 1.02 KB
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendAsync net472 6.78μs 22.5ns 84ns 0.364 0 0 2.3 KB
master SendAsync netcoreapp3.1 4.71μs 9.56ns 37ns 0.0309 0 0 2.2 KB
#2455 SendAsync net472 6.98μs 38ns 237ns 0.359 0 0 2.3 KB
#2455 SendAsync netcoreapp3.1 4.81μs 17.9ns 69.4ns 0.0303 0 0 2.2 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 net472 3.12μs 12.2ns 47.2ns 0.226 0 0 1.44 KB
master EnrichedLog netcoreapp3.1 3.07μs 15ns 60ns 0.021 0 0 1.52 KB
#2455 EnrichedLog net472 3.23μs 10.3ns 40ns 0.225 0 0 1.44 KB
#2455 EnrichedLog netcoreapp3.1 3.1μs 13.4ns 51.8ns 0.0213 0 0 1.52 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 net472 281μs 957ns 3.7μs 0.414 0.138 0 4.31 KB
master EnrichedLog netcoreapp3.1 223μs 610ns 2.28μs 0 0 0 4.19 KB
#2455 EnrichedLog net472 288μs 1.26μs 4.88μs 0.424 0.141 0 4.31 KB
#2455 EnrichedLog netcoreapp3.1 231μs 690ns 2.67μs 0 0 0 4.19 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 net472 6.99μs 23.8ns 89.1ns 0.504 0 0 3.21 KB
master EnrichedLog netcoreapp3.1 6.28μs 6.98ns 24.2ns 0.0476 0 0 3.58 KB
#2455 EnrichedLog net472 7.21μs 36.5ns 171ns 0.502 0 0 3.21 KB
#2455 EnrichedLog netcoreapp3.1 6.38μs 28.8ns 112ns 0.0481 0 0 3.58 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 net472 2.3μs 11.3ns 50.3ns 0.159 0.00111 0 1 KB
master SendReceive netcoreapp3.1 2.05μs 5.28ns 19ns 0.0136 0 0 1 KB
#2455 SendReceive net472 2.27μs 8.64ns 33.5ns 0.158 0 0 1 KB
#2455 SendReceive netcoreapp3.1 2.04μs 11.2ns 63.4ns 0.0139 0 0 1 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 net472 5.82μs 25.3ns 94.8ns 0.288 0 0 1.85 KB
master EnrichedLog netcoreapp3.1 4.93μs 22.2ns 86ns 0.0198 0 0 1.47 KB
#2455 EnrichedLog net472 6.03μs 31.6ns 197ns 0.287 0 0 1.85 KB
#2455 EnrichedLog netcoreapp3.1 5.24μs 25.7ns 173ns 0.0187 0 0 1.47 KB
Benchmarks.Trace.SpanBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net472 944ns 5.4ns 39.3ns 0.0705 0 0 449 B
master StartFinishSpan netcoreapp3.1 863ns 2.78ns 10.8ns 0.00602 0 0 448 B
master StartFinishScope net472 1.05μs 4.99ns 21.2ns 0.0829 0 0 530 B
master StartFinishScope netcoreapp3.1 1.02μs 3.62ns 14ns 0.00756 0 0 568 B
#2455 StartFinishSpan net472 913ns 4.32ns 17.3ns 0.0705 0 0 449 B
#2455 StartFinishSpan netcoreapp3.1 876ns 3.47ns 13.4ns 0.00615 0 0 448 B
#2455 StartFinishScope net472 1.1μs 5.16ns 20ns 0.0831 0 0 530 B
#2455 StartFinishScope netcoreapp3.1 1.1μs 5.11ns 20.4ns 0.00785 0 0 568 B

Comment thread tracer/src/Datadog.Trace/Configuration/ExporterSettings.cs Outdated
Comment thread tracer/src/Datadog.Trace/Configuration/ExporterSettings.cs Outdated
Comment thread tracer/src/Datadog.Trace/Configuration/ExporterSettings.cs Outdated
Comment thread tracer/src/Datadog.Trace/Configuration/ExporterSettings.cs Outdated
Comment thread tracer/test/Datadog.Trace.Tests/Configuration/ExporterSettingsTests.cs Outdated
@pierotibou pierotibou changed the title [WIP] Review Exporter Settings Review Exporter Settings Feb 19, 2022
@pierotibou
pierotibou marked this pull request as ready for review February 19, 2022 00:09
@pierotibou
pierotibou requested a review from a team as a code owner February 19, 2022 00:09
Comment thread tracer/src/Datadog.Trace/Configuration/ExporterSettings.cs Outdated
Comment thread tracer/src/Datadog.Trace/Configuration/ExporterSettings.cs
Add the URL as the first parameter to consider
Change the tests as well to order them by order of precedence
There's one use case that still throws, not sure what to do yet
Adds a builder to do it to keep the object immutable
Changes the tests
Adapted the checkAgentCommand
... by checking default values all the time
Based on the same system as used in DirectLogsSubmissionsSettings
Note that it is a breaking change
it was used only in tests and it doesn't seem we are going further down this road
@lucaspimentel lucaspimentel added the area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) label Apr 5, 2022
Comment thread tracer/src/Datadog.Trace/Configuration/ExporterSettings.cs Outdated
Comment thread tracer/src/Datadog.Trace/Configuration/ExporterSettings.cs
{
if (!Uri.TryCreate(traceAgentUrl, UriKind.RelativeOrAbsolute, out var uri))
{
ValidationWarnings.Add($"The provided Uri: ${traceAgentUrl} provided in '{ConfigurationKeys.AgentUri}' is not valid. It won't be taken into account to send traces.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
ValidationWarnings.Add($"The provided Uri: ${traceAgentUrl} provided in '{ConfigurationKeys.AgentUri}' is not valid. It won't be taken into account to send traces.");
ValidationWarnings.Add($"The Uri '${traceAgentUrl}' provided in '{ConfigurationKeys.AgentUri}' is not valid. It won't be taken into account to send traces.");

var traceAgentUrl = source?.GetString(ConfigurationKeys.AgentUri);
if (!string.IsNullOrWhiteSpace(traceAgentUrl))
{
if (!Uri.TryCreate(traceAgentUrl, UriKind.RelativeOrAbsolute, out var uri))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: could we invert the if here?

public int PartialFlushMinSpans { get; set; }
public string TracesPipeName { get; set; }
public int TracesPipeTimeoutMs { get; set; }
public string TracesUnixDomainSocketPath { get; set; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This shouldn't have gone I don't think 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is correct, TracesUnixDomainSocketPath got removed from ExporterSettings here but it is still present on the ImmutableExporterSettings type if you expand below

@pierotibou pierotibou Apr 13, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was removed intentionally as it had been added only for .NET. (cf PR description)
This is the reason why Lucas rightfully asked me to document these settings (cf https://github.com/DataDog/architecture/pull/1000)

};

var tracerSettings = new TracerSettings(new NameValueConfigurationSource(settings));
var tracerSettings = new ImmutableTracerSettings(new TracerSettings(new NameValueConfigurationSource(settings)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a little on the fence, but I feel like this test belongs in ImmutableExporterSettingsTests since that is where the replacement of localhost occurs

[Fact]
public void Traces_SocketFilesExist_ExplicitTraceAgentPort_UsesDefaultHttp()
{
// AgentPort isn't settable directly, so goinng a config source as a user would

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// AgentPort isn't settable directly, so goinng a config source as a user would
// AgentPort isn't settable directly, so setting via a config source as a user would

var immutableExporterSettings = Setup(FileExistsMock(ExporterSettings.DefaultMetricsUnixDomainSocket), new ExporterSettings());
Assert.Equal(expected: MetricsTransportType.UDS, actual: immutableExporterSettings.MetricsTransport);
Assert.Equal(expected: ExporterSettings.DefaultMetricsUnixDomainSocket, actual: immutableExporterSettings.MetricsUnixDomainSocketPath);
CheckDefaultValues(immutableExporterSettings, "MetricsTransport", "MetricsUnixDomainSocketPath", "DogStatsdPort");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we assert DogStatsdPort to be 0 in this instance?

@zacharycmontoya zacharycmontoya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with some minor comments

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configuration parsing issue with UDS (DD_AGENT_HOST+DD_TRACE_AGENT_URL)

4 participants