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 15, 2019
1 parent 6aa65ec commit cae4ae1
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 1 deletion.
103 changes: 103 additions & 0 deletions app/metrics.yaml
Expand Up @@ -16,10 +16,113 @@ 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
send_in_pings:
- session_end
description: >
Counting how many URLs are visited in a session, 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"
controls:
tray_new_window:
type: counter
lifetime: ping
description: >
Counting how many times users open new windows.
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"
context_menu_long_pressed:
type: counter
lifetime: ping
description: >
Counting how many times users do a long press on the context menu.
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"
curve_mode_actived:
type: boolean
lifetime: ping
description: >
Counting how many users are using the curved mode.
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
lifetime: ping
description: >
Counting how many searches are queried in a specific search engine.
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,13 @@ protected void onStop() {

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

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

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

synchronized (this) {
Expand All @@ -944,6 +950,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 @@ -5,11 +5,20 @@

import androidx.annotation.UiThread;

import org.mozilla.vrbrowser.GleanMetrics.Controls;
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 +27,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 +63,103 @@ 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);
}

@UiThread
public static void trayNewWindowEvent() {
Controls.INSTANCE.getTrayNewWindow().add();
}

public static void longPressContextMenuEvent() {
Controls.INSTANCE.getContextMenuLongPressed().add();
}

// 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.");
// }
}

public static void curveModeActiveEvent(boolean aEnabled) {
Controls.INSTANCE.getCurveModeActived().set(aEnabled);
}

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

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 @@ -25,6 +25,7 @@
import org.mozilla.vrbrowser.browser.SessionChangeListener;
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.views.UIButton;
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsWidget;
Expand Down Expand Up @@ -152,6 +153,7 @@ private void initialize(Context aContext) {
view.requestFocusFromTouch();

TelemetryWrapper.trayNewWindowEvent();
GleanMetricsService.trayNewWindowEvent();

notifyAddWindowClicked();
});
Expand Down

0 comments on commit cae4ae1

Please sign in to comment.