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)
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu committed Oct 21, 2019
1 parent a4d7968 commit a2beb5f
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 5 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 @@ -435,6 +445,7 @@ dependencies {
implementation deps.android_components.ui_autocomplete
implementation deps.android_components.concept_fetch
implementation deps.android_components.lib_fetch
implementation deps.android_components.glean

// Kotlin dependency
implementation deps.kotlin.stdlib
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 FirefoxReality_wavevr, FirefoxReality_oculusvr, FirefoxReality_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
notification_emails:
- dmu@mozilla.com
expires: "2020-05-01"
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.res.Configuration;

import org.mozilla.vrbrowser.browser.Places;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.LocaleUtils;

Expand All @@ -26,6 +27,7 @@ public void onCreate() {
mPlaces = new Places(this);

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 @@ -116,10 +117,17 @@ public void setTelemetryEnabled(boolean isEnabled) {
final boolean hasEnabled = isTelemetryEnabled();
if (hasEnabled != isEnabled) {
TelemetryWrapper.init(mContext);
GleanMetricsService.init(mContext);
}

TelemetryHolder.get().getConfiguration().setUploadEnabled(isEnabled);
TelemetryHolder.get().getConfiguration().setCollectionEnabled(isEnabled);

if (isEnabled) {
GleanMetricsService.start();
} else {
GleanMetricsService.stop();
}
}

public void setGeolocationData(String aGeolocationData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

import java.util.Locale;

import kotlin.coroutines.Continuation;
import mozilla.components.browser.search.provider.localization.SearchLocalization;
import mozilla.components.browser.search.provider.localization.SearchLocalizationProvider;

public class GeolocationLocalizationProvider extends SearchLocalizationProvider {
public class GeolocationLocalizationProvider implements SearchLocalizationProvider {

private String mCountry;
private String mLanguage;
Expand All @@ -20,20 +22,21 @@ public class GeolocationLocalizationProvider extends SearchLocalizationProvider
mRegion = data.getCountryCode();
}

public SearchLocalization determineRegion(Continuation<? super SearchLocalization> continuation) {
return new SearchLocalization(mLanguage, mCountry, mRegion);
}

@NotNull
@Override
public String getCountry() {
return mCountry;
}

@NotNull
@Override
public String getLanguage() {
return mLanguage;
}

@Nullable
@Override
public String getRegion() {
return mRegion;
}
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 FirefoxReality_wavevr, FirefoxReality_oculusvr, FirefoxReality_googlevr, etc. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854)||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 FirefoxReality_wavevr, FirefoxReality_oculusvr, FirefoxReality_googlevr, etc. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854)||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 FirefoxReality_wavevr, FirefoxReality_oculusvr, FirefoxReality_googlevr, etc. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854)||2020-05-01 |


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

5 changes: 4 additions & 1 deletion versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def versions = [:]
// GeckoView versions can be found here:
// https://maven.mozilla.org/?prefix=maven2/org/mozilla/geckoview/
versions.gecko_view = "71.0.20191018095340"
versions.android_components = "4.0.0"
versions.android_components = "16.0.0"
versions.mozilla_speech = "1.0.6"
versions.openwnn = "1.3.7"
versions.google_vr = "1.190.0"
Expand Down 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 @@ -125,6 +126,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 a2beb5f

Please sign in to comment.