Skip to content

Commit

Permalink
Migrate telemetry pings to Glean (Stage 2). Fixes #2230
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu committed Nov 20, 2019
1 parent 6aa65ec commit dc6c7f8
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 1 deletion.
60 changes: 60 additions & 0 deletions app/metrics.yaml
Expand Up @@ -16,10 +16,70 @@ distribution:
- baseline
- events
- metrics
- session_end
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1420
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568
notification_emails:
- fxr-telemetry@mozilla.com
- dmu@mozilla.com
expires: "2020-05-01"
url:
domains:
type: counter
send_in_pings:
- session_end
description: >
Counting how many domains are visited in a session.
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/2230
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568
notification_emails:
- fxr-telemetry@mozilla.com
- dmu@mozilla.com
expires: "2020-05-01"
visits:
type: counter
send_in_pings:
- session_end
description: >
Counting how many URL links are visited in a session.
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/2230
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568
notification_emails:
- fxr-telemetry@mozilla.com
- dmu@mozilla.com
expires: "2020-05-01"
query_type:
type: labeled_counter
description: >
Counting how many URLs are visited in a day, by input method.
labels:
- type_link
- type_query
- voice_query
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/2230
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568
notification_emails:
- fxr-telemetry@mozilla.com
- dmu@mozilla.com
expires: "2020-05-01"
searches:
counts:
type: labeled_counter
description: >
Counting how many searches are queried in a specific search engine. The search engine `identifier`s are used as keys for this metric.
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/2230
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568
notification_emails:
- fxr-telemetry@mozilla.com
- dmu@mozilla.com
expires: "2020-05-01"
18 changes: 18 additions & 0 deletions app/pings.yaml
@@ -0,0 +1,18 @@
# 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/pings/1-0-0

session_end:
description: >
This ping is sent at the end of a session (when Firefox Reality switches to the background).
We usually send search and UI control metrics at the end of a session.
include_client_id: true
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/2230
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568
notification_emails:
- fxr-telemetry@mozilla.com
- dmu@mozilla.com
Expand Up @@ -52,6 +52,7 @@
import org.mozilla.vrbrowser.geolocation.GeolocationWrapper;
import org.mozilla.vrbrowser.input.MotionEventGenerator;
import org.mozilla.vrbrowser.search.SearchEngineWrapper;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.OffscreenDisplay;
import org.mozilla.vrbrowser.ui.widgets.KeyboardWidget;
Expand Down Expand Up @@ -380,9 +381,11 @@ protected void onStop() {

if (SettingsStore.getInstance(this).getCylinderDensity() > 0.0f) {
TelemetryWrapper.queueCurvedModeActiveEvent();
} else {
}

TelemetryWrapper.stop();
GleanMetricsService.sessionStop();
}

@Override
Expand Down Expand Up @@ -918,6 +921,7 @@ void pauseGeckoViewCompositor() {
mIsPresentingImmersive = true;
mWindows.enterImmersiveMode();
TelemetryWrapper.startImmersive();
GleanMetricsService.startImmersive();
PauseCompositorRunnable runnable = new PauseCompositorRunnable();

synchronized (this) {
Expand All @@ -944,6 +948,7 @@ void resumeGeckoViewCompositor() {
resetUIYaw();

TelemetryWrapper.uploadImmersiveToHistogram();
GleanMetricsService.stopImmersive();
Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(() -> {
mWindows.resumeCompositor();
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.mozilla.vrbrowser.browser.UserAgentOverride;
import org.mozilla.vrbrowser.browser.VideoAvailabilityListener;
import org.mozilla.vrbrowser.geolocation.GeolocationData;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.BitmapCache;
import org.mozilla.vrbrowser.utils.InternalPages;
Expand Down Expand Up @@ -922,6 +923,7 @@ public void onPageStart(@NonNull GeckoSession aSession, @NonNull String aUri) {
Log.d(LOGTAG, "Session onPageStart");
mState.mIsLoading = true;
TelemetryWrapper.startPageLoadTime();
GleanMetricsService.startPageLoadTime();

for (GeckoSession.ProgressDelegate listener : mProgressListeners) {
listener.onPageStart(aSession, aUri);
Expand All @@ -937,6 +939,7 @@ public void onPageStop(@NonNull GeckoSession aSession, boolean b) {
mState.mIsLoading = false;
if (!SessionUtils.isLocalizedContent(mState.mUri)) {
TelemetryWrapper.uploadPageLoadToHistogram(mState.mUri);
GleanMetricsService.stopPageLoadTimeWithURI(mState.mUri);
}

for (GeckoSession.ProgressDelegate listener : mProgressListeners) {
Expand Down
Expand Up @@ -125,6 +125,10 @@ public String getResourceURL() {
return uri.getScheme() + "://" + uri.getHost();
}

public String getIdentifier() {
return mSearchEngine.getIdentifier();
}

// Receiver for locale updates
private BroadcastReceiver mLocaleChangedReceiver = new BroadcastReceiver() {
@Override
Expand Down
Expand Up @@ -5,11 +5,19 @@

import androidx.annotation.UiThread;

import org.mozilla.vrbrowser.GleanMetrics.Pings;
import org.mozilla.vrbrowser.GleanMetrics.Searches;
import org.mozilla.vrbrowser.GleanMetrics.Url;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.search.SearchEngineWrapper;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.SystemUtils;
import org.mozilla.vrbrowser.BuildConfig;
import org.mozilla.vrbrowser.GleanMetrics.Distribution;
import org.mozilla.vrbrowser.utils.UrlUtils;

import java.net.URI;
import java.util.HashSet;

import mozilla.components.service.glean.Glean;
import mozilla.components.service.glean.config.Configuration;
Expand All @@ -18,9 +26,10 @@
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 boolean initialized = false;
private static Context context = null;
private static HashSet<String> domainMap = new HashSet<String>();

// We should call this at the application initial stage.
public static void init(Context aContext) {
Expand Down Expand Up @@ -53,6 +62,90 @@ public static void stop() {
Glean.INSTANCE.setUploadEnabled(false);
}

public static void startPageLoadTime() {
// TODO: Blocked by Bug 1595914.
// pageLoadingTimerId = Pages.INSTANCE.getPageLoad().start();
}

public static void stopPageLoadTimeWithURI(String uri) {
// TODO: Blocked by Bug 1595914.
// Pages.INSTANCE.getPageLoad().stopAndAccumulate(pageLoadingTimerId);

try {
URI uriLink = URI.create(uri);
if (uriLink.getHost() == null) {
return;
}

if (domainMap.add(UrlUtils.stripCommonSubdomains(uriLink.getHost()))) {
Url.INSTANCE.getDomains().add();
}
Url.INSTANCE.getVisits().add();

} catch (IllegalArgumentException e) {
Log.e(LOGTAG, "Invalid URL", e);
}

}

public static void sessionStop() {
domainMap.clear();
Pings.INSTANCE.getSessionEnd().send();
}

@UiThread
public static void urlBarEvent(boolean aIsUrl) {
if (aIsUrl) {
Url.INSTANCE.getQueryType().get("type_link").add();
} else {
Url.INSTANCE.getQueryType().get("type_query").add();
// Record search engines.
String searchEngine = getDefaultSearchEngineIdentifierForTelemetry();
Searches.INSTANCE.getCounts().get(searchEngine).add();
}
}

@UiThread
public static void voiceInputEvent() {
Url.INSTANCE.getQueryType().get("voice_query").add();

// Record search engines.
String searchEngine = getDefaultSearchEngineIdentifierForTelemetry();
Searches.INSTANCE.getCounts().get(searchEngine).add();
}

public static void startImmersive() {
// TODO: Blocked by Bug 1595914 and 1595723.
// immersiveTimerId = Durarion.INSTANCE.getImmersiveMode().start();
}

public static void stopImmersive() {
// TODO: Blocked by Bug 1595914 and 1595723.
// Durarion.INSTANCE.getImmersiveMode().stopAndAccumulate(immersiveTimerId);
}

// TODO: Confirm if we don't need multiple metrics for tracking window open duration.
// like WindowLifetime1 ~ WindowLifetimeN for multiple windows.
public static void openWindowEvent(int windowId) {
// TODO: Blocked by Bug 1595914 and Bug 1595723.
// GleanTimerId id = Durarion.INSTANCE.getWindowLifetime().start();
// windowLifetimeId.put(windowId, id);
}

public static void closeWindowEvent(int windowId) {
// TODO: Blocked by Bug 1595914 and Bug 1595723.
// if (windowLifetimeId.containsKey(windowId)) {
// Durarion.INSTANCE.getWindowLifetime().stopAndAccumulate(windowLifetimeId.get(windowId));
// windowLifetimeId.remove(windowId);
// } else {
// Log.e(LOGTAG, "Can't find window id.");
// }
}

private static String getDefaultSearchEngineIdentifierForTelemetry() {
return SearchEngineWrapper.get(context).getIdentifier();
}

private static void setStartupMetrics() {
Distribution.INSTANCE.getChannelName().set(DeviceType.isOculusBuild() ? "oculusvr" : BuildConfig.FLAVOR_platform);
}
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.databinding.NavigationUrlBinding;
import org.mozilla.vrbrowser.search.SearchEngineWrapper;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.SelectionActionWidget;
Expand Down Expand Up @@ -446,13 +447,15 @@ public void handleURLEdit(String text) {
if (uri != null) {
url = uri.toString();
TelemetryWrapper.urlBarEvent(true);
GleanMetricsService.urlBarEvent(true);
} else if (text.startsWith("about:") || text.startsWith("resource://")) {
url = text;
} else {
url = SearchEngineWrapper.get(getContext()).getSearchURL(text);

// Doing search in the URL bar, so sending "aIsURL: false" to telemetry.
TelemetryWrapper.urlBarEvent(false);
GleanMetricsService.urlBarEvent(false);
}

if (mSession.getCurrentUri() != url) {
Expand Down Expand Up @@ -483,6 +486,7 @@ public void setClickable(boolean clickable) {
}

TelemetryWrapper.voiceInputEvent();
GleanMetricsService.voiceInputEvent();
};

private OnClickListener mClearListener = view -> {
Expand Down
Expand Up @@ -36,6 +36,7 @@
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.input.CustomKeyboard;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.keyboards.DanishKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.FinnishKeyboard;
Expand Down Expand Up @@ -847,6 +848,7 @@ private void handleVoiceInput() {
}
mIsInVoiceInput = true;
TelemetryWrapper.voiceInputEvent();
GleanMetricsService.voiceInputEvent();
mVoiceSearchWidget.show(CLEAR_FOCUS);
mWidgetPlacement.visible = false;
mWidgetManager.updateWidget(this);
Expand Down
Expand Up @@ -40,6 +40,7 @@
import org.mozilla.vrbrowser.browser.VideoAvailabilityListener;
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.adapters.Bookmark;
import org.mozilla.vrbrowser.ui.callbacks.BookmarksCallback;
Expand Down Expand Up @@ -202,6 +203,7 @@ private void initialize(Context aContext) {
setFocusable(true);

TelemetryWrapper.openWindowEvent(mWindowId);
GleanMetricsService.openWindowEvent(mWindowId);

if (mSession.getGeckoSession() != null) {
onCurrentSessionChange(null, mSession.getGeckoSession());
Expand Down Expand Up @@ -310,6 +312,7 @@ public void onResume() {

public void close() {
TelemetryWrapper.closeWindowEvent(mWindowId);
GleanMetricsService.closeWindowEvent(mWindowId);
hideContextMenus();
releaseWidget();
mBookmarksView.onDestroy();
Expand Down
14 changes: 14 additions & 0 deletions docs/metrics.md
Expand Up @@ -11,6 +11,7 @@ Sorry about that.
- [baseline](#baseline)
- [events](#events)
- [metrics](#metrics)
- [session_end](#session_end)


## baseline
Expand Down Expand Up @@ -39,6 +40,19 @@ 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 |
| searches.counts |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Counting how many searches are queried in a specific search engine. The search engine `identifier`s are used as keys for this metric. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568)||2020-05-01 |
| url.query_type |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Counting how many URLs are visited in a day, by input method. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568)|<ul><li>type_link</li><li>type_query</li><li>voice_query</li></ul>|2020-05-01 |

## session_end
This ping is sent at the end of a session (when Firefox Reality switches to the background). We usually send search and UI control metrics at the end of a session.

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 |
| url.domains |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |Counting how many domains are visited in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568)||2020-05-01 |
| url.visits |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |Counting how many URL links are visited in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854#issuecomment-546214568)||2020-05-01 |


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

0 comments on commit dc6c7f8

Please sign in to comment.