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

Introduce an Experiments.shared object to add Nimbus experiments #8223

Merged
merged 2 commits into from
Mar 31, 2021

Conversation

jhugman
Copy link
Contributor

@jhugman jhugman commented Mar 25, 2021

Fixes SDK-210.
Depends on SDK-241.

We introduce a singleton Experiments.shared to give Firefox for iOS access to the Nimbus experimentation platform.

This is branched from @rfk's upgrade of Application Services, but will require a version of Application Services' library of at least 75.0.0
(including mozilla/application-services#3901, mozilla/application-services#3930 and mozilla/application-services#3991)
to enable access to the Nimbus.swift wrapper and the Nimbus-SDK.

Because of this, it is not ready to land on main. We should discuss when it is ready, and where to land it in the meantime.

However, it should be ready for review.

Because it is building on another branch outside of the main repo, I can't base this PR on that branch. The commit to review is

@jhugman jhugman requested review from travis79 and boek March 25, 2021 19:56
@mergify
Copy link
Contributor

mergify bot commented Mar 25, 2021

This pull request has conflicts when rebasing. Could you fix it @jhugman?

@rfk
Copy link
Contributor

rfk commented Mar 25, 2021

This is branched from @rfk's upgrade of Application Services,

FYI those changes are now on main, but via a rebased commit, so I expect you may need to rebase away my commit on your branch here as well.

@jhugman jhugman force-pushed the jhugman/fxios-hearts-nimbus branch from 6b61588 to 49b5d46 Compare March 26, 2021 19:04
@@ -109,6 +109,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati

telemetry = TelemetryWrapper(profile: profile)

// Start intialzing the Nimbus SDK. This should be done after Glean
// has been started.
initializeExperiments()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be initialized after Glean, but as early as possible so it's available to startup experiments.

Copy link
Member

Choose a reason for hiding this comment

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

Technically, it could be initialized before Glean as Glean caches recordings before it is initialized and replays them when it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was seeing Rust errors in FxA client during the initialization of TelemetryWrapper when putting nimbus init earlier.

Comment on lines +44 to +64
static var dbPath: String? {
let profilePath: String?
if AppConstants.IsRunningTest || AppConstants.IsRunningPerfTest {
profilePath = (UIApplication.shared.delegate as? TestAppDelegate)?.dirForTestProfile
} else {
profilePath = FileManager.default.containerURL(
forSecurityApplicationGroupIdentifier: AppInfo.sharedContainerIdentifier
)?
.appendingPathComponent("profile.profile")
.path
}
let dbPath = profilePath.flatMap {
URL(fileURLWithPath: $0).appendingPathComponent("nimbus.db").path
}

if let dbPath = dbPath, Logger.logPII {
log.info("Nimbus database: \(dbPath)")
}
return dbPath
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feels like it should be utility function someplace (it's all static), but I couldn't find one.

Copy link
Member

Choose a reason for hiding this comment

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

For comparison, Glean gets its file directory like this:

func getGleanDirectory() -> URL {
    let paths = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)
    let documentsDirectory = paths[0]
    return documentsDirectory.appendingPathComponent("glean_data")
}

I see this asks for a path to a shared container so that it is the same storage for both the app and any app-extensions. Just FYI, allowing Nimbus to run in an iOS app-extension may deserve some consideration since app-extensions run in their own process, typically have their own storage and memory, and Glean does not support being ran in a app-extension process. This may all work just fine for Nimbus, but beware: here be dragons (from my experiences with Glean on iOS).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been worried about extensions.

I had considered working with extensions to be part of another, as yet defined epic, once there was a demand for it. It will require some fundamental work in Nimbus SDK, e.g. understanding accessing rkv across process boundaries, running rkv in different processes to access the same file, or running completely different instances of nimbus and database, that only share ids (e.g. in the keychain).

That Glean doesn't support extensions yet, is just yet another reason for Nimbus not worry about them right now.

@@ -109,6 +109,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati

telemetry = TelemetryWrapper(profile: profile)

// Start intialzing the Nimbus SDK. This should be done after Glean
// has been started.
initializeExperiments()
Copy link
Member

Choose a reason for hiding this comment

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

Technically, it could be initialized before Glean as Glean caches recordings before it is initialized and replays them when it is.

Comment on lines +44 to +64
static var dbPath: String? {
let profilePath: String?
if AppConstants.IsRunningTest || AppConstants.IsRunningPerfTest {
profilePath = (UIApplication.shared.delegate as? TestAppDelegate)?.dirForTestProfile
} else {
profilePath = FileManager.default.containerURL(
forSecurityApplicationGroupIdentifier: AppInfo.sharedContainerIdentifier
)?
.appendingPathComponent("profile.profile")
.path
}
let dbPath = profilePath.flatMap {
URL(fileURLWithPath: $0).appendingPathComponent("nimbus.db").path
}

if let dbPath = dbPath, Logger.logPII {
log.info("Nimbus database: \(dbPath)")
}
return dbPath
}
Copy link
Member

Choose a reason for hiding this comment

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

For comparison, Glean gets its file directory like this:

func getGleanDirectory() -> URL {
    let paths = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)
    let documentsDirectory = paths[0]
    return documentsDirectory.appendingPathComponent("glean_data")
}

I see this asks for a path to a shared container so that it is the same storage for both the app and any app-extensions. Just FYI, allowing Nimbus to run in an iOS app-extension may deserve some consideration since app-extensions run in their own process, typically have their own storage and memory, and Glean does not support being ran in a app-extension process. This may all work just fine for Nimbus, but beware: here be dragons (from my experiences with Glean on iOS).

// channel. The values given here should match what `Experimenter`
// thinks it is.
let appSettings = NimbusAppSettings(
appName: "fxios",
Copy link
Member

Choose a reason for hiding this comment

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

Note that this should be changed to firefox_ios. Source of truth for this app name is currently defined here: https://github.com/mozilla/probe-scraper/blob/b3730a6d22e70519beeb2c5df6aac6fb8d3ed00f/repositories.yaml#L231

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is useful, thanks.

@jhugman jhugman force-pushed the jhugman/fxios-hearts-nimbus branch from 7f4b062 to 7216138 Compare March 29, 2021 15:45
@jhugman jhugman force-pushed the jhugman/fxios-hearts-nimbus branch from 7216138 to d814cfb Compare March 30, 2021 19:04
@jhugman jhugman merged commit 9e1a42a into main Mar 31, 2021
@jhugman jhugman deleted the jhugman/fxios-hearts-nimbus branch March 31, 2021 13:31
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