-
Notifications
You must be signed in to change notification settings - Fork 399
Streamline ddsketch loading, remove circular dependencies #5008
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
base: master
Are you sure you want to change the base?
Conversation
|
Thank you for updating Change log entry section 👏 Visited at: 2025-11-06 13:31:16 UTC |
Typing analysisThis PR does not change typing compared to the base branch. |
BenchmarksBenchmark execution time: 2025-11-26 01:51:34 Comparing candidate commit 9fc0113 in PR branch Found 1 performance improvements and 0 performance regressions! Performance is the same for 43 metrics, 2 unstable metrics. scenario:tracing - Propagation - Trace Context
|
… but tests still run" This reverts commit 76df349.
…datadog/core/ddsketch
b17d209 to
0d84417
Compare
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage 🔗 Commit SHA: 9fc0113 | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
|
CI is failing due to missing type declaration, I'll add it if there is consensus that this change is the way to go. |
ivoanjo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 So I think this change is fine, but I'm curious -- where is the circular dependency again?
You listed
Removing circular dependency: ddsketch -> core -> configuration -> ddsketch
But... lib/datadog/core/ddsketch.rb did not require anything before, so I'm not sure where the circular dependency again? I played with the master branch before a bit and I could not see any circular require warnings.
Co-authored-by: Ivo Anjo <[email protected]>
|
The technical circular dependency was removed in 43e1f23#diff-6566ed78aec0d0209e0f3b7776e7db57d4694f438d12d3b6b9312f1209bfd994L3, specifically the require of 'datadog/core' from 'datadog/core/ddsketch'. However, 'datadog/core/ddsketch' still references Datadog::Core, but now without the require being present. So, technically, the circular dependency is there, but not in 'require' form at the moment. |
|
Oh, right, I understand. Indeed |
* master: [PROF-13115] Bootstrap installing dependencies on Ruby 4.0.0-preview2 Clarify support for `rb_obj_info` and why it's OK to not have it Tweak pending to not apply to all Ruby preview versions Do not try to use `rb_obj_info` on Ruby 4.0 Adjust stack collector spec to account for changed Ruby 4 behavior [PROF-13115] Disable heap profiling on Ruby 4 preview due to incompatibility Rewrite security response tests
63bf975 to
e474def
Compare
|
I tried to put back in the empty class but this causes issues because it's not supposed to be creatable when the C extension is missing, and trying to fix that took me back to the current state of things before the changes in this PR. I put in the ddsketch.rb so that type checking rake task is happy, and that file only contains a comment about the DDSketch class, but no definition of the class itself. |
| # Datadog::Core::DDSketch is defined completely in the native extension. | ||
| # Do not define it here (for example, as an empty class) because we don't | ||
| # want to be able to create instances of the empty stub class if the | ||
| # native extension is missing or failed to load. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a blocker for this PR if you don't agree with me, but I'm not a fan of this pattern of working really hard not to define the class.
In particular, because I've seen that in profiling, even when classes start as pure-native, they often evolve small Ruby-level helpers that are 200% easier to write in Ruby code instead of writing some gnarly C code "just to avoid adding a Ruby file".
So I think living with the empty definition here is better than just keeping a comment; also because it lets tools such as LSPs know where a class is defined (and then you can read the comment attached to the class that tells you "the rest is in C").
What profiling does in exchange is that the profiling classes are only required if the native extension is loaded successfully and I would suggest adopting the pattern here. Specifically: define the class in this file but make it so it won't exist if the extension isn't loaded. This happens not because the class is not defined in Ruby code but because the Ruby code doesn't get required unless the extension is up and running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to add that core.rb now has knowledge of ddsketch when maybe should not due to its nature of being "general" class/module.
|
CI default configuration does not have libdatadog_api extension, check into using that for the test that ddsketch is missing |
(Dismissing since my approval was based on older versions, and the approach has changed since. As noted in my comment -- my feedback is not blocking either, there's an existing approval already)
What does this PR do?
Changes how ddsketch / libdatadog integration is handled:
Before, there was a
lib/datadog/core/ddsketch.rbfile which contained a class-levelsupported?method. Having this file meant that you could always requiredatadog/core/ddsketch, but you wouldn't always get a functional ddsketch out of that require.The proposed change is to delete this file completely. Loading
datadog/corewill attempt to bring in ddsketch (and this is already behavior in master), therefore no additional require is needed for ddsketch.To check for ddsketch presence, the
supported?method was moved up toDatadog::Coremodule (up fromDatadog::Core::DDSketch). Meaning:Datadog::Core::DDSketchwill be not defined at all.Motivation:
Removing circular dependency: ddsketch -> core -> configuration -> ddsketch
Change log entry
None
Additional Notes:
How to test the change?
Existing CI