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-11045] Fix profiling warnings being really hard to silence #4232

Merged
merged 10 commits into from
Dec 17, 2024

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Dec 17, 2024

What does this PR do?

This PR fixes the report we had in #4231 that the profiling initialization warnings were hard to silence.

In particular, due to the way the profiling component was accessing the dd-trace-rb logger, any configuration changes to change the log level were actually not visible to the profiling component. This issue is now fixed, and enabling profiling + changing the log level in the same Datadog.configure block will be respected.

I also included a few more improvements:

Motivation:

Fixes #4231

Change log entry

Yes. Fix profiling warnings being really hard to silence

Additional Notes:

There's still one case where it's not possible to avoid the warning: when starting profiling via an environment variable (e.g. DD_PROFILING_ENABLED=true bundle exec ddprofrb ruby <somescript>).

This is a result of there not being a way to set the log level of dd-trace-rb via an environment variable. I decided to not tackle this one for now; hopefully the fixes above are enough of an improvement to the status quo ;)

How to test the change?

Here's two sample test cases:

  1. DD_PROFILING_ENABLED=true DD_PROFILING_ALLOCATION_ENABLED=true bundle exec ddprofrb exec ruby -e "Datadog.configure { |c| c.logger.level = Logger::ERROR; c.profiling.enabled = true };"

With this PR prints the "using Ractors may result in allocation profiling stopping" only once, whereas in master it prints it multiple times

  1. DD_PROFILING_ALLOCATION_ENABLED=true bundle exec ruby -e "require 'datadog/auto_instrument'; Datadog.configure { |c| c.logger.level = Logger::ERROR; c.profiling.enabled = true }"

With this PR does not print the message; whereas in master it prints it once.

Since most folks are not using ractors, this is more of a "FYI/BTW".

Also, I've slightly tweaked the text to reduce the overall string,
while keeping the same info.
Receiving the logger as argument means that we'll use the latest logger
configured via `Datadog.configure`; in contrast with using the
`Datadog.logger` directly, since during components initialization
the **older/fallback** logger gets used, which won't reflect any
settings given.

The distinction is subtle but important: consider the case of setting
log level. Prior to this PR, the log level got ignored by the
`Profiling::Component` since the old/fallback logger usually did
not pick itt up.

After this PR, enabling profiling and changing the log level in
the same `Datadog.configure` block will produce the expected effect
of Profiling::Component respecting that log level.
We had left these TODOs a while ago and since I'm cleaning up a number
of logging-related things in the profiling component, I decided to go
ahead and clear these ones as well.
This makes sure these information messages, when printed, are not
printed more than once.

I considered what to do with the warning messages as well, but since
having individual OnlyOnce instances is quite a bit of boilerplate
for the number of warnings we are emitting, I decided to target only
this one for now.
@ivoanjo ivoanjo requested review from a team as code owners December 17, 2024 12:18
@github-actions github-actions bot added core Involves Datadog core libraries profiling Involves Datadog profiling labels Dec 17, 2024
@ivoanjo ivoanjo added bug Involves a bug and removed core Involves Datadog core libraries labels Dec 17, 2024
@datadog-datadog-prod-us1
Copy link
Contributor

datadog-datadog-prod-us1 bot commented Dec 17, 2024

Datadog Report

Branch report: ivoanjo/prof-11045-fix-profiling-logging
Commit report: 12ca619
Test service: dd-trace-rb

✅ 0 Failed, 22311 Passed, 1476 Skipped, 5m 35.67s Total Time

@ivoanjo
Copy link
Member Author

ivoanjo commented Dec 17, 2024

⌛ 5 Performance Regressions

These regressions are false positives, I'll see what I can do about updating our config to correct this.

@pr-commenter
Copy link

pr-commenter bot commented Dec 17, 2024

Benchmarks

Benchmark execution time: 2024-12-17 14:38:21

Comparing candidate commit 12ca619 in PR branch ivoanjo/prof-11045-fix-profiling-logging with baseline commit be1c39a in branch master.

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

@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.75%. Comparing base (be1c39a) to head (12ca619).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4232   +/-   ##
=======================================
  Coverage   97.75%   97.75%           
=======================================
  Files        1355     1355           
  Lines       82145    82149    +4     
  Branches     4216     4216           
=======================================
+ Hits        80301    80305    +4     
  Misses       1844     1844           

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

@github-actions github-actions bot added the core Involves Datadog core libraries label Dec 17, 2024
@ivoanjo ivoanjo merged commit 61ca49f into master Dec 17, 2024
337 of 338 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/prof-11045-fix-profiling-logging branch December 17, 2024 16:31
@github-actions github-actions bot added this to the 2.9.0 milestone Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Involves a bug core Involves Datadog core libraries profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

i cannot stop this message: "WARN -- datadog: [datadog] In all known versions of Ruby 3.x]...
3 participants