From ad4f29474e199ee73ce783cc78a4f7b3e8181544 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Thu, 4 Mar 2021 21:29:19 +0200 Subject: [PATCH] For #17869 - New AndroidKeystoreExperiment telemetry --- app/metrics.yaml | 101 ++++++++++++++++++ .../mozilla/fenix/components/metrics/Event.kt | 20 ++++ .../components/metrics/GleanMetricsService.kt | 24 +++++ .../components/metrics/MetricController.kt | 22 ++++ docs/metrics.md | 10 +- 5 files changed, 175 insertions(+), 2 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 53e09d98e..d2c763aca 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -4533,3 +4533,104 @@ engine: - fenix-core@mozilla.com - skaspari@mozilla.com expires: "2021-12-31" + +android_keystore_experiment: + experiment_failure: + type: event + description: | + Records an instance of an unexpected failure during the experiment + extra_keys: + failure_exception: + description: | + Exception class associated with an unexpected failure of this + experiment, not caught by the other failure handlers. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/17869 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395 + data_sensitivity: + - technical + notification_emails: + - fenix-core@mozilla.com + expires: "2021-09-01" + get_failure: + type: event + description: | + Unexpected failure when trying to read from secure prefs. + extra_keys: + failure_exception: + description: | + Exception class associated with an unexpected failure of this + experiment. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/17869 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395 + data_sensitivity: + - technical + notification_emails: + - fenix-core@mozilla.com + expires: "2021-09-01" + get_result: + type: event + description: | + Success when trying to read from secure prefs. + extra_keys: + result: + description: | + Result code identifying whether the read operation returned the + expected value or not. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/17869 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395 + data_sensitivity: + - technical + notification_emails: + - fenix-core@mozilla.com + expires: "2021-09-01" + write_failure: + type: event + description: | + Unexpected failure when trying to write to secure prefs. + extra_keys: + failure_exception: + description: | + Exception class associated with an unexpected failure of this + experiment. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/17869 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395 + data_sensitivity: + - technical + notification_emails: + - fenix-core@mozilla.com + expires: "2021-09-01" + write_success: + type: event + description: | + Success in writing to secure prefs. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/17869 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395 + data_sensitivity: + - technical + notification_emails: + - fenix-core@mozilla.com + expires: "2021-09-01" + reset: + type: event + description: | + An experiment failed, and was reset to run again in the future from a + blank state. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/17869 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395 + data_sensitivity: + - technical + notification_emails: + - fenix-core@mozilla.com + expires: "2021-09-01" diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt index c7e2431ea..1f0b41d4c 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt @@ -9,6 +9,7 @@ import mozilla.components.browser.errorpages.ErrorType import mozilla.components.browser.state.search.SearchEngine import mozilla.components.feature.top.sites.TopSite import org.mozilla.fenix.GleanMetrics.Addons +import org.mozilla.fenix.GleanMetrics.AndroidKeystoreExperiment import org.mozilla.fenix.GleanMetrics.AppTheme import org.mozilla.fenix.GleanMetrics.Autoplay import org.mozilla.fenix.GleanMetrics.Collections @@ -221,6 +222,25 @@ sealed class Event { get() = hashMapOf(TopSites.swipeCarouselKeys.page to page.toString()) } + data class SecurePrefsExperimentFailure(val failureException: String) : Event() { + override val extras = + mapOf(AndroidKeystoreExperiment.experimentFailureKeys.failureException to failureException) + } + data class SecurePrefsGetFailure(val failureException: String) : Event() { + override val extras = + mapOf(AndroidKeystoreExperiment.getFailureKeys.failureException to failureException) + } + data class SecurePrefsGetSuccess(val successCode: String) : Event() { + override val extras = + mapOf(AndroidKeystoreExperiment.getResultKeys.result to successCode) + } + data class SecurePrefsWriteFailure(val failureException: String) : Event() { + override val extras = + mapOf(AndroidKeystoreExperiment.writeFailureKeys.failureException to failureException) + } + object SecurePrefsWriteSuccess : Event() + object SecurePrefsReset : Event() + data class TopSiteLongPress(val type: TopSite.Type) : Event() { override val extras: Map? get() = hashMapOf(TopSites.longPressKeys.type to type.name) diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt index d122d34a7..d28e40d21 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt @@ -15,6 +15,7 @@ import mozilla.components.support.base.log.logger.Logger import org.mozilla.fenix.Config import org.mozilla.fenix.GleanMetrics.AboutPage import org.mozilla.fenix.GleanMetrics.Addons +import org.mozilla.fenix.GleanMetrics.AndroidKeystoreExperiment import org.mozilla.fenix.GleanMetrics.AppTheme import org.mozilla.fenix.GleanMetrics.Autoplay import org.mozilla.fenix.GleanMetrics.BannerOpenInApp @@ -750,6 +751,29 @@ private val Event.wrapper: EventWrapper<*>? { BannerOpenInApp.goToSettings.record(it) } ) + is Event.SecurePrefsExperimentFailure -> EventWrapper( + { AndroidKeystoreExperiment.experimentFailure.record(it) }, + { AndroidKeystoreExperiment.experimentFailureKeys.valueOf(it) } + ) + is Event.SecurePrefsGetFailure -> EventWrapper( + { AndroidKeystoreExperiment.getFailure.record(it) }, + { AndroidKeystoreExperiment.getFailureKeys.valueOf(it) } + ) + is Event.SecurePrefsGetSuccess -> EventWrapper( + { AndroidKeystoreExperiment.getResult.record(it) }, + { AndroidKeystoreExperiment.getResultKeys.valueOf(it) } + ) + is Event.SecurePrefsWriteFailure -> EventWrapper( + { AndroidKeystoreExperiment.writeFailure.record(it) }, + { AndroidKeystoreExperiment.writeFailureKeys.valueOf(it) } + ) + is Event.SecurePrefsWriteSuccess -> EventWrapper( + { AndroidKeystoreExperiment.writeSuccess.record(it) } + ) + is Event.SecurePrefsReset -> EventWrapper( + { AndroidKeystoreExperiment.reset.record(it) } + ) + // Don't record other events in Glean: is Event.AddBookmark -> null is Event.OpenedBookmark -> null diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt index 013fd2422..7f9aed10a 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt @@ -23,6 +23,7 @@ import mozilla.components.feature.media.facts.MediaFacts import mozilla.components.feature.prompts.dialog.LoginDialogFacts import mozilla.components.feature.pwa.ProgressiveWebAppFacts import mozilla.components.feature.top.sites.facts.TopSitesFacts +import mozilla.components.lib.dataprotect.SecurePrefsReliabilityExperiment import mozilla.components.support.base.Component import mozilla.components.support.base.facts.Action import mozilla.components.support.base.facts.Fact @@ -76,6 +77,7 @@ internal class DebugMetricController( } @VisibleForTesting +@Suppress("LargeClass") internal class ReleaseMetricController( private val services: List, private val isDataTelemetryEnabled: () -> Boolean, @@ -267,6 +269,26 @@ internal class ReleaseMetricController( } null } + Component.LIB_DATAPROTECT to SecurePrefsReliabilityExperiment.Companion.Actions.EXPERIMENT -> { + Event.SecurePrefsExperimentFailure(metadata?.get("javaClass") as String? ?: "null") + } + Component.LIB_DATAPROTECT to SecurePrefsReliabilityExperiment.Companion.Actions.GET -> { + if (SecurePrefsReliabilityExperiment.Companion.Values.FAIL.v == value?.toInt()) { + Event.SecurePrefsGetFailure(metadata?.get("javaClass") as String? ?: "null") + } else { + Event.SecurePrefsGetSuccess(value ?: "") + } + } + Component.LIB_DATAPROTECT to SecurePrefsReliabilityExperiment.Companion.Actions.WRITE -> { + if (SecurePrefsReliabilityExperiment.Companion.Values.FAIL.v == value?.toInt()) { + Event.SecurePrefsWriteFailure(metadata?.get("javaClass") as String? ?: "null") + } else { + Event.SecurePrefsWriteSuccess + } + } + Component.LIB_DATAPROTECT to SecurePrefsReliabilityExperiment.Companion.Actions.RESET -> { + Event.SecurePrefsReset + } else -> null } diff --git a/docs/metrics.md b/docs/metrics.md index 4412b58ab..0c988a1d7 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -52,6 +52,12 @@ The following metrics are added to the ping: | about_page.support_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped on "Support" item from About page |[1](https://github.com/mozilla-mobile/fenix/pull/8047), [2](https://github.com/mozilla-mobile/fenix/pull/13958#issuecomment-676857877)||2021-04-01 |2 | | addons.open_addon_in_toolbar_menu |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user interacted with an installed add-on in the toolbar menu |[1](https://github.com/mozilla-mobile/fenix/pull/8318), [2](https://github.com/mozilla-mobile/fenix/pull/13958#issuecomment-676857877)|
  • addon_id: The id of the add-on that was interacted with in the toolbar menu
|2021-04-01 |2 | | addons.open_addons_in_settings |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user accessed "Add-ons" from the Settings |[1](https://github.com/mozilla-mobile/fenix/pull/8318), [2](https://github.com/mozilla-mobile/fenix/pull/13958#issuecomment-676857877)||2021-04-01 |2 | +| android_keystore_experiment.experiment_failure |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |Records an instance of an unexpected failure during the experiment |[1](https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395)|
  • failure_exception: Exception class associated with an unexpected failure of this experiment, not caught by the other failure handlers.
|2021-09-01 |1 | +| android_keystore_experiment.get_failure |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |Unexpected failure when trying to read from secure prefs. |[1](https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395)|
  • failure_exception: Exception class associated with an unexpected failure of this experiment.
|2021-09-01 |1 | +| android_keystore_experiment.get_result |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |Success when trying to read from secure prefs. |[1](https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395)|
  • result: Result code identifying whether the read operation returned the expected value or not.
|2021-09-01 |1 | +| android_keystore_experiment.reset |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |An experiment failed, and was reset to run again in the future from a blank state. |[1](https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395)||2021-09-01 |1 | +| android_keystore_experiment.write_failure |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |Unexpected failure when trying to write to secure prefs. |[1](https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395)|
  • failure_exception: Exception class associated with an unexpected failure of this experiment.
|2021-09-01 |1 | +| android_keystore_experiment.write_success |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |Success in writing to secure prefs. |[1](https://github.com/mozilla-mobile/fenix/pull/18333#pullrequestreview-612447395)||2021-09-01 |1 | | app_theme.dark_theme_selected |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user selected Dark Theme |[1](https://github.com/mozilla-mobile/fenix/pull/7968), [2](https://github.com/mozilla-mobile/fenix/pull/13958#issuecomment-676857877)|
  • source: The source from where dark theme was selected. The source can be 'SETTINGS' or 'ONBOARDING'
|2021-04-01 |2 | | autoplay.setting_changed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user changed their autoplay setting to either block_cellular, block_audio, or block_all. |[1](https://github.com/mozilla-mobile/fenix/pull/13041#issuecomment-665777411)|
  • autoplay_setting: The new setting for autoplay: block_cellular, block_audio, or block_all.
|2021-08-01 |2 | | autoplay.visited_setting |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user visited the autoplay settings screen |[1](https://github.com/mozilla-mobile/fenix/pull/13041#issuecomment-665777411)||2021-08-01 |2 | @@ -315,8 +321,8 @@ The following metrics are added to the ping: | perf.awesomebar.session_suggestions |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Duration of a session awesomebar suggestion query. |[1](https://github.com/mozilla-mobile/fenix/pull/10276#pullrequestreview-411101979)||2020-11-15 |1, 2 | | perf.awesomebar.shortcuts_suggestions |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Duration of a shortcuts awesomebar suggestion query. |[1](https://github.com/mozilla-mobile/fenix/pull/10276#pullrequestreview-411101979)||2020-11-15 |1, 2 | | perf.awesomebar.synced_tabs_suggestions |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Duration of a synced tabs awesomebar suggestion query. |[1](https://github.com/mozilla-mobile/fenix/pull/10276#pullrequestreview-411101979)||2020-11-15 |1, 2 | -| perf.startup.application_on_create |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |The duration of `FenixApplication.onCreate` in the main process. |[1](todo)||2021-08-11 |1 | -| perf.startup.home_activity_on_create |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |The duration of `HomeActivity.onCreate`. |[1](todo)||2021-08-11 |1 | +| perf.startup.application_on_create |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |The duration of `FenixApplication.onCreate` in the main process. |[1](https://github.com/mozilla-mobile/fenix/pull/17973#issue-572183889)||2021-08-11 |1 | +| perf.startup.home_activity_on_create |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |The duration of `HomeActivity.onCreate`. |[1](https://github.com/mozilla-mobile/fenix/pull/17973#issue-572183889)||2021-08-11 |1 | | preferences.accessibility_services |[string_list](https://mozilla.github.io/glean/book/user/metrics/string_list.html) |Whether or not the user has touch exploration or switch services enabled. These are built into the Android OS, not Fenix prefs. default: "" |[1](https://github.com/mozilla-mobile/fenix/pull/11211), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | | preferences.open_links_in_a_private_tab |[string_list](https://mozilla.github.io/glean/book/user/metrics/string_list.html) |Whether or not the user has enabled open links in a private tab. default: false |[1](https://github.com/mozilla-mobile/fenix/pull/11211), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | | preferences.open_links_in_app |[string_list](https://mozilla.github.io/glean/book/user/metrics/string_list.html) |Whether or not the user has the open links in apps feature enabled. default: false |[1](https://github.com/mozilla-mobile/fenix/pull/11446), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |