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 experiment logic #1081

Closed
wants to merge 22 commits into from
Closed

add experiment logic #1081

wants to merge 22 commits into from

Conversation

SabrinaTardio
Copy link
Contributor

@SabrinaTardio SabrinaTardio commented Nov 15, 2024

Please review the release process for BrowserServicesKit here.

Required:

Task/Issue URL: https://app.asana.com/0/1204186595873227/1208687542689225/f
iOS PR: duckduckgo/iOS#3582
macOS PR: duckduckgo/macos-browser#3559
What kind of version bump will this require?: Major

Optional:

Tech Design URL: https://app.asana.com/0/481882893211075/1208680035673275/f
CC:

Description: updates stateFor and isSubfeatureEnabled api to manage remote experiments and also adds getActiveExperimentsAPI

Steps to test this PR:

  1. Check all tests pass
  2. Run macOS app
  3. Run iOS app

<!—
Before submitting a PR, please ensure you have tested the combinations you expect the reviewer to test, then delete configurations you know do not need explicit testing.

Using a simulator where a physical device is unavailable is acceptable.
—>

OS Testing:

  • iOS 14
  • iOS 15
  • iOS 16
  • macOS 10.15
  • macOS 11
  • macOS 12

Internal references:

Software Engineering Expectations
Technical Design Template

@SabrinaTardio SabrinaTardio changed the title Sabrina/add experiment logic add experiment logic Nov 15, 2024
@SabrinaTardio SabrinaTardio marked this pull request as ready for review November 15, 2024 13:58
randomizer: randomizer)
}

public func stateFor(_ subfeature: any PrivacySubfeature,
Copy link
Contributor

Choose a reason for hiding this comment

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

looking at this API, I see an important issue with the naming. I understand the urge to be backward compatible, but I dislike that a method named like a simple getter actually mutates the internal state underneath (this is new behavior). can you think of proposing something here? e.g. resolveState(for subfeature?


private var store: ExperimentsDataStoring
private let randomizer: (Range<Double>) -> Double
private let queue = DispatchQueue(label: "com.ExperimentCohortsManager.queue")
Copy link
Contributor

Choose a reason for hiding this comment

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

this queue is not needed, it gives a false sense of security but it doesn't protect from anything;
instead you should clarify in the documentation for this manager that it is inherently not thread-safe, particularly for the method that assigns a cohort (as it mutates the state), and so should never be used elsewhere except for as an instance inside AppPrivacyConfig

cohortID: CohortID?,
versionProvider: AppVersionProvider,
randomizer: (Range<Double>) -> Double) -> PrivacyConfigurationFeatureState {
Self.experimentManagerQueue.sync {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should limit the sync queue block to only what truly requires synchronization. Avoid including any dependencies inside it (!). For example, the InternalUserDecider should handle its responsibilities elsewhere because if someone adds main queue synchronization code to it ever, it will lead to potential deadlock

(target.localeLanguage == nil || target.localeLanguage == locale.languageCode)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

What I dislike the most is that AppPrivacyConfiguration is turning into a MassiveAppPrivacyConfiguration. Can we plan a follow-up project to streamline and clean this up, possibly?

@jaceklyp jaceklyp requested a review from bwaresiak November 21, 2024 13:16
@bwaresiak
Copy link
Collaborator

bwaresiak commented Nov 21, 2024

Just glancing over this, made me think that we should add @samsymons and @diegoreymendez as stakeholders, as Config space is now used both in Host app and the Extensions - so potentially we could be using Feature experiments in all of these targets, while current implementation doesn't really solve the potential problem of cross-process data synchronization.

I'm not saying we need to solve for this now, but rather should be aware of that any any potential limitations.

Other than this, I see some good discussions in the comments, @SabrinaTardio and @jaceklyp :-) If you would feel like I could help speed up things by jumping on a call to try talking through some concepts brought here with both you, feel free to ping me. Other than that I was thinking to have a look (overview, not detailed) at this (as it's pretty interesting problem!), but once you are closer to actual solution to not add noise to your current flow.

@SabrinaTardio
Copy link
Contributor Author

Just glancing over this, made me think that we should add @samsymons and @diegoreymendez as stakeholders, as Config space is now used both in Host app and the Extensions - so potentially we could be using Feature experiments in all of these targets, while current implementation doesn't really solve the potential problem of cross-process data synchronization.

I'm not saying we need to solve for this now, but rather should be aware of that any any potential limitations.

Other than this, I see some good discussions in the comments, @SabrinaTardio and @jaceklyp :-) If you would feel like I could help speed up things by jumping on a call to try talking through some concepts brought here with both you, feel free to ping me. Other than that I was thinking to have a look (overview, not detailed) at this (as it's pretty interesting problem!), but once you are closer to actual solution to not add noise to your current flow.

Just for transparency we had a sync discussion about this and have a TD as a result (https://app.asana.com/0/1204186595873227/1208823859841917/f)
I’m working on either updating this or make an entirely new one for simplicity.

@SabrinaTardio
Copy link
Contributor Author

We had a sync discussion about this and have a TD as a result (https://app.asana.com/0/1204186595873227/1208823859841917/f)
I will open a new PR with the changes

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.

3 participants