Skip to content

Commit

Permalink
Nimbus-SDK-119 Get Nimbus server endpoint at build time. (mozilla-mob…
Browse files Browse the repository at this point in the history
…ile#16682)

This PR builds on [AC#mozilla-mobile#9024][1], and implements setting the Nimbus endpoints from [a secret set at build time][2].

For production use, this requires a secret named `nimbus_url` to be put into CI.

Note: Nimbus is currently behind a feature flag.

If developers wish to use a Nimbus server for local development, you can set the url by adding an entry into local.properties, e.g.:

```
nimbus.remote-settings.url=https://settings.stage.moz4ws.net
```

Without setting server, Nimbus will be able to function, except no experimental definitions will be fetched, and features under experiment will be configured as if not enrolled in the experiment.

[1]: mozilla-mobile/android-components#9024
[2]: https://groups.google.com/a/mozilla.com/g/android-components-team/c/lAGVKQy8aiA/m/rY3uGAwhBAAJ
  • Loading branch information
jhugman committed Dec 3, 2020
1 parent c465521 commit ea9f692
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ gen-external-apklibs
# macOS
.DS_Store

# Token files
# Secrets files, e.g. tokens
.leanplum_token
.adjust_token
.sentry_token
.mls_token

.nimbus

# Python Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ The known features that are disabled by default are:
- Mozilla Location Services (also known as MLS)
- Firebase Push Services
- Telemetry (only disabled by default in debug builds)
- Nimbus

## Pre-push hooks
To reduce review turn-around time, we'd like all pushes to run tests locally. We'd
Expand Down Expand Up @@ -211,6 +212,15 @@ In order to build successfully, you need to check out a commit in the dependency
- Run the `<android-components>/tools/list_compatible_dependency_versions.py` script to output a compatible commit
- Check out the latest commit from master in this repository and the dependency repository. However, this may fail if there were breaking changes added recently to the dependency.

### Using Nimbus servers during local development
If you're working with the Nimbus experiments platform, by default for local development Fenix configures Nimbus to not use a server.

If you wish to use a Nimbus server during local development, you can add a `https://` or `file://` endpoint to the `local.properties` file.

- `nimbus.remote-settings.url`

Testing experimental branches should be possible without a server.

### GeckoView
Specify a relative path to your local `mozilla-central` checkout via `dependencySubstitutions.geckoviewTopsrcdir`,
and optional a path to m-c object directory via `dependencySubstitutions.geckoviewTopobjdir`.
Expand Down
24 changes: 24 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,30 @@ android.applicationVariants.all { variant ->
buildConfigField 'String', 'MLS_TOKEN', '""'
println("X_X")
}

// -------------------------------------------------------------------------------------------------
// Nimbus: Read endpoint from local.properties of a local file if it exists
// -------------------------------------------------------------------------------------------------

print("Nimbus endpoint: ")

if (!isDebug) {
try {
def url = new File("${rootDir}/.nimbus").text.trim()
buildConfigField 'String', 'NIMBUS_ENDPOINT', '"' + url + '"'
println "(Added from .nimbus file)"
} catch (FileNotFoundException ignored) {
buildConfigField 'String', 'NIMBUS_ENDPOINT', 'null'
println("X_X")
}
} else if (gradle.hasProperty("localProperties.nimbus.remote-settings.url")) {
def url=gradle.getProperty("localProperties.nimbus.remote-settings.url")
buildConfigField 'String', 'NIMBUS_ENDPOINT', '"' + url + '"'
println "(Added from local.properties file)"
} else {
buildConfigField 'String', 'NIMBUS_ENDPOINT', 'null'
println("--")
}
}

androidExtensions {
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/org/mozilla/fenix/components/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import android.app.Application
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.net.Uri
import mozilla.components.lib.crash.CrashReporter
import mozilla.components.lib.crash.service.CrashReporterService
import mozilla.components.lib.crash.service.GleanCrashReporterService
import mozilla.components.lib.crash.service.MozillaSocorroService
import mozilla.components.lib.crash.service.SentryService
import mozilla.components.service.nimbus.Nimbus
import mozilla.components.service.nimbus.NimbusServerSettings
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
Expand Down Expand Up @@ -103,7 +105,13 @@ class Analytics(
}

val experiments by lazyMonitored {
Nimbus(context, server = null).apply {
val url: String? = BuildConfig.NIMBUS_ENDPOINT
val serverSettings = if (!url.isNullOrBlank()) {
NimbusServerSettings(url = Uri.parse(url))
} else {
null
}
Nimbus(context, serverSettings).apply {
if (FeatureFlags.nimbusExperiments) {
initialize()
// Global opt out state is stored in Nimbus, and shouldn't be toggled to `true`
Expand Down
1 change: 1 addition & 0 deletions taskcluster/fenix_taskgraph/transforms/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def add_shippable_secrets(config, tasks):
('leanplum', '.leanplum_token'),
('sentry_dsn', '.sentry_token'),
('mls', '.mls_token'),
('nimbus_url', '.nimbus'),
)])
else:
dummy_secrets.extend([{
Expand Down

0 comments on commit ea9f692

Please sign in to comment.