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

DEBUG-2334 dynamic instrumentation instrumenter component #4012

Merged
merged 28 commits into from
Oct 30, 2024

Conversation

p-datadog
Copy link
Member

@p-datadog p-datadog commented Oct 17, 2024

Change log entry

None, DI is not yet customer-visible.

What does this PR do?

This component instruments target code, meaning when target method or target line is invoked, the specified callback will be called with information about the program state at the target point (e.g. method parameters for method probe, local variables for line probe).

Motivation:
Initial implementation of Ruby dynamic instrumentation.

Additional Notes:
The instrumenter itself is under 300 lines. Most of the diff is in the test suite.

How to test the change?
This PR includes unit tests, but a large part of instrumentation is dealing with code that is loaded after the instrumentation is installed (since much Ruby code is lazily loaded) and test coverage for this will be added later since it requires more DI components.

Unsure? Have a question? Request a review!

This component instruments target code, meaning when
target method or target line is invoked, the specified
callback will be called with information about the
program state at the target point (e.g. method parameters
for method probe, local variables for line probe).
@p-datadog p-datadog requested a review from a team as a code owner October 17, 2024 18:48
spec/datadog/di/instrumenter_spec.rb Show resolved Hide resolved
spec/datadog/di/hook_line_recursive.rb Show resolved Hide resolved
spec/datadog/di/instrumenter_spec.rb Outdated Show resolved Hide resolved
spec/datadog/di/instrumenter_spec.rb Outdated Show resolved Hide resolved
spec/datadog/di/instrumenter_spec.rb Outdated Show resolved Hide resolved
lib/datadog/di/instrumenter.rb Show resolved Hide resolved
lib/datadog/di/utils.rb Show resolved Hide resolved
spec/datadog/di/instrumenter_spec.rb Show resolved Hide resolved
spec/datadog/di/hook_method.rb Show resolved Hide resolved
spec/datadog/di/instrumenter_spec.rb Show resolved Hide resolved
p-datadog and others added 3 commits October 17, 2024 14:51
Co-authored-by: datadog-datadog-prod-us1[bot] <88084959+datadog-datadog-prod-us1[bot]@users.noreply.github.com>
Co-authored-by: datadog-datadog-prod-us1[bot] <88084959+datadog-datadog-prod-us1[bot]@users.noreply.github.com>
Co-authored-by: datadog-datadog-prod-us1[bot] <88084959+datadog-datadog-prod-us1[bot]@users.noreply.github.com>
@pr-commenter
Copy link

pr-commenter bot commented Oct 17, 2024

Benchmarks

Benchmark execution time: 2024-10-17 20:01:02

Comparing candidate commit f904292 in PR branch di-instrumenter with baseline commit 60febf8 in branch master.

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

scenario:profiler - sample timeline=false

  • 🟥 throughput [-0.637op/s; -0.619op/s] or [-9.385%; -9.119%]

@p-datadog
Copy link
Member Author

This PR has some xit tests, I am planning on reviewing them to either make them work or delete them from the tree.

@codecov-commenter
Copy link

codecov-commenter commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 92.33716% with 40 lines in your changes missing coverage. Please review.

Project coverage is 97.79%. Comparing base (e8ef953) to head (8ef0a12).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
lib/datadog/di/instrumenter.rb 83.49% 17 Missing ⚠️
spec/datadog/di/instrumenter_spec.rb 96.29% 12 Missing ⚠️
lib/datadog/di/probe.rb 57.14% 3 Missing ⚠️
lib/datadog/di.rb 87.50% 2 Missing ⚠️
spec/datadog/di/hook_line.rb 80.00% 1 Missing ⚠️
spec/datadog/di/hook_line_basic.rb 80.00% 1 Missing ⚠️
spec/datadog/di/hook_line_load.rb 80.00% 1 Missing ⚠️
spec/datadog/di/hook_line_recursive.rb 88.88% 1 Missing ⚠️
spec/datadog/di/hook_line_targeted.rb 80.00% 1 Missing ⚠️
spec/datadog/di/hook_method.rb 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4012      +/-   ##
==========================================
- Coverage   97.82%   97.79%   -0.04%     
==========================================
  Files        1327     1337      +10     
  Lines       79698    80212     +514     
  Branches     3952     4013      +61     
==========================================
+ Hits        77968    78441     +473     
- Misses       1730     1771      +41     

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

@p-datadog p-datadog added the dev/internal Other internal work that does not need to be included in the changelog label Oct 18, 2024
Copy link
Member

@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 have a few minor notes regarding code checker variable, but despite that 🟢

lib/datadog/di.rb Show resolved Hide resolved
lib/datadog/di/utils.rb Show resolved Hide resolved
sig/datadog/di.rbs Show resolved Hide resolved
lib/datadog/di.rb Outdated Show resolved Hide resolved
Comment on lines +106 to +108
duration = Benchmark.realtime do # steep:ignore
rv = super(*args, **kwargs)
end
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is delegation is correct -- there may be corner cases with args/keyword args; see https://eregon.me/blog/2019/11/10/the-delegation-challenge-of-ruby27.html for details. I think this is a quite sensitive part since getting it wrong means installing a probe can break the app.

(Also @lloeki quite likes this topic so I think he's the person to ping for a quick check on this bit ;D )

Copy link
Member Author

Choose a reason for hiding this comment

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

This is one of my items to address before initial release, but the "shortcut" is I can just mandate Ruby 3.0+ for DI if this problem is difficult to solve.

p-datadog and others added 2 commits October 29, 2024 09:05
Co-authored-by: Ivo Anjo <ivo.anjo@datadoghq.com>
@p-datadog p-datadog force-pushed the di-instrumenter branch 3 times, most recently from 2b6eed6 to 9cb5206 Compare October 29, 2024 15:35
The DI code being benchmarked does not exist in master,
making the baseline benchmark run fail.
I will extract it into a separate PR.
@p-datadog p-datadog merged commit fe0c0f2 into master Oct 30, 2024
269 of 270 checks passed
@p-datadog p-datadog deleted the di-instrumenter branch October 30, 2024 13:04
@github-actions github-actions bot added this to the 2.5.0 milestone Oct 30, 2024
p-datadog pushed a commit that referenced this pull request Oct 30, 2024
These contain code for line probes and method probes,
only method probes are currently enabled becuase more DI code
is needed to have line probes work.
p-datadog added a commit that referenced this pull request Oct 30, 2024
These contain code for line probes and method probes,
only method probes are currently enabled becuase more DI code
is needed to have line probes work.

Co-authored-by: Oleg Pudeyev <code@olegp.name>
p-datadog pushed a commit to p-datadog/dd-trace-rb that referenced this pull request Nov 1, 2024
* master: (25 commits)
  lint
  update method
  fix unix path regex
  add back mixed_http_and_uds
  fix test
  update tests to match this new world order
  use uds
  Fix Intel case
  Purge circleci cache
  Udpate ffi to 1.17 for gemfiles/*lock
  Pin version across rubies
  Fix labeler
  Pin bundler version
  Improve naming for persistent_data arg for appsec waf
  [🤖] Lock Dependency: https://github.com/DataDog/dd-trace-rb/actions/runs/11611017851
  Update libddwaf gem to v1.15.0.0.0
  Add musl keys
  Reduce requirement to 2.27
  Implement requirement.json
  DEBUG-2334 DI benchmarks extracted from DataDog#4012 (DataDog#4049)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev/internal Other internal work that does not need to be included in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants