Skip to content

Commit

Permalink
Allow using the legacy "tagPings" on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexterp37 committed Jul 20, 2020
1 parent 743fc84 commit 920d5bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class GleanDebugActivity : Activity() {
* The value must match the pattern `[a-zA-Z0-9-]{1,20}`.
*/
const val TAG_DEBUG_VIEW_EXTRA_KEY = "debugViewTag"
const val LEGACY_TAG_PINGS = "tagPings"

/**
* Tags all outgoing pings as debug pings to make them available for real-time validation.
* The value must match the pattern `[a-zA-Z0-9-]{1,20}`.
Expand Down Expand Up @@ -74,8 +76,10 @@ class GleanDebugActivity : Activity() {
}

// Make sure that at least one of the supported commands was used.
val supportedCommands =
listOf(SEND_PING_EXTRA_KEY, LOG_PINGS_EXTRA_KEY, TAG_DEBUG_VIEW_EXTRA_KEY, SOURCE_TAGS_KEY)
val supportedCommands = listOf(
SEND_PING_EXTRA_KEY, LOG_PINGS_EXTRA_KEY,
TAG_DEBUG_VIEW_EXTRA_KEY, SOURCE_TAGS_KEY, LEGACY_TAG_PINGS
)

// Enable debugging options and start the application.
intent.extras?.let {
Expand All @@ -92,6 +96,13 @@ class GleanDebugActivity : Activity() {
// Set the debug view tag, if the tag is invalid it won't be set
debugViewTag?.let {
Glean.setDebugViewTag(debugViewTag)
} ?: run {
// If the 'debugViewTag' was not used, try to look for the legacy
// way of setting debug view tags. We should leave this block of
// code around at most until December 2020.
intent.getStringExtra(LEGACY_TAG_PINGS)?.let { legacyTag ->
Glean.setDebugViewTag(legacyTag)
}
}

val logPings: Boolean? = intent.getBooleanExtra(LOG_PINGS_EXTRA_KEY, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,35 +198,33 @@ class GleanDebugActivityTest {
}

@Test
fun `pings are correctly tagged using debugViewTag`() {
val pingTag = "test-debug-ID"
fun `pings are correctly tagged using legacy tagPings`() {
val pingTag = "legacy-debug-ID"

// Use the test client in the Glean configuration
val context = ApplicationProvider.getApplicationContext<Context>()
resetGlean(context, Glean.configuration.copy(
httpClient = TestPingTagClient(debugHeaderValue = pingTag)
))

// Put some metric data in the store, otherwise we won't get a ping out
// Define a 'booleanMetric' boolean metric, which will be stored in "store1"
val booleanMetric = BooleanMetricType(
disabled = false,
category = "telemetry",
lifetime = Lifetime.Application,
name = "boolean_metric",
sendInPings = listOf("metrics")
// Create a custom ping for testing. Since we're testing headers,
// it's fine for this to be empty.
val customPing = PingType<NoReasonCodes>(
name = "custom",
includeClientId = false,
sendIfEmpty = true,
reasonCodes = listOf()
)

booleanMetric.set(true)
assertTrue(booleanMetric.testHasValue())

// Set the extra values and start the intent.
val intent = Intent(ApplicationProvider.getApplicationContext<Context>(),
GleanDebugActivity::class.java)
intent.putExtra(GleanDebugActivity.SEND_PING_EXTRA_KEY, "metrics")
intent.putExtra(GleanDebugActivity.TAG_DEBUG_VIEW_EXTRA_KEY, pingTag)
intent.putExtra(GleanDebugActivity.LEGACY_TAG_PINGS, pingTag)
launch<GleanDebugActivity>(intent)

customPing.submit()

// This will trigger the call to `fetch()` in the TestPingTagClient which is where the
// test assertions will occur
triggerWorkManager(context)
Expand Down

0 comments on commit 920d5bb

Please sign in to comment.