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

Add new interface to register experiments #5755

Merged
merged 2 commits into from
Sep 20, 2022
Merged

Conversation

jurre
Copy link
Member

@jurre jurre commented Sep 20, 2022

Currently experiments are required to be passed in as an optional
options flag to the individual classes like the FileFetcher and
FileUpdater. This is fine, but it becomes a bit cumbersome when more
deeply nested objects need to access this flag, as we need to pass it
down to all of them.

This introduces a global Dependabot::Experiments interface that we can
use to register experiments and access them where needed.

The idea is that these are set in the Updater before running an update,
and will be available for the duration of the job.

Right now most of the existing experiments are left as is, using the options flags,
but I've ported the kubernetes_enabled feature flag for the Docker ecosystem to
demonstrate how this would work.

There is more functionality we could add to this interface, but for now it just adds what
is needed.

@jurre jurre requested a review from a team as a code owner September 20, 2022 07:32
@jurre jurre force-pushed the jurre/nicer-feature-flags branch 4 times, most recently from 7c329c0 to 3116e29 Compare September 20, 2022 09:23
Copy link
Member

@landongrindheim landongrindheim left a comment

Choose a reason for hiding this comment

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

I really like this change! I find it much easier to reason about and I'm guessing it's less bug-prone than the previous use of options being passed around everywhere 🙌

Comment on lines +228 to +230
$options[:updater_options].each do |name, val|
Dependabot::Experiment.register(name, val)
end
Copy link
Member

Choose a reason for hiding this comment

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

Do we use :updater_options for more than experiments? Maybe it's not such a big deal for dry-run, but the name doesn't really fit the purpose.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah we use a few different names in different places, we ended up with an options arg for the FileUpdater with the idea that it could be used for more things than just experiments. I'm not sure that we ever have, and going forward we should probably rename things where it makes sense, but I was aiming to keep the change as small as possible

Currently experiments are required to be passed in as an optional
`options` flag to the individual classes like the FileFetcher and
FileUpdater. This is fine, but it becomes a bit cumbersome when more
deeply nested objects need to access this flag, as we need to pass it
down to all of them.

This introduces a global `Dependabot::Experiments` interface that we can
use to register experiments and access them where needed.

The idea is that these are set in the Updater before running an update,
and will be available for the duration of the job.
@jurre jurre force-pushed the jurre/nicer-feature-flags branch from 3116e29 to aa2bb20 Compare September 20, 2022 13:54
@jurre jurre requested a review from pavera September 20, 2022 14:12
Copy link
Contributor

@pavera pavera left a comment

Choose a reason for hiding this comment

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

This feels much cleaner than before. 🚀

@jurre
Copy link
Member Author

jurre commented Sep 20, 2022

cc @brendandburns this change affects how the kubernetes_enabled flag is checked in the Docker ecosystem, so when you update Dependabot Core on your end you'll need to make a small change to make things work, it would be very similar to https://github.com/dependabot/dependabot-core/pull/5755/files#diff-b18ee444afdafa5177657bddd586b0097d8d8f631729850ed2afd5b6eb573e5aR65-R67. Please let me know if I can help with that in any way!

@jurre jurre merged commit 237af99 into main Sep 20, 2022
@jurre jurre deleted the jurre/nicer-feature-flags branch September 20, 2022 15:49
@jeffwidman
Copy link
Member

Thanks @jurre, funny having never looked at the actual code, I'd always assume feature/experiment flags were implemented this way already. 😆

Is there any cleanup that needs to be done in a follow-on PR to remove code / feautres that this PR makes superfluous? Based on the conversation ☝️, I wasn't clear if the options arg should be kept or removed since we never use it?

@jurre
Copy link
Member Author

jurre commented Sep 20, 2022

Is there any cleanup that needs to be done in a follow-on PR to remove code / feautres that this PR makes superfluous?

Yeah we can migrate the existing flags to use this functionality, but we can also keep them as is and wait for them to naturally be removed as those experiments are wrapped up.

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.

4 participants