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

[PROF-6900] Fix wrong libdatadog version being picked during profiler build #2531

Merged
merged 3 commits into from
Jan 13, 2023

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Jan 10, 2023

What does this PR do?:

This PR fixes an issue I spotted recently relating to the libdatadog version that gets picked during profiler build.

Specifically, I had the following setup:

  • Two versions of the libdatadog gem locally installed (1.0.1.1.0, 0.9.0.1.0)
  • I tried to install ddtrace 1.8.0 from rubygems

The ddtrace 1.8.0 release has a dependency on libdatadog 0.9.x.

But, what I observed is that building the profiler (and thus installing ddtrace) failed because the profiling native extension was trying to compile and link to libdatadog 1.0.x instead of 0.9.x.

Upon investigation, I've discovered that the issue is that the extconf.rb script (which gets called by rubygems during installation) is not run with the equivalent of bundle exec, e.g. it can access all gems (and versions) that are installed locally, not just the ones that are defined in the dependencies of our gem in the gemspec.

Thus, at least on my machine, when we did require 'libdatadog' to access the libdatadog gem, rubygems picked a version which did not match the one that was stated in the gemspec.

To fix this, I've modified the native_extension_helpers.rb (which gets called by the extconf.rb) to tell RubyGems to activate the exact version of libdatadog that we need.

Additionally, I've added error handling so we gracefully recover from any errors that can happen on this step.

Motivation:

Avoid impacting customers that are installing ddtrace (and avoid having them endup having to disable profiling to install ddtrace).

Additional Notes:

Hopefully no customers ever got bitten by this (we had no reports thus far). To reproduce this, they'd need to have a weird combination of having a more modern version of libdatadog than they needed, and then install an older version of ddtrace.

How to test the change?:

See instructions above for the setup I had that triggered this issue. You'll have to check out the exact commit where the fix happened, because then I had to merge master into this branch, and master brought in support for the latest libdatadog, which will make the issue not trigger again until there's a newer version of libdatadog out there.

The `REPORT_ISSUE` string is somewhat specific to the error that was
using it, because it mentions "if you needed to use this", where this
is the env var to disable building the native extension.

So to avoid confusion, I decided to inline it on the check it belongs
to.
… build

**What does this PR do?**:

This PR fixes an issue I spotted recently relating to the libdatadog
version that gets picked during profiler build.

Specifically, I had the following setup:

* Two versions of the libdatadog gem locally installed
  (1.0.1.1.0, 0.9.0.1.0)
* I tried to install ddtrace 1.8.0 from rubygems

The ddtrace 1.8.0 release has a dependency on libdatadog 0.9.x.

But, what I observed is that building the profiler (and thus installing
ddtrace) failed because the profiling native extension was trying to
compile and link to libdatadog 1.0.x instead of 0.9.x.

Upon investigation, I've discovered that the issue is that the
`extconf.rb` script (which gets called by rubygems during installation)
is not run with the equivalent of `bundle exec`, e.g. it can access all
gems (and versions) that are installed locally, not just the ones that
are defined in the dependencies of our gem in the `gemspec`.

Thus, at least on my machine, when we did `require 'libdatadog'`
to access the `libdatadog` gem, rubygems picked a version which did
not match the one that was stated in the `gemspec`.

To fix this, I've modified the `native_extension_helpers.rb`
(which gets called by the `extconf.rb`) to tell RubyGems to activate
the exact version of `libdatadog` that we need.

Additionally, I've added error handling so we gracefully recover
from any errors that can happen on this step.

**Motivation**:

Avoid impacting customers that are installing ddtrace (and avoid
having them endup having to disable profiling to install ddtrace).

**Additional Notes**:

Hopefully no customers ever got bitten by this (we had no reports thus
far). To reproduce this, they'd need to have a weird combination of
having a more modern version of libdatadog than they needed, and then
install an older version of ddtrace.

**How to test the change?**:

See instructions above for the setup I had that triggered this
issue.
@ivoanjo ivoanjo requested a review from a team January 10, 2023 10:21
@github-actions github-actions bot added the profiling Involves Datadog profiling label Jan 10, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #2531 (c37d946) into master (b31c5dc) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2531   +/-   ##
=======================================
  Coverage   98.03%   98.03%           
=======================================
  Files        1124     1124           
  Lines       60660    60686   +26     
  Branches     2767     2767           
=======================================
+ Hits        59466    59494   +28     
+ Misses       1194     1192    -2     
Impacted Files Coverage Δ
spec/datadog/profiling/http_transport_spec.rb 99.14% <ø> (ø)
...iling_native_extension/native_extension_helpers.rb 96.73% <100.00%> (+0.53%) ⬆️
...datadog/profiling/native_extension_helpers_spec.rb 97.69% <100.00%> (+0.27%) ⬆️
lib/datadog/core/diagnostics/environment_logger.rb 97.63% <0.00%> (-0.82%) ⬇️
...ng/contrib/active_support/cache/instrumentation.rb 86.30% <0.00%> (+0.09%) ⬆️
spec/datadog/profiling/native_extension_spec.rb 98.74% <0.00%> (+0.62%) ⬆️
lib/datadog/core/workers/polling.rb 100.00% <0.00%> (+3.44%) ⬆️
...ec/datadog/tracing/contrib/sidekiq/patcher_spec.rb 100.00% <0.00%> (+4.00%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ivoanjo ivoanjo merged commit 5e4e38e into master Jan 13, 2023
@ivoanjo ivoanjo deleted the ivoanjo/prof-6900-issue-libdatadog-version branch January 13, 2023 14:47
@github-actions github-actions bot added this to the 1.9.0 milestone Jan 13, 2023
@TonyCTHsu TonyCTHsu mentioned this pull request Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants