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

Add support for Unix Domain Socket (UDS) configuration via DD_TRACE_AGENT_URL #2806

Merged
merged 3 commits into from
Apr 26, 2023

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Apr 21, 2023

What does this PR do?:

This PR extends the AgentSettingsResolver to allow the DD_TRACE_AGENT_URL to contain a Unix Domain Socket (UDS) configuration string, for instance unix:///some/path/to/the/apm.socket.

It also adds a warning if there's configuration for both http and unix domain socket (and in that case it will prioritize the http variant).

Motivation:

This was missing for feature parity with other Datadog client libraries, and it was annoying a lot of customers in #1967 (thanks for the patience, folks!).

Additional Notes:

The change is quite small because dd-trace-rb already supported using unix domain sockets -- you just couldn't configure them via this environment variable. Thus, the only thing that changed was parsing it correctly.

How to test the change?:

Configure an agent with a uds socket and report data through it.

Fixes #1967

…AGENT_URL`

**What does this PR do?**:

This PR extends the `AgentSettingsResolver` to allow the
`DD_TRACE_AGENT_URL` to contain a Unix Domain Socket (UDS) configuration
string, for instance `unix:///some/path/to/the/apm.socket`.

It also adds a warning if there's configuration for both http and
unix domain socket (and in that case it will prioritize the http
variant).

**Motivation**:

This was missing for feature parity with other Datadog client libraries,
and it was annoying a lot of customers in #1967 (thanks for the
patience, folks!).

**Additional Notes**:

The change is quite small because dd-trace-rb already supported using
unix domain sockets -- you just couldn't configure them via this
environment variable. Thus, the only thing that changed was parsing it
correctly.

**How to test the change?**:

Configure an agent with a uds socket and report data through it.

Fixes #1967
@ivoanjo ivoanjo requested a review from a team April 21, 2023 13:33
@github-actions github-actions bot added the core Involves Datadog core libraries label Apr 21, 2023
Copy link
Member

@GustavoCaso GustavoCaso left a comment

Choose a reason for hiding this comment

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

LGTM

@ivoanjo ivoanjo added the do-not-merge/WIP Not ready for merge label Apr 25, 2023
@ivoanjo
Copy link
Member Author

ivoanjo commented Apr 25, 2023

Hey! I found a tiny tiny bug that wouldn't even impact customers at this point but I want to fix it and add test coverage for it before merging this PR, so I've marked this as do not merge :)

@ivoanjo ivoanjo removed the do-not-merge/WIP Not ready for merge label Apr 25, 2023
@ivoanjo
Copy link
Member Author

ivoanjo commented Apr 25, 2023

Tiny bug fixed in e7680ed

@ivoanjo
Copy link
Member Author

ivoanjo commented Apr 26, 2023

Thanks y'all for the reviews, merging away!

@ivoanjo ivoanjo merged commit 1b79b66 into master Apr 26, 2023
107 of 123 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/support-uds-via-env branch April 26, 2023 08:11
@github-actions github-actions bot added this to the 1.11.0 milestone Apr 26, 2023
ivoanjo added a commit that referenced this pull request Aug 9, 2023
…figuration

**What does this PR do?**:

This PR fixes a corner case bug introduced in #2806 when we added
support for configuration unix domain socket (UDS) via the
`DD_TRACE_AGENT_URL` environment variable.

Specifically, when a mix of http and uds configuration was specified,
we printed a warning and used the http configuration instead.

But, if only the hostname or only the port + uds configuration was
provided, we did not correctly use the default hostname and default
port as a replacement.

That is:

* `DD_AGENT_HOST=10.128.186.61 DD_TRACE_AGENT_URL=unix:///var/run/datadog/apm.socket`
  resulted in `hostname="10.128.186.61", port=nil`
* `DD_TRACE_AGENT_PORT=1234 DD_TRACE_AGENT_URL=unix:///var/run/datadog/apm.socket`
  resulted in `hostname=nil, port=1234`

This led to a failure to communicate with the Datadog agent in
these situations.

**Motivation**:

Fix issue when communicating with the agent.

**Additional Notes**:

We caught this issue while testing internal apps. On the plus side,
we did not get any customer reports for this issue, so hopefully
nobody was bitten by it.

**How to test the change?**:

Change includes test coverage. You can also compare the output of
the `AgentSettingsResolver` before/after the issue was fixed:

```
 # Before
$ DD_AGENT_HOST=10.128.186.61 DD_TRACE_AGENT_URL=unix:///var/run/datadog/apm.socket bundle exec ruby -e "require 'ddtrace'; pp(Datadog::Core::Configuration::AgentSettingsResolver.call(Datadog.configuration))"
 #<struct Datadog::Core::Configuration::AgentSettingsResolver::AgentSettings
 adapter=:net_http,
 ssl=false,
 hostname="10.128.186.61",
 port=nil,
 uds_path=nil,
 timeout_seconds=nil,
 deprecated_for_removal_transport_configuration_proc=nil>
$ DD_TRACE_AGENT_PORT=1234 DD_TRACE_AGENT_URL=unix:///var/run/datadog/apm.socket bundle exec ruby -e "require 'ddtrace'; pp(Datadog::Core::Configuration::AgentSettingsResolver.call(Datadog.configuration))"
 #<struct Datadog::Core::Configuration::AgentSettingsResolver::AgentSettings
 adapter=:net_http,
 ssl=false,
 hostname=nil,
 port=1234,
 uds_path=nil,
 timeout_seconds=nil,
 deprecated_for_removal_transport_configuration_proc=nil>

 # After
$ DD_AGENT_HOST=10.128.186.61 DD_TRACE_AGENT_URL=unix:///var/run/datadog/apm.socket bundle exec ruby -e "require 'ddtrace'; pp(Datadog::Core::Configuration::AgentSettingsResolver.call(Datadog.configuration))"
 #<struct Datadog::Core::Configuration::AgentSettingsResolver::AgentSettings
 adapter=:net_http,
 ssl=false,
 hostname="10.128.186.61",
 port=8126,
 uds_path=nil,
 timeout_seconds=nil,
 deprecated_for_removal_transport_configuration_proc=nil>
$ DD_TRACE_AGENT_PORT=1234 DD_TRACE_AGENT_URL=unix:///var/run/datadog/apm.socket bundle exec ruby -e "require 'ddtrace'; pp(Datadog::Core::Configuration::AgentSettingsResolver.call(Datadog.configuration))"
 #<struct Datadog::Core::Configuration::AgentSettingsResolver::AgentSettings
 adapter=:net_http,
 ssl=false,
 hostname="127.0.0.1",
 port=1234,
 uds_path=nil,
 timeout_seconds=nil,
 deprecated_for_removal_transport_configuration_proc=nil>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing support for Unix Domain Socket configuration via DD_TRACE_AGENT_URL
4 participants