Skip to content

Commit 8af1b3a

Browse files
author
Tarik Eshaq
committed
Adds experiments to simple app
1 parent f074469 commit 8af1b3a

File tree

17 files changed

+101
-31
lines changed

17 files changed

+101
-31
lines changed

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import static org.gradle.api.tasks.testing.TestResult.ResultType
66

77
buildscript {
88
repositories {
9+
mavenLocal()
910
if (project.hasProperty("googleRepo")) {
1011
maven {
1112
name "Google"
@@ -48,6 +49,7 @@ plugins {
4849

4950
allprojects {
5051
repositories {
52+
mavenLocal()
5153
if (project.hasProperty("googleRepo")) {
5254
maven {
5355
name "Google"

buildSrc/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
}
88

99
repositories {
10+
mavenLocal()
1011
jcenter()
1112
}
1213

buildSrc/src/main/java/Dependencies.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object Versions {
2929

3030
const val mozilla_appservices = "61.0.7"
3131

32-
const val mozilla_glean = "31.2.3"
32+
const val mozilla_glean = "31.4.0-TESTING26"
3333

3434
const val material = "1.1.0"
3535
const val nearby = "17.0.0"

components/browser/engine-gecko-beta/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
buildscript {
66
repositories {
7+
mavenLocal()
78
maven {
89
url "https://maven.mozilla.org/maven2"
910
}

components/browser/engine-gecko-nightly/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
buildscript {
66
repositories {
7+
mavenLocal()
78
maven {
89
url "https://maven.mozilla.org/maven2"
910
}

components/browser/engine-gecko/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
buildscript {
66
repositories {
7+
mavenLocal()
78
maven {
89
url "https://maven.mozilla.org/maven2"
910
}

components/lib/crash/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
buildscript {
66
repositories {
7+
mavenLocal()
78
maven {
89
url "https://maven.mozilla.org/maven2"
910
}

components/service/glean/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ dependencies {
4646
implementation Dependencies.kotlin_stdlib
4747
implementation Dependencies.kotlin_coroutines
4848
implementation Dependencies.androidx_work_runtime
49-
50-
api GLEAN_LIBRARY
49+
api (GLEAN_LIBRARY) {
50+
exclude group: 'org.mozilla.components', module: 'concept-fetch'
51+
}
5152

5253
// So consumers can set a HTTP client.
5354
api project(':concept-fetch')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package mozilla.components.service.glean
2+
3+
import kotlinx.coroutines.*
4+
import mozilla.telemetry.glean.Experiments as ExperimentsCore
5+
6+
object Experiments {
7+
private var inner: ExperimentsCore = ExperimentsCore
8+
private val job = SupervisorJob()
9+
private val scope = CoroutineScope(Dispatchers.IO) + job
10+
fun initialize(baseUrl: String, collectionName: String, bucketName: String, dbPath: String) {
11+
inner.initialize(baseUrl, collectionName, bucketName, dbPath)
12+
}
13+
fun getBranch(experimentName: String): String {
14+
return inner.getBranch(experimentName)
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package mozilla.components.service.glean
2+
3+
4+
import mozilla.components.concept.fetch.Client
5+
import mozilla.telemetry.glean.RustHttpConfig as HttpConfig
6+
7+
/**
8+
* An object allowing configuring the HTTP client used by Rust code.
9+
*/
10+
object RustHttpConfig {
11+
12+
/**
13+
* Set the HTTP client to be used by all Rust code.
14+
*
15+
* The `Lazy`'s value is not read until the first request is made.
16+
*
17+
* This must be called
18+
* - after initializing a megazord for users using a custom megazord build.
19+
* - before any other calls into application-services rust code which make HTTP requests.
20+
*/
21+
fun setClient(c: Lazy<Client>) {
22+
HttpConfig.setClient(c)
23+
}
24+
}

components/support/migration/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
buildscript {
66
repositories {
7+
mavenLocal()
78
maven {
89
url "https://maven.mozilla.org/maven2"
910
}

components/support/sync-telemetry/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
buildscript {
66
repositories {
7+
mavenLocal()
78
maven {
89
url "https://maven.mozilla.org/maven2"
910
}

components/tooling/glean-gradle-plugin/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010
}
1111

1212
repositories {
13+
mavenLocal()
1314
mavenCentral()
1415
}
1516

@@ -67,6 +68,7 @@ publishing {
6768
}
6869

6970
repositories {
71+
mavenLocal()
7072
maven {
7173
url = "$buildDir/maven"
7274
}

samples/glean/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
buildscript {
66
repositories {
7+
mavenLocal()
78
maven {
89
url "https://maven.mozilla.org/maven2"
910
}

samples/glean/samples-glean-library/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
buildscript {
66
repositories {
7+
mavenLocal()
78
maven {
89
url "https://maven.mozilla.org/maven2"
910
}

samples/glean/src/main/java/org/mozilla/samples/glean/GleanApplication.kt

+43-28
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,66 @@ package org.mozilla.samples.glean
66

77
import android.app.Application
88
import android.content.Intent
9+
import kotlinx.coroutines.*
910
import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient
1011
import mozilla.components.service.experiments.Configuration as ExperimentsConfig
1112
import mozilla.components.service.glean.Glean
13+
import mozilla.components.service.glean.Experiments as Exp
1214
import mozilla.components.service.glean.config.Configuration
1315
import mozilla.components.service.glean.net.ConceptFetchHttpUploader
1416
import mozilla.components.service.experiments.Experiments
17+
import mozilla.components.service.glean.RustHttpConfig
1518
import mozilla.components.support.base.log.Log
1619
import mozilla.components.support.base.log.sink.AndroidLogSink
1720
import org.mozilla.samples.glean.GleanMetrics.Basic
1821
import org.mozilla.samples.glean.GleanMetrics.Test
1922
import org.mozilla.samples.glean.GleanMetrics.Custom
2023
import org.mozilla.samples.glean.GleanMetrics.Pings
24+
import kotlin.coroutines.CoroutineContext
25+
2126

2227
class GleanApplication : Application() {
2328

2429
override fun onCreate() {
25-
super.onCreate()
26-
27-
// We want the log messages of all builds to go to Android logcat
28-
Log.addSink(AndroidLogSink())
29-
30-
// Register the sample application's custom pings.
31-
Glean.registerPings(Pings)
32-
33-
// Initialize the Glean library. Ideally, this is the first thing that
34-
// must be done right after enabling logging.
35-
val client by lazy { HttpURLConnectionClient() }
36-
val httpClient = ConceptFetchHttpUploader.fromClient(client)
37-
val config = Configuration(httpClient = httpClient)
38-
Glean.initialize(applicationContext, uploadEnabled = true, configuration = config)
39-
40-
// Initialize the Experiments library and pass in the callback that will generate a
41-
// broadcast Intent to signal the application that experiments have been updated. This is
42-
// only relevant to the experiments library, aside from recording the experiment in Glean.
43-
Experiments.initialize(applicationContext, ExperimentsConfig(httpClient = client)) {
44-
val intent = Intent()
45-
intent.action = "org.mozilla.samples.glean.experiments.updated"
46-
sendBroadcast(intent)
47-
}
30+
super.onCreate()
31+
// We want the log messages of all builds to go to Android logcat
32+
Log.addSink(AndroidLogSink())
33+
34+
// Register the sample application's custom pings.
35+
Glean.registerPings(Pings)
4836

49-
Test.timespan.start()
37+
// Initialize the Glean library. Ideally, this is the first thing that
38+
// must be done right after enabling logging.
39+
val client by lazy { HttpURLConnectionClient() }
40+
val httpClient = ConceptFetchHttpUploader.fromClient(client)
41+
val config = Configuration(httpClient = httpClient)
42+
Glean.initialize(applicationContext, uploadEnabled = true, configuration = config)
43+
RustHttpConfig.setClient(lazy { HttpURLConnectionClient() })
44+
Thread {
45+
GlobalScope.launch {
46+
var exp = mozilla.components.service.glean.Experiments
47+
exp.initialize("https://kinto.dev.mozaws.net/v1/",
48+
"messaging-collection",
49+
"main",
50+
applicationContext.dataDir.path)
51+
val res = exp.getBranch("button-color")
52+
println(res)
53+
}
54+
}.start()
55+
// Initialize the Experiments library and pass in the callback that will generate a
56+
// broadcast Intent to signal the application that experiments have been updated. This is
57+
// only relevant to the experiments library, aside from recording the experiment in Glean.
58+
Experiments.initialize(applicationContext, ExperimentsConfig(httpClient = client)) {
59+
val intent = Intent()
60+
intent.action = "org.mozilla.samples.glean.experiments.updated"
61+
sendBroadcast(intent)
62+
}
5063

51-
Custom.counter.add()
64+
Test.timespan.start()
5265

53-
// Set a sample value for a metric.
54-
Basic.os.set("Android")
66+
Custom.counter.add()
67+
68+
// Set a sample value for a metric.
69+
Basic.os.set("Android")
70+
}
5571
}
56-
}

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.yaml.snakeyaml.Yaml
66

77
buildscript {
88
repositories {
9+
mavenLocal()
910
jcenter()
1011
}
1112

0 commit comments

Comments
 (0)