From 87543c362a47810d149eb109b6a82e6b06c19aa4 Mon Sep 17 00:00:00 2001 From: Daosheng Mu Date: Mon, 25 Nov 2019 02:53:04 -0800 Subject: [PATCH] Migrate telemetry pings to Glean (Stage 2). Fixes #2230 (#2241) --- app/metrics.yaml | 60 ++++++++++++ app/pings.yaml | 18 ++++ .../mozilla/vrbrowser/VRBrowserActivity.java | 5 + .../vrbrowser/browser/engine/Session.java | 3 + .../vrbrowser/search/SearchEngineWrapper.java | 4 + .../telemetry/GleanMetricsService.java | 95 ++++++++++++++++++- .../vrbrowser/ui/views/NavigationURLBar.java | 4 + .../vrbrowser/ui/widgets/KeyboardWidget.java | 2 + .../vrbrowser/ui/widgets/WindowWidget.java | 3 + docs/metrics.md | 14 +++ 10 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 app/pings.yaml diff --git a/app/metrics.yaml b/app/metrics.yaml index 3bf7de5f6..2caf7df7c 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -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/2241#issuecomment-557740258 + 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/2241#issuecomment-557740258 + 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/2241#issuecomment-557740258 + 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/2241#issuecomment-557740258 + notification_emails: + - fxr-telemetry@mozilla.com - dmu@mozilla.com expires: "2020-05-01" diff --git a/app/pings.yaml b/app/pings.yaml new file mode 100644 index 000000000..67ee75831 --- /dev/null +++ b/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/2241#issuecomment-557740258 + notification_emails: + - fxr-telemetry@mozilla.com + - dmu@mozilla.com diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 0891ce0c3..104485692 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -53,6 +53,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; @@ -390,9 +391,11 @@ protected void onStop() { if (SettingsStore.getInstance(this).getCylinderDensity() > 0.0f) { TelemetryWrapper.queueCurvedModeActiveEvent(); + } else { } TelemetryWrapper.stop(); + GleanMetricsService.sessionStop(); } @Override @@ -953,6 +956,7 @@ void pauseGeckoViewCompositor() { mIsPresentingImmersive = true; mWindows.enterImmersiveMode(); TelemetryWrapper.startImmersive(); + GleanMetricsService.startImmersive(); PauseCompositorRunnable runnable = new PauseCompositorRunnable(); synchronized (this) { @@ -979,6 +983,7 @@ void resumeGeckoViewCompositor() { resetUIYaw(); TelemetryWrapper.uploadImmersiveToHistogram(); + GleanMetricsService.stopImmersive(); Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(() -> { mWindows.resumeCompositor(); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java index 0eab60614..5fb88c74e 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java @@ -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; @@ -954,6 +955,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); @@ -969,6 +971,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) { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/search/SearchEngineWrapper.java b/app/src/common/shared/org/mozilla/vrbrowser/search/SearchEngineWrapper.java index a87c1b5c8..947185677 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/search/SearchEngineWrapper.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/search/SearchEngineWrapper.java @@ -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 diff --git a/app/src/common/shared/org/mozilla/vrbrowser/telemetry/GleanMetricsService.java b/app/src/common/shared/org/mozilla/vrbrowser/telemetry/GleanMetricsService.java index 5e124ad55..ce334d00f 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/telemetry/GleanMetricsService.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/telemetry/GleanMetricsService.java @@ -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; @@ -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 domainMap = new HashSet(); // We should call this at the application initial stage. public static void init(Context aContext) { @@ -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); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/NavigationURLBar.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/NavigationURLBar.java index c16a9dc9a..580a93044 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/NavigationURLBar.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/NavigationURLBar.java @@ -39,6 +39,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; @@ -452,6 +453,7 @@ 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 { @@ -459,6 +461,7 @@ public void handleURLEdit(String text) { // Doing search in the URL bar, so sending "aIsURL: false" to telemetry. TelemetryWrapper.urlBarEvent(false); + GleanMetricsService.urlBarEvent(false); } if (mSession.getCurrentUri() != url) { @@ -490,6 +493,7 @@ public void setClickable(boolean clickable) { } TelemetryWrapper.voiceInputEvent(); + GleanMetricsService.voiceInputEvent(); }; private OnClickListener mClearListener = view -> { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java index 9e7b3605e..6eda45a0d 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java @@ -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; @@ -866,6 +867,7 @@ private void handleVoiceInput() { } mIsInVoiceInput = true; TelemetryWrapper.voiceInputEvent(); + GleanMetricsService.voiceInputEvent(); mVoiceSearchWidget.show(CLEAR_FOCUS); mWidgetPlacement.visible = false; mWidgetManager.updateWidget(this); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java index 5e782e54f..9746e9a5b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java @@ -39,6 +39,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; @@ -207,6 +208,7 @@ private void initialize(Context aContext) { setFocusable(true); TelemetryWrapper.openWindowEvent(mWindowId); + GleanMetricsService.openWindowEvent(mWindowId); if (mSession.getGeckoSession() != null) { onCurrentSessionChange(null, mSession.getGeckoSession()); @@ -319,6 +321,7 @@ public void onResume() { public void close() { TelemetryWrapper.closeWindowEvent(mWindowId); + GleanMetricsService.closeWindowEvent(mWindowId); hideContextMenus(); releaseWidget(); mBookmarksView.onDestroy(); diff --git a/docs/metrics.md b/docs/metrics.md index e5a1e84e4..fc2857bfe 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -11,6 +11,7 @@ Sorry about that. - [baseline](#baseline) - [events](#events) - [metrics](#metrics) + - [session_end](#session_end) ## baseline @@ -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/2241#issuecomment-557740258)||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/2241#issuecomment-557740258)|
  • type_link
  • type_query
  • voice_query
|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/2241#issuecomment-557740258)||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/2241#issuecomment-557740258)||2020-05-01 |