Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Glean baseline pings integration. (stage 1) (#1854)
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu authored and keianhzo committed Oct 28, 2019
1 parent 6d2aa2e commit 425f01f
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
plugins {
id "com.jetbrains.python.envs" version "0.0.26"
}

apply plugin: 'com.android.application'
apply from: "$project.rootDir/tools/gradle/versionCode.gradle"
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
Expand Down Expand Up @@ -32,6 +37,11 @@ def getUseDebugSigningOnRelease = { ->
return false
}

// Generate markdown docs for the collected metrics.
ext.gleanGenerateMarkdownDocs = true
ext.gleanDocsDirectory = "$rootDir/docs"
apply from: 'https://github.com/mozilla-mobile/android-components/raw/v' + deps.android_components_version + '/components/service/glean/scripts/sdk_generator.gradle'

android {
compileSdkVersion build_versions.target_sdk
defaultConfig {
Expand Down Expand Up @@ -449,6 +459,7 @@ dependencies {
implementation deps.android_components.lib_fetch
implementation deps.android_components.support_rustlog
implementation deps.android_components.support_rusthttp
implementation deps.android_components.glean

// TODO this should not be necessary at all, see Services.kt
implementation deps.work.runtime
Expand Down
25 changes: 25 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


$schema: moz://mozilla.org/schemas/glean/metrics/1-0-0

distribution:
channel_name:
type: string
lifetime: application
description: >
The distribution channel name of this application. We use this field to recognize Firefox Reality
is distributed to which channels, such as wavevr, oculusvr, googlevr, etc.
send_in_pings:
- baseline
- events
- metrics
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1420
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568
notification_emails:
- [email protected]
expires: "2020-05-01"
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.mozilla.vrbrowser.browser.Services;
import org.mozilla.vrbrowser.db.AppDatabase;
import org.mozilla.vrbrowser.db.DataRepository;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.BitmapCache;
import org.mozilla.vrbrowser.utils.LocaleUtils;
Expand All @@ -37,6 +38,7 @@ public void onCreate() {
mAccounts = new Accounts(this);

TelemetryWrapper.init(this);
GleanMetricsService.init(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.telemetry.TelemetryHolder;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.LocaleUtils;
Expand Down Expand Up @@ -132,6 +133,9 @@ public void setTelemetryEnabled(boolean isEnabled) {
// We send after enabling in case of opting-in
if (isEnabled) {
TelemetryWrapper.telemetryStatus(true);
GleanMetricsService.start();
} else {
GleanMetricsService.stop();
}

// Update the status sent flag
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.mozilla.vrbrowser.telemetry;

import android.content.Context;
import android.util.Log;

import androidx.annotation.UiThread;

import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.SystemUtils;
import org.mozilla.vrbrowser.BuildConfig;
import org.mozilla.vrbrowser.GleanMetrics.Distribution;

import mozilla.components.service.glean.Glean;
import mozilla.components.service.glean.config.Configuration;


public class GleanMetricsService {

private final static String APP_NAME = "FirefoxReality";
private static boolean initialized = false;
private final static String LOGTAG = SystemUtils.createLogtag(GleanMetricsService.class);
private static Context context = null;

// We should call this at the application initial stage.
public static void init(Context aContext) {
if (initialized)
return;

context = aContext;
initialized = true;

final boolean telemetryEnabled = SettingsStore.getInstance(aContext).isTelemetryEnabled();
if (telemetryEnabled) {
GleanMetricsService.start();
} else {
GleanMetricsService.stop();
}
Configuration config = new Configuration(Configuration.DEFAULT_TELEMETRY_ENDPOINT,
BuildConfig.BUILD_TYPE);
Glean.INSTANCE.initialize(aContext, config);
}

// It would be called when users turn on/off the setting of telemetry.
// e.g., SettingsStore.getInstance(context).setTelemetryEnabled();
public static void start() {
Glean.INSTANCE.setUploadEnabled(true);
setStartupMetrics();
}

// It would be called when users turn on/off the setting of telemetry.
// e.g., SettingsStore.getInstance(context).setTelemetryEnabled();
public static void stop() {
Glean.INSTANCE.setUploadEnabled(false);
}

private static void setStartupMetrics() {
Distribution.INSTANCE.getChannelName().set(DeviceType.isOculusBuild() ? "oculusvr" : BuildConfig.FLAVOR_platform);
}
}
45 changes: 45 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!-- AUTOGENERATED BY glean_parser. DO NOT EDIT. -->

# Metrics
This document enumerates the metrics collected by this project.
This project may depend on other projects which also collect metrics.
This means you might have to go searching through the dependency tree to get a full picture of everything collected by this project.
Sorry about that.

# Pings

- [baseline](#baseline)
- [events](#events)
- [metrics](#metrics)


## baseline
This is a built-in ping that is assembled out of the box by the Glean SDK.
See the Glean SDK documentation for the [`baseline` ping](https://mozilla.github.io/glean/book/user/pings/baseline.html).
The following metrics are added to the ping:

| Name | Type | Description | Data reviews | Extras | Expiration |
| --- | --- | --- | --- | --- | --- |
| distribution.channel_name |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The distribution channel name of this application. We use this field to recognize Firefox Reality is distributed to which channels, such as wavevr, oculusvr, googlevr, etc. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568)||2020-05-01 |

## events
This is a built-in ping that is assembled out of the box by the Glean SDK.
See the Glean SDK documentation for the [`events` ping](https://mozilla.github.io/glean/book/user/pings/events.html).
The following metrics are added to the ping:

| Name | Type | Description | Data reviews | Extras | Expiration |
| --- | --- | --- | --- | --- | --- |
| distribution.channel_name |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The distribution channel name of this application. We use this field to recognize Firefox Reality is distributed to which channels, such as wavevr, oculusvr, googlevr, etc. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568)||2020-05-01 |

## metrics
This is a built-in ping that is assembled out of the box by the Glean SDK.
See the Glean SDK documentation for the [`metrics` ping](https://mozilla.github.io/glean/book/user/pings/metrics.html).
The following metrics are added to the ping:

| Name | Type | Description | Data reviews | Extras | Expiration |
| --- | --- | --- | --- | --- | --- |
| distribution.channel_name |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The distribution channel name of this application. We use this field to recognize Firefox Reality is distributed to which channels, such as wavevr, oculusvr, googlevr, etc. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568)||2020-05-01 |


<!-- AUTOGENERATED BY glean_parser. DO NOT EDIT. -->

3 changes: 3 additions & 0 deletions versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ deps.gecko_view = gecko_view

def android_components = [:]
android_components.telemetry = "org.mozilla.components:service-telemetry:$versions.android_components"
android_components.glean = "org.mozilla.components:service-glean:$versions.android_components"
android_components.browser_errorpages = "org.mozilla.components:browser-errorpages:$versions.android_components"
android_components.browser_search = "org.mozilla.components:browser-search:$versions.android_components"
android_components.browser_storage = "org.mozilla.components:browser-storage-sync:$versions.android_components"
Expand Down Expand Up @@ -137,6 +138,8 @@ deps.junit = "junit:junit:$versions.junit"

deps.android_gradle_plugin = "com.android.tools.build:gradle:$versions.android_gradle_plugin"

deps.android_components_version = versions.android_components

deps.snakeyaml = "org.yaml:snakeyaml:$versions.snakeyaml:android"

deps.gson = "com.google.code.gson:gson:$versions.gson"
Expand Down

0 comments on commit 425f01f

Please sign in to comment.