Skip to content

Commit ff2cb6a

Browse files
Bug 1914027 - Add more ping types in Glean Debug Tools r=android-reviewers,boek
Differential Revision: https://phabricator.services.mozilla.com/D234395
1 parent 9b9d834 commit ff2cb6a

File tree

7 files changed

+92
-213
lines changed

7 files changed

+92
-213
lines changed

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/gleandebugtools/GleanDebugToolsMiddleware.kt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package org.mozilla.fenix.debugsettings.gleandebugtools
77
import mozilla.components.lib.state.Middleware
88
import mozilla.components.lib.state.MiddlewareContext
99
import mozilla.components.support.ktx.kotlin.urlEncode
10-
import org.mozilla.fenix.R
1110
import org.mozilla.fenix.utils.ClipboardHandler
1211

1312
internal const val PING_PREVIEW_URL = "https://debug-ping-preview.firebaseapp.com/"
@@ -24,7 +23,7 @@ class GleanDebugToolsMiddleware(
2423
private val gleanDebugToolsStorage: GleanDebugToolsStorage,
2524
private val clipboardHandler: ClipboardHandler,
2625
private val openDebugView: (String) -> Unit,
27-
private val showToast: (Int) -> Unit,
26+
private val showToast: (String) -> Unit,
2827
) : Middleware<GleanDebugToolsState, GleanDebugToolsAction> {
2928
override fun invoke(
3029
context: MiddlewareContext<GleanDebugToolsState, GleanDebugToolsAction>,
@@ -51,24 +50,14 @@ class GleanDebugToolsMiddleware(
5150
clipboardHandler.text = debugViewLink
5251
}
5352
is GleanDebugToolsAction.DebugViewTagChanged -> {} // No-op
54-
is GleanDebugToolsAction.SendBaselinePing -> {
55-
gleanDebugToolsStorage.sendBaselinePing(
53+
is GleanDebugToolsAction.SendPing -> {
54+
gleanDebugToolsStorage.sendPing(
55+
pingType = context.state.pingType,
5656
debugViewTag = context.state.debugViewTag,
5757
)
58-
showToast(R.string.glean_debug_tools_send_baseline_ping_toast_message)
59-
}
60-
is GleanDebugToolsAction.SendMetricsPing -> {
61-
gleanDebugToolsStorage.sendMetricsPing(
62-
debugViewTag = context.state.debugViewTag,
63-
)
64-
showToast(R.string.glean_debug_tools_send_metrics_ping_toast_message)
65-
}
66-
is GleanDebugToolsAction.SendPendingEventPing -> {
67-
gleanDebugToolsStorage.sendPendingEventPing(
68-
debugViewTag = context.state.debugViewTag,
69-
)
70-
showToast(R.string.glean_debug_tools_send_pending_event_ping_toast_message)
58+
showToast(context.state.pingType)
7159
}
60+
is GleanDebugToolsAction.ChangePingType -> {} // No-op
7261
}
7362
}
7463

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/gleandebugtools/GleanDebugToolsStorage.kt

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,12 @@ interface GleanDebugToolsStorage {
1717
fun setLogPings(enabled: Boolean)
1818

1919
/**
20-
* Send a baseline ping.
20+
* Send a ping.
21+
*
22+
* @param pingType The type of ping to submit.
23+
* @param debugViewTag The debug tag to use for the ping.
2124
*/
22-
fun sendBaselinePing(debugViewTag: String)
23-
24-
/**
25-
* Send a metrics ping.
26-
*/
27-
fun sendMetricsPing(debugViewTag: String)
28-
29-
/**
30-
* Send a pending event ping.
31-
*/
32-
fun sendPendingEventPing(debugViewTag: String)
25+
fun sendPing(pingType: String, debugViewTag: String)
3326
}
3427

3528
/**
@@ -40,18 +33,21 @@ class DefaultGleanDebugToolsStorage : GleanDebugToolsStorage {
4033
Glean.setLogPings(enabled)
4134
}
4235

43-
override fun sendBaselinePing(debugViewTag: String) {
36+
override fun sendPing(pingType: String, debugViewTag: String) {
4437
Glean.setDebugViewTag(debugViewTag)
45-
Glean.submitPingByName("baseline")
38+
Glean.submitPingByName(pingType)
4639
}
4740

48-
override fun sendMetricsPing(debugViewTag: String) {
49-
Glean.setDebugViewTag(debugViewTag)
50-
Glean.submitPingByName("metrics")
51-
}
52-
53-
override fun sendPendingEventPing(debugViewTag: String) {
54-
Glean.setDebugViewTag(debugViewTag)
55-
Glean.submitPingByName("events")
41+
/**
42+
* @see [DefaultGleanDebugToolsStorage].
43+
*/
44+
companion object {
45+
46+
/**
47+
* Get all the types of pings that can be submitted.
48+
*/
49+
fun getPingTypes(): Set<String> {
50+
return Glean.getRegisteredPingNames()
51+
}
5652
}
5753
}

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/gleandebugtools/GleanDebugToolsStore.kt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ import mozilla.components.lib.state.UiStore
1414
*
1515
* @property logPingsToConsoleEnabled Whether logging pings to console is enabled.
1616
* @property debugViewTag The debug view tag of the ping.
17+
* @property pingType The selected ping to be submitted.
18+
* @property pingTypes The types of pings that can be submitted.
1719
*/
1820
data class GleanDebugToolsState(
1921
val logPingsToConsoleEnabled: Boolean,
2022
val debugViewTag: String,
23+
val pingType: String = "metrics",
24+
val pingTypes: List<String> = DefaultGleanDebugToolsStorage.getPingTypes().sorted(),
2125
) : State {
2226

2327
/**
@@ -51,19 +55,14 @@ sealed class GleanDebugToolsAction : Action {
5155
data class DebugViewTagChanged(val newTag: String) : GleanDebugToolsAction()
5256

5357
/**
54-
* Send a pending event ping.
58+
* Change the type of ping to submit to [newPing].
5559
*/
56-
data object SendPendingEventPing : GleanDebugToolsAction()
60+
data class ChangePingType(val newPing: String) : GleanDebugToolsAction()
5761

5862
/**
59-
* Send a baseline ping.
63+
* Send the ping.
6064
*/
61-
data object SendBaselinePing : GleanDebugToolsAction()
62-
63-
/**
64-
* Send a metrics ping.
65-
*/
66-
data object SendMetricsPing : GleanDebugToolsAction()
65+
data object SendPing : GleanDebugToolsAction()
6766

6867
/**
6968
* Open the relevant debug view.
@@ -93,11 +92,10 @@ internal object GleanDebugToolsReducer {
9392
debugViewTag = action.newTag,
9493
)
9594
}
96-
is GleanDebugToolsAction.SendBaselinePing -> state
97-
is GleanDebugToolsAction.SendMetricsPing -> state
98-
is GleanDebugToolsAction.SendPendingEventPing -> state
9995
is GleanDebugToolsAction.OpenDebugView -> state
10096
is GleanDebugToolsAction.CopyDebugViewLink -> state
97+
is GleanDebugToolsAction.SendPing -> state
98+
is GleanDebugToolsAction.ChangePingType -> state.copy(pingType = action.newPing)
10199
}
102100
}
103101
}

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/gleandebugtools/ui/GleanDebugToolsScreen.kt

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import androidx.compose.ui.text.input.KeyboardType
2525
import mozilla.components.compose.base.annotation.FlexibleWindowLightDarkPreview
2626
import mozilla.components.lib.state.ext.observeAsState
2727
import org.mozilla.fenix.R
28+
import org.mozilla.fenix.compose.Dropdown
29+
import org.mozilla.fenix.compose.MenuItem
2830
import org.mozilla.fenix.compose.SwitchWithLabel
2931
import org.mozilla.fenix.compose.TextField
3032
import org.mozilla.fenix.compose.button.PrimaryButton
@@ -83,9 +85,10 @@ fun GleanDebugToolsScreen(
8385

8486
GleanDebugSendPingsSection(
8587
isButtonEnabled = gleanDebugToolsState.isDebugTagButtonEnabled,
86-
onSendPendingEventPing = { gleanDebugToolsStore.dispatch(GleanDebugToolsAction.SendPendingEventPing) },
87-
onSendBaselinePing = { gleanDebugToolsStore.dispatch(GleanDebugToolsAction.SendBaselinePing) },
88-
onSendMetricsPing = { gleanDebugToolsStore.dispatch(GleanDebugToolsAction.SendMetricsPing) },
88+
curPing = gleanDebugToolsState.pingType,
89+
pingTypes = gleanDebugToolsState.pingTypes,
90+
onPingItemClicked = { gleanDebugToolsStore.dispatch(GleanDebugToolsAction.ChangePingType(it)) },
91+
onSendPing = { gleanDebugToolsStore.dispatch(GleanDebugToolsAction.SendPing) },
8992
)
9093
}
9194
}
@@ -178,29 +181,33 @@ private fun GleanDebugViewSection(
178181
@Composable
179182
private fun GleanDebugSendPingsSection(
180183
isButtonEnabled: Boolean,
181-
onSendPendingEventPing: () -> Unit,
182-
onSendBaselinePing: () -> Unit,
183-
onSendMetricsPing: () -> Unit,
184+
curPing: String,
185+
pingTypes: List<String>,
186+
onPingItemClicked: (String) -> Unit,
187+
onSendPing: () -> Unit,
184188
) {
185189
Column(
186190
modifier = Modifier.padding(horizontal = FirefoxTheme.space.small),
187191
) {
188-
GleanTestPingButton(
189-
text = stringResource(R.string.glean_debug_tools_send_pending_event_pings_button_text),
190-
enabled = isButtonEnabled,
191-
onClick = onSendPendingEventPing,
192+
Dropdown(
193+
label = "Ping Type",
194+
placeholder = "",
195+
dropdownItems = getPingDropdownMenu(
196+
curPing = curPing,
197+
pings = pingTypes,
198+
onClickItem = onPingItemClicked,
199+
),
192200
)
193201

194-
GleanTestPingButton(
195-
text = stringResource(R.string.glean_debug_tools_send_baseline_pings_button_text),
196-
enabled = isButtonEnabled,
197-
onClick = onSendBaselinePing,
198-
)
202+
Spacer(modifier = Modifier.height(FirefoxTheme.space.small))
199203

200-
GleanTestPingButton(
201-
text = stringResource(R.string.glean_debug_tools_send_metrics_pings_button_text),
204+
PrimaryButton(
205+
text = stringResource(R.string.glean_debug_tools_send_ping_button_text),
206+
modifier = Modifier
207+
.fillMaxWidth()
208+
.padding(horizontal = FirefoxTheme.space.xxSmall),
202209
enabled = isButtonEnabled,
203-
onClick = onSendMetricsPing,
210+
onClick = onSendPing,
204211
)
205212
}
206213
}
@@ -241,28 +248,15 @@ private fun GleanDebugButton(
241248
)
242249
}
243250

244-
/**
245-
* The UI for a send test ping button on the Glean Debug Tools page.
246-
*
247-
* @param text The text on the button.
248-
* @param enabled Controls the enabled state of the list item. When `false`, the list item will not
249-
* be clickable.
250-
* @param onClick Called when the user clicks on the button.
251-
*/
252-
@Composable
253-
private fun GleanTestPingButton(
254-
text: String,
255-
enabled: Boolean,
256-
onClick: () -> Unit,
257-
) {
258-
PrimaryButton(
259-
text = text,
260-
modifier = Modifier
261-
.fillMaxWidth()
262-
.padding(horizontal = FirefoxTheme.space.xxSmall),
263-
enabled = enabled,
264-
onClick = onClick,
265-
)
251+
private fun getPingDropdownMenu(
252+
curPing: String,
253+
pings: List<String>,
254+
onClickItem: (String) -> Unit,
255+
) = pings.map {
256+
MenuItem(
257+
title = it,
258+
isChecked = it == curPing,
259+
) { onClickItem(it) }
266260
}
267261

268262
@Composable

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/ui/FenixOverlay.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import mozilla.components.compose.base.annotation.LightDarkPreview
2323
import mozilla.components.concept.storage.LoginsStorage
2424
import mozilla.components.lib.state.ext.observeAsState
2525
import mozilla.telemetry.glean.Glean
26+
import org.mozilla.fenix.R
2627
import org.mozilla.fenix.debugsettings.addresses.AddressesDebugLocalesRepository
2728
import org.mozilla.fenix.debugsettings.addresses.AddressesTools
2829
import org.mozilla.fenix.debugsettings.addresses.FakeAddressesDebugLocalesRepository
@@ -90,10 +91,13 @@ fun FenixOverlay(
9091
intent.data = Uri.parse(debugViewLink)
9192
context.startActivity(intent)
9293
},
93-
showToast = { resId ->
94+
showToast = { pingType ->
9495
val toast = Toast.makeText(
9596
context,
96-
context.getString(resId),
97+
context.getString(
98+
R.string.glean_debug_tools_send_ping_toast_message,
99+
pingType,
100+
),
97101
Toast.LENGTH_LONG,
98102
)
99103
toast.show()

mobile/android/fenix/app/src/main/res/values/static_strings.xml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,8 @@
213213
<string name="glean_debug_tools_open_debug_view">Open debug view (in default browser)</string>
214214
<!-- The copy debug view link button text in Glean debug tools -->
215215
<string name="glean_debug_tools_copy_debug_view_link">Copy debug view link</string>
216-
<!-- The send pending event pings button text in Glean debug tools -->
217-
<string name="glean_debug_tools_send_pending_event_pings_button_text">Send pending event pings</string>
218-
<!-- The send baseline event pings button text in Glean debug tools -->
219-
<string name="glean_debug_tools_send_baseline_pings_button_text">Send baseline pings</string>
220-
<!-- The send metrics event pings button text in Glean debug tools -->
221-
<string name="glean_debug_tools_send_metrics_pings_button_text">Send metrics pings</string>
222-
<!-- The send pending event pings toast message -->
223-
<string name="glean_debug_tools_send_pending_event_ping_toast_message">Sent pending event ping</string>
224-
<!-- The send baseline pings toast message -->
225-
<string name="glean_debug_tools_send_baseline_ping_toast_message">Sent baseline ping</string>
226-
<!-- The send metrics pings toast message -->
227-
<string name="glean_debug_tools_send_metrics_ping_toast_message">Sent metrics ping</string>
216+
<!-- The send ping button text in Glean debug tools -->
217+
<string name="glean_debug_tools_send_ping_button_text">Send Ping</string>
218+
<!-- The send pings toast message. The first parameter is the type of ping -->
219+
<string name="glean_debug_tools_send_ping_toast_message">Sent %1$s ping</string>
228220
</resources>

0 commit comments

Comments
 (0)