-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
This pull request has conflicts when rebasing. Could you fix it @jhugman? |
FYI those changes are now on |
6b61588
to
49b5d46
Compare
@@ -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() |
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.
This needs to be initialized after Glean, but as early as possible so it's available to startup experiments.
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.
Technically, it could be initialized before Glean as Glean caches recordings before it is initialized and replays them when it is.
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 was seeing Rust errors in FxA client during the initialization of TelemetryWrapper
when putting nimbus init earlier.
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 | ||
} |
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.
This feels like it should be utility function someplace (it's all static
), but I couldn't find one.
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.
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).
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'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() |
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.
Technically, it could be initialized before Glean as Glean caches recordings before it is initialized and replays them when it is.
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 | ||
} |
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.
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).
Client/Experiments/Experiments.swift
Outdated
// channel. The values given here should match what `Experimenter` | ||
// thinks it is. | ||
let appSettings = NimbusAppSettings( | ||
appName: "fxios", |
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.
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
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.
This is useful, thanks.
7f4b062
to
7216138
Compare
7216138
to
d814cfb
Compare
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, butwill 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