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

fix: ensure uds always takes precedence over http if both configurations are defined #4024

Merged

Conversation

mabdinur
Copy link
Contributor

@mabdinur mabdinur commented Oct 24, 2024

What does this PR do?

Ensures uds configurations are parsed in a manner that is consistent with other libraries.

Motivation:

  • Ensures DD_TRACE_AGENT_URL is applied in a consistent manner.

Change log entry

Additional Notes:

How to test the change?

@mabdinur mabdinur marked this pull request as ready for review October 24, 2024 15:46
@mabdinur mabdinur requested a review from a team as a code owner October 24, 2024 15:46
@pr-commenter
Copy link

pr-commenter bot commented Oct 24, 2024

Benchmarks

Benchmark execution time: 2024-11-01 14:15:42

Comparing candidate commit 09b6274 in PR branch munir/uds-should-take-precedence-over-http-if-both-defined with baseline commit d361376 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 29 metrics, 2 unstable metrics.

Comment on lines 235 to 238
can_use_uds? && !mixed_http_and_uds?
# When we have mixed settings for http/https and uds, we print a warning
# and use the uds settings.
unless defined?(@mixed_http_and_uds)
@mixed_http_and_uds = (configured_hostname || configured_port) && can_use_uds?
if @mixed_http_and_uds
warn_if_configuration_mismatch(
[
DetectedConfiguration.new(
friendly_name: 'configuration for unix domain socket',
value: parsed_url.to_s,
),
DetectedConfiguration.new(
friendly_name: 'configuration of hostname/port for http/https use',
value: "hostname: '#{hostname}', port: '#{port}'",
),
]
)
end
end
can_use_uds?
Copy link
Contributor

Choose a reason for hiding this comment

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

With these changes we violate SRP. Question-mark methods doesn't suppose to set any variables, but provide only true/false checks.

Solution: Rename existing method mixed_http_and_uds? into mixed_http_and_uds and adjust should_use_uds? accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

The variable being set is just a cache for the value being returned or am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

Memoizing values plays an important part when combined with the warnings: it means we don't repeat warnings just because some helper function queried the same info again.

@ivoanjo
Copy link
Member

ivoanjo commented Oct 25, 2024

Thanks for picking this up! I assume from

Ensures uds configurations are parsed in a manner that is consistent with other libraries.

That other dd libraries behave in the way we're changing Ruby to adhere to.

Do you mind if I ask for some references? Is there perhaps a system-test for this that we can use to ensure we don't regress across libraries?

@mabdinur
Copy link
Contributor Author

Thanks for picking this up! I assume from

Ensures uds configurations are parsed in a manner that is consistent with other libraries.

That other dd libraries behave in the way we're changing Ruby to adhere to.

Do you mind if I ask for some references? Is there perhaps a system-test for this that we can use to ensure we don't regress across libraries?

We have this system-test: https://github.com/DataDog/system-tests/blob/5e90616079fc11656348026f5f771aea8bafa748/tests/parametric/test_config_consistency.py#L145.

@mabdinur mabdinur requested a review from Strech October 25, 2024 17:18
@ivoanjo
Copy link
Member

ivoanjo commented Oct 28, 2024

Copy link
Contributor

@Strech Strech left a comment

Choose a reason for hiding this comment

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

I think it's LGTM if we fix reader method to return value.

lib/datadog/core/configuration/agent_settings_resolver.rb Outdated Show resolved Hide resolved
@github-actions github-actions bot added the core Involves Datadog core libraries label Nov 1, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.71%. Comparing base (922d8ff) to head (14480fe).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4024   +/-   ##
=======================================
  Coverage   97.71%   97.71%           
=======================================
  Files        1338     1338           
  Lines       80248    80249    +1     
  Branches     4016     4016           
=======================================
+ Hits        78418    78419    +1     
  Misses       1830     1830           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TonyCTHsu TonyCTHsu force-pushed the munir/uds-should-take-precedence-over-http-if-both-defined branch from 14480fe to ebaa0bf Compare November 1, 2024 14:45
@TonyCTHsu TonyCTHsu merged commit 51446c7 into master Nov 1, 2024
219 of 231 checks passed
@TonyCTHsu TonyCTHsu deleted the munir/uds-should-take-precedence-over-http-if-both-defined branch November 1, 2024 14:54
@github-actions github-actions bot added this to the 2.5.0 milestone Nov 1, 2024
@Strech Strech mentioned this pull request Nov 5, 2024
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.

7 participants