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-5748] Improve error message when pkg-config tool is not installed #2134

Merged
merged 1 commit into from
Jul 8, 2022

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Jul 7, 2022

What does this PR do?

Add a better error message to be presented to customers when pkg-config is not installed. (See below for example)

Motivation

In #2068 a customer reported that they were not getting profiling with the message:

Profiling was requested but is not supported, profiling disabled: Your ddtrace installation is missing support for the Continuous Profiler because there was a problem in setting up the libddprof dependency.

After investigating this issue (and adding extra tools to debug it, see #2069) it turns out that the customer was missing the pkg-config tool.

This tool is currently invoked indirectly via Ruby's mkmf helper, and is used to configure linking to libddprof/libdatadog.

I must admit I was surprised that there's not better error logging in mkmf when the pkg-config tool is actually missing (vs it being installed but returning an error when being called).

Thus, to hopefully avoid other customers running into this issue, I've added a bit of code to detect it, and hopefully present a better error message in that situation.

I've also learned that pkg-config is "old news" on some Linux distributions, and instead they ship something called pkgconf which is a reimplementation of pkg-config.

Additional Notes

How to test the change?

Beyond the RSpec tests, this can be triggered for testing by:

  1. Changing the pkg_config call on extconf.rb
-unless pkg_config('ddprof_ffi_with_rpath')
+unless pkg_config('ddprof_ffi_with_rpath_broken')

which triggers the generic message (because pkg-config is available but returns an error since the configuration file is not found):

+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| there was a problem in setting up the `libddprof` dependency.                |
|                                                                              |
| The Datadog Continuous Profiler will not be available,                       |
| but all other ddtrace features will work fine!                               |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+
  1. Crippling pkg_config:
$ docker-compose run --no-deps --rm tracer-2.1 /bin/bash
  # doing this inside docker is fine because it doesn't persist
$ rm /usr/bin/pkg-config
$ bundle exec rake clean compile
 # ...
+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| the `pkg-config` system tool is missing.                                     |
| This issue can usually be fixed by installing:                               |
| 1. the `pkg-config` package on Homebrew and Debian/Ubuntu-based Linux;       |
| 2. the `pkgconf` package on Arch and Alpine-based Linux;                     |
| 3. the `pkgconf-pkg-config` package on Fedora/Red Hat-based Linux.           |
|                                                                              |
| The Datadog Continuous Profiler will not be available,                       |
| but all other ddtrace features will work fine!                               |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+

Closes #2068

In #2068 a customer reported that they were not getting profiling
with the message:

> Profiling was requested but is not supported, profiling disabled:
> Your ddtrace installation is missing support for the Continuous
> Profiler because there was a problem in setting up the libddprof
> dependency.

After investigating this issue (and adding extra tools to debug it,
see #2069) it turns out that the customer was missing the `pkg-config`
tool.

This tool is currently invoked indirectly via Ruby's `mkmf` helper,
and is used to configure linking to libddprof/libdatadog.

I must admit I was surprised that there's not better error logging
in `mkmf` when the `pkg-config` tool is actually missing
(vs it being installed but returning an error when being called).

Thus, to hopefully avoid other customers running into this issue,
I've added a bit of code to detect it, and hopefully present a
better error message in that situation.

I've also learned that `pkg-config` is "old news" on some Linux
distributions, and instead they ship something called `pkgconf`
which is a reimplementation of `pkg-config`.

Beyond the RSpec tests, this can be triggered for testing by:

1. Changing the `pkg_config` call on extconf.rb

```diff
-unless pkg_config('ddprof_ffi_with_rpath')
+unless pkg_config('ddprof_ffi_with_rpath_broken')
```

which triggers the generic message (because pkg-config is
available but returns an error since the configuration file
is not found):

```
+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| there was a problem in setting up the `libddprof` dependency.                |
|                                                                              |
| The Datadog Continuous Profiler will not be available,                       |
| but all other ddtrace features will work fine!                               |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+
```

2. Crippling `pkg_config`:

```bash
$ docker-compose run --no-deps --rm tracer-2.1 /bin/bash
  # doing this inside docker is fine because it doesn't persist
$ rm /usr/bin/pkg-config
$ bundle exec rake clean compile
 # ...
+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| the `pkg-config` system tool is missing.                                     |
| This issue can usually be fixed by installing:                               |
| 1. the `pkg-config` package on Homebrew and Debian/Ubuntu-based Linux;       |
| 2. the `pkgconf` package on Arch and Alpine-based Linux;                     |
| 3. the `pkgconf-pkg-config` package on Fedora/Red Hat-based Linux.           |
|                                                                              |
| The Datadog Continuous Profiler will not be available,                       |
| but all other ddtrace features will work fine!                               |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+
```

Closes #2068
@ivoanjo ivoanjo requested a review from a team July 7, 2022 09:27
@codecov-commenter
Copy link

Codecov Report

Merging #2134 (c623405) into master (96c395d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2134   +/-   ##
=======================================
  Coverage   97.53%   97.53%           
=======================================
  Files        1040     1040           
  Lines       53871    53894   +23     
=======================================
+ Hits        52542    52566   +24     
+ Misses       1329     1328    -1     
Impacted Files Coverage Δ
...iling_native_extension/native_extension_helpers.rb 95.89% <100.00%> (+0.23%) ⬆️
...datadog/profiling/native_extension_helpers_spec.rb 98.19% <100.00%> (+0.32%) ⬆️
spec/datadog/profiling/ext/forking_spec.rb 99.39% <0.00%> (-0.61%) ⬇️
lib/datadog/core/diagnostics/environment_logger.rb 100.00% <0.00%> (+1.58%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@ivoanjo ivoanjo merged commit 5b50fdc into master Jul 8, 2022
@ivoanjo ivoanjo deleted the ivoanjo/prof-5748-handle-missing-pkgconfig branch July 8, 2022 07:32
@github-actions github-actions bot added this to the 1.2.0 milestone Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate "Profiler disabled because there was a problem in setting up the libddprof dependency"
3 participants