Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Fix metric types of engine telemetry. #18115

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4482,8 +4482,8 @@ contextual_menu:
- [email protected]
expires: "2021-06-01"

engine:
tab_kills:
engine_tab:
kills:
type: labeled_counter
labels:
- foreground
Expand All @@ -4502,7 +4502,7 @@ engine:
- [email protected]
expires: "2021-12-31"
kill_foreground_age:
type: timespan
type: timing_distribution
time_unit: millisecond
description: |
Measures the age of the engine session of a foreground (selected) tab
Expand All @@ -4518,7 +4518,7 @@ engine:
- [email protected]
expires: "2021-12-31"
kill_background_age:
type: timespan
type: timing_distribution
time_unit: millisecond
description: |
Measures the age of the engine session of a background tab at the
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/org/mozilla/fenix/TelemetryMiddleware.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.search.telemetry.ads.AdsTelemetry
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.GleanMetrics.Engine as EngineMetrics
import org.mozilla.fenix.GleanMetrics.EngineTab as EngineMetrics

/**
* [Middleware] to record telemetry in response to [BrowserAction]s.
Expand Down Expand Up @@ -138,24 +138,24 @@ class TelemetryMiddleware(
}

val isSelected = tab.id == state.selectedTabId
val ageNanos = tab.engineState.ageNanos()
val age = tab.engineState.age()

// Increment the counter of killed foreground/background tabs
val tabKillLabel = if (isSelected) { "foreground" } else { "background" }
EngineMetrics.tabKills[tabKillLabel].add()
EngineMetrics.kills[tabKillLabel].add()

// Record the age of the engine session of the killed foreground/background tab.
if (isSelected && ageNanos != null) {
EngineMetrics.killForegroundAge.setRawNanos(ageNanos)
} else if (ageNanos != null) {
EngineMetrics.killBackgroundAge.setRawNanos(ageNanos)
if (isSelected && age != null) {
EngineMetrics.killForegroundAge.accumulateSamples(listOf(age).toLongArray())
} else if (age != null) {
EngineMetrics.killBackgroundAge.accumulateSamples(listOf(age).toLongArray())
}
}
}

@Suppress("MagicNumber")
private fun EngineState.ageNanos(): Long? {
private fun EngineState.age(): Long? {
val timestamp = (timestamp ?: return null)
val now = Clock.elapsedRealtime()
return (now - timestamp) * 1_000_000
return (now - timestamp)
}
47 changes: 24 additions & 23 deletions app/src/test/java/org/mozilla/fenix/TelemetryMiddlewareTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import mozilla.components.support.test.mock
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -38,7 +39,7 @@ import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.search.telemetry.ads.AdsTelemetry
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.GleanMetrics.Engine as EngineMetrics
import org.mozilla.fenix.GleanMetrics.EngineTab as EngineMetrics

@RunWith(FenixRobolectricTestRunner::class)
@ExperimentalCoroutinesApi
Expand Down Expand Up @@ -284,14 +285,14 @@ class TelemetryMiddlewareTest {
selectedTabId = "foreground"
)).joinBlocking()

Assert.assertFalse(EngineMetrics.tabKills["foreground"].testHasValue())
Assert.assertFalse(EngineMetrics.tabKills["background"].testHasValue())
assertFalse(EngineMetrics.kills["foreground"].testHasValue())
assertFalse(EngineMetrics.kills["background"].testHasValue())

store.dispatch(
EngineAction.KillEngineSessionAction("foreground")
).joinBlocking()

Assert.assertTrue(EngineMetrics.tabKills["foreground"].testHasValue())
assertTrue(EngineMetrics.kills["foreground"].testHasValue())
}

@Test
Expand All @@ -305,24 +306,24 @@ class TelemetryMiddlewareTest {
selectedTabId = "foreground"
)).joinBlocking()

Assert.assertFalse(EngineMetrics.tabKills["foreground"].testHasValue())
Assert.assertFalse(EngineMetrics.tabKills["background"].testHasValue())
assertFalse(EngineMetrics.kills["foreground"].testHasValue())
assertFalse(EngineMetrics.kills["background"].testHasValue())

store.dispatch(
EngineAction.KillEngineSessionAction("background_pocket")
).joinBlocking()

Assert.assertFalse(EngineMetrics.tabKills["foreground"].testHasValue())
Assert.assertTrue(EngineMetrics.tabKills["background"].testHasValue())
assertEquals(1, EngineMetrics.tabKills["background"].testGetValue())
assertFalse(EngineMetrics.kills["foreground"].testHasValue())
assertTrue(EngineMetrics.kills["background"].testHasValue())
assertEquals(1, EngineMetrics.kills["background"].testGetValue())

store.dispatch(
EngineAction.KillEngineSessionAction("background_verge")
).joinBlocking()

Assert.assertFalse(EngineMetrics.tabKills["foreground"].testHasValue())
Assert.assertTrue(EngineMetrics.tabKills["background"].testHasValue())
assertEquals(2, EngineMetrics.tabKills["background"].testGetValue())
assertFalse(EngineMetrics.kills["foreground"].testHasValue())
assertTrue(EngineMetrics.kills["background"].testHasValue())
assertEquals(2, EngineMetrics.kills["background"].testGetValue())
}

@Test
Expand All @@ -343,18 +344,18 @@ class TelemetryMiddlewareTest {
engineSession = mock()
)).joinBlocking()

Assert.assertFalse(EngineMetrics.killForegroundAge.testHasValue())
Assert.assertFalse(EngineMetrics.killBackgroundAge.testHasValue())
assertFalse(EngineMetrics.killForegroundAge.testHasValue())
assertFalse(EngineMetrics.killBackgroundAge.testHasValue())

clock.elapsedTime = 500

store.dispatch(
EngineAction.KillEngineSessionAction("foreground")
).joinBlocking()

Assert.assertTrue(EngineMetrics.killForegroundAge.testHasValue())
Assert.assertFalse(EngineMetrics.killBackgroundAge.testHasValue())
assertEquals(400, EngineMetrics.killForegroundAge.testGetValue())
assertTrue(EngineMetrics.killForegroundAge.testHasValue())
assertFalse(EngineMetrics.killBackgroundAge.testHasValue())
assertEquals(400_000_000, EngineMetrics.killForegroundAge.testGetValue().sum)
}

@Test
Expand All @@ -377,16 +378,16 @@ class TelemetryMiddlewareTest {

clock.elapsedTime = 700

Assert.assertFalse(EngineMetrics.killForegroundAge.testHasValue())
Assert.assertFalse(EngineMetrics.killBackgroundAge.testHasValue())
assertFalse(EngineMetrics.killForegroundAge.testHasValue())
assertFalse(EngineMetrics.killBackgroundAge.testHasValue())

store.dispatch(
EngineAction.KillEngineSessionAction("background_pocket")
).joinBlocking()

Assert.assertTrue(EngineMetrics.killBackgroundAge.testHasValue())
Assert.assertFalse(EngineMetrics.killForegroundAge.testHasValue())
assertEquals(600, EngineMetrics.killBackgroundAge.testGetValue())
assertTrue(EngineMetrics.killBackgroundAge.testHasValue())
assertFalse(EngineMetrics.killForegroundAge.testHasValue())
assertEquals(600_000_000, EngineMetrics.killBackgroundAge.testGetValue().sum)
}
}

Expand Down
10 changes: 5 additions & 5 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ The following metrics are added to the ping:
| browser.search.ad_clicks |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Records clicks of adverts on SERP pages. The key format is ‘<provider-name>’. |[1](https://github.com/mozilla-mobile/fenix/pull/10112), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
| browser.search.in_content |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Records the type of interaction a user has on SERP pages. |[1](https://github.com/mozilla-mobile/fenix/pull/10167), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
| browser.search.with_ads |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Records counts of SERP pages with adverts displayed. The key format is ‘<provider-name>’. |[1](https://github.com/mozilla-mobile/fenix/pull/10112), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
| engine.kill_background_age |[timespan](https://mozilla.github.io/glean/book/user/metrics/timespan.html) |Measures the age of the engine session of a background tab at the time its content process got killed. |[1](https://github.com/mozilla-mobile/fenix/pull/17864)||2021-12-31 |1 |
| engine.kill_foreground_age |[timespan](https://mozilla.github.io/glean/book/user/metrics/timespan.html) |Measures the age of the engine session of a foreground (selected) tab at the time its content process got killed. |[1](TBD)||2021-12-31 |1 |
| engine.tab_kills |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |How often was the content process of a foreground (selected) or background tab killed. |[1](https://github.com/mozilla-mobile/fenix/pull/17864)|<ul><li>foreground</li><li>background</li></ul>|2021-12-31 |1 |
| engine_tab.kill_background_age |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measures the age of the engine session of a background tab at the time its content process got killed. |[1](https://github.com/mozilla-mobile/fenix/pull/17864)||2021-12-31 |1 |
| engine_tab.kill_foreground_age |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measures the age of the engine session of a foreground (selected) tab at the time its content process got killed. |[1](TBD)||2021-12-31 |1 |
| engine_tab.kills |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |How often was the content process of a foreground (selected) or background tab killed. |[1](https://github.com/mozilla-mobile/fenix/pull/17864)|<ul><li>foreground</li><li>background</li></ul>|2021-12-31 |1 |
| events.normal_and_private_uri_count |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |A counter of URIs visited by the user in the current session, including page reloads. This includes private browsing. This does not include background page requests and URIs from embedded pages but may be incremented without user interaction by website scripts that programmatically redirect to a new location. |[1](https://github.com/mozilla-mobile/fenix/pull/17935)||2022-08-01 |2 |
| events.total_uri_count |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |A counter of URIs visited by the user in the current session, including page reloads. This does not include background page requests and URIs from embedded pages or private browsing but may be incremented without user interaction by website scripts that programmatically redirect to a new location. |[1](https://github.com/mozilla-mobile/fenix/pull/1785), [2](https://github.com/mozilla-mobile/fenix/pull/8314), [3](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
| metrics.adjust_ad_group |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |A string containing the Adjust ad group ID from which the user installed Fenix. This will not send on the first session the user runs. If the install is organic, this will be empty. |[1](https://github.com/mozilla-mobile/fenix/pull/9253), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
Expand Down Expand Up @@ -315,8 +315,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 |
Expand Down