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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lazy option from the configuration option #2931

Merged
merged 6 commits into from
Jul 6, 2023

Conversation

GustavoCaso
Copy link
Member

@GustavoCaso GustavoCaso commented Jun 26, 2023

What does this PR do?

This PR removes the lazy option in favour of checking the content of default.

These changes are part of an internal discussion of the ruby team 馃槃

Motivation

The lazy option is superfluous, the check to either evaluate default as a block or a static value could be achieved by checking the type of value default is. default.is_a?(Proc)

There is an edge case:
The default value is a block.

When we provide a block to default and do not specify it as lazy, we store the block as the default value. I added a new option, experimental_default_proc, to circumvent that edge case. Pushing us to be more explicit about those edge cases makes the code more readable and easier to grok.

Since this new option is experimental and we might not need it in the near future, I gave it a name that it clear to the reader that they should not rely on it and that is subject to change.

I added a deprecation warning to lazy, so if anyone is using the core code to build their settings, they can migrate to the new system.

Additional Notes

How to test the change?

CI

@github-actions github-actions bot added ci-app CI product for test suite instrumentation core Involves Datadog core libraries integrations Involves tracing integrations tracing labels Jun 26, 2023
@GustavoCaso GustavoCaso changed the title WIP Remove lazy option from the configuration options Jun 26, 2023
@GustavoCaso GustavoCaso force-pushed the core-configuration-remove-lazy branch 2 times, most recently from 3eb2a14 to 569713b Compare June 26, 2023 16:05
@codecov-commenter
Copy link

Codecov Report

Merging #2931 (569713b) into master (0e396e9) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           master    #2931    +/-   ##
========================================
  Coverage   97.95%   97.95%            
========================================
  Files        1282     1282            
  Lines       70682    70438   -244     
  Branches     3250     3247     -3     
========================================
- Hits        69236    68997   -239     
+ Misses       1446     1441     -5     
Impacted Files Coverage 螖
lib/datadog/ci/configuration/settings.rb 100.00% <酶> (酶)
lib/datadog/core/configuration/base.rb 97.95% <酶> (-0.05%) 猬囷笍
...ib/datadog/core/configuration/option_definition.rb 100.00% <酶> (酶)
lib/datadog/tracing/configuration/settings.rb 94.11% <酶> (-0.93%) 猬囷笍
...ing/contrib/action_cable/configuration/settings.rb 100.00% <酶> (酶)
...ng/contrib/action_mailer/configuration/settings.rb 100.00% <酶> (酶)
...cing/contrib/action_pack/configuration/settings.rb 95.45% <酶> (-0.55%) 猬囷笍
...cing/contrib/action_view/configuration/settings.rb 100.00% <酶> (酶)
...active_model_serializers/configuration/settings.rb 100.00% <酶> (酶)
...ng/contrib/active_record/configuration/settings.rb 100.00% <酶> (酶)
... and 48 more

... and 2 files with indirect coverage changes

馃摚 We鈥檙e building smart automated test selection to slash your CI/CD build times. Learn more

@marcotc
Copy link
Member

marcotc commented Jun 26, 2023

馃憢 @GustavoCaso, why is lazy being removed?

@GustavoCaso GustavoCaso force-pushed the core-configuration-remove-lazy branch from 569713b to 22107ae Compare June 27, 2023 08:56
@GustavoCaso
Copy link
Member Author

@marcotc I am preparing an RFC to reduce some of the complexity of our core configuration code and options. By any means, this is something we have to do, I instead want the guild to agree, but for the cases of the lazy option, I wanted to have an example PR for everyone to have a look at.

@GustavoCaso GustavoCaso changed the title Remove lazy option from the configuration options [EXPERIMENTAL] Remove lazy option from the configuration options Jun 27, 2023
@GustavoCaso GustavoCaso force-pushed the core-configuration-remove-lazy branch 2 times, most recently from 32988eb to f54d36f Compare June 30, 2023 09:53
@GustavoCaso GustavoCaso changed the title [EXPERIMENTAL] Remove lazy option from the configuration options Remove lazy option from the configuration option Jun 30, 2023
@GustavoCaso GustavoCaso force-pushed the core-configuration-remove-lazy branch from f54d36f to cc61167 Compare June 30, 2023 10:07
@github-actions github-actions bot added the appsec Application Security monitoring product label Jun 30, 2023
@GustavoCaso GustavoCaso marked this pull request as ready for review June 30, 2023 10:16
@GustavoCaso GustavoCaso requested a review from a team June 30, 2023 10:16
@lloeki
Copy link
Contributor

lloeki commented Jun 30, 2023

In my mind lazy referred to when a proc (or callable, really) is evaluated:

  • default may be a callable
  • some settings may allow callables to be set as values (IIRC there's transport)

lazy decides whether these are evaluated upon the setting being set or upon the setting being called once.

So:

  • I don't really see a solid argument for a callable being evaluated upon being set (except maybe if there are settings that should store a callable that is not meant to be called to resolve to the setting value i.e if the callable is itself the value)
  • if a non-callable is set then by definition the value is evaluated right away

If we hold the above as true then it looks like lazy is indeed superfluous as we can check for respond_to?(:call).

Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

Overall I really like this diff!

I think the missing bit is being a bit more clear on our advice to customers (do we want them to use experimental_default_proc? And are they aware it may disappear soon?).

This is one situation where the warnings, as well as the PR description should be considered with advanced customers in mind as the readers, not only our team.

Comment on lines 90 to 100
Datadog::Core.log_deprecation do
'The `lazy` option is deprecated. You no longer need to specify an option to be lazy '\
"when the default value is a block.\n"\
'In the case edge case that you need the default value to be a block, please use the the expriemntal option:'\
'experimental_default_proc'
end
Copy link
Member

Choose a reason for hiding this comment

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

Two notes on this:

  • "You no longer need to" should perhaps be "you no longer can" -- this option is gone, it's not that you wouldn't ever need it
  • Is it worth telling people to use the experimental option? Should we instead tell them that we don't support it all until we figure out what we should do?

@GustavoCaso GustavoCaso force-pushed the core-configuration-remove-lazy branch from b0a1cdb to 5d914ad Compare July 4, 2023 12:32
Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

馃憤 LGTM. It may be worth to triple-check that everyone is happy with this internally, but I see no reason not to merge this in :)

@GustavoCaso GustavoCaso force-pushed the core-configuration-remove-lazy branch from 5d914ad to 88063eb Compare July 5, 2023 15:29
@GustavoCaso GustavoCaso force-pushed the core-configuration-remove-lazy branch from 40af507 to c926bc2 Compare July 5, 2023 16:20
@GustavoCaso GustavoCaso force-pushed the core-configuration-remove-lazy branch from c926bc2 to 5b1c1f3 Compare July 5, 2023 16:23
@GustavoCaso GustavoCaso merged commit 338bb04 into master Jul 6, 2023
203 checks passed
@GustavoCaso GustavoCaso deleted the core-configuration-remove-lazy branch July 6, 2023 07:50
@github-actions github-actions bot added this to the 1.13.0 milestone Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appsec Application Security monitoring product ci-app CI product for test suite instrumentation core Involves Datadog core libraries integrations Involves tracing integrations tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants