Skip to content
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
3 changes: 3 additions & 0 deletions firebase-dataconnect/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
[#8446](https://github.com/firebase/firebase-android-sdk/pull/8446),
[#8456](https://github.com/firebase/firebase-android-sdk/pull/8456),
[#8460](https://github.com/firebase/firebase-android-sdk/pull/8460))
- [changed] Add grpc request headers for platform name and sdk version
to enable metrics collection in cloud monitoring.
([#8486](https://github.com/firebase/firebase-android-sdk/pull/8486))

# 17.3.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,23 @@ class GrpcMetadataIntegrationTest : DataConnectIntegrationTestBase() {
val expectedAppId = getFirebaseAppIdFromStrings()

metadata.asClue {
metadata.keys().shouldContainAll(googRequestParamsHeader.name(), googApiClientHeader.name())
metadata
.keys()
.shouldContainAll(
googRequestParamsHeader.name(),
googApiClientHeader.name(),
clientPlatformHeader.name(),
clientVersionHeader.name(),
)
assertSoftly {
// Do not verify "x-firebase-auth-token" here since that header is effectively tested by
// AuthIntegrationTest
metadata.get(googRequestParamsHeader) shouldBe
"location=${dataConnect.config.location}&frontend=data"
metadata.get(googApiClientHeader) shouldBe expectedGoogApiClientHeader(isFromGeneratedSdk)
metadata.get(gmpAppIdHeader) shouldBe expectedAppId
metadata.get(clientPlatformHeader) shouldBe "android"
metadata.get(clientVersionHeader) shouldBe BuildConfig.VERSION_NAME
}
}
}
Expand Down Expand Up @@ -469,6 +478,12 @@ class GrpcMetadataIntegrationTest : DataConnectIntegrationTestBase() {
val googApiClientHeader: Metadata.Key<String> =
Metadata.Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER)

val clientPlatformHeader: Metadata.Key<String> =
Metadata.Key.of("x-client-platform", Metadata.ASCII_STRING_MARSHALLER)

val clientVersionHeader: Metadata.Key<String> =
Metadata.Key.of("x-client-version", Metadata.ASCII_STRING_MARSHALLER)

private val gmpAppIdHeader: Metadata.Key<String> =
Metadata.Key.of("x-firebase-gmpid", Metadata.ASCII_STRING_MARSHALLER)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ internal class DataConnectGrpcMetadata(
Metadata().also {
it.put(googRequestParamsHeader, googRequestParamsHeaderValue)
it.put(googApiClientHeader, googApiClientHeaderValue(callerSdkType))
it.put(clientPlatformHeader, "android")
it.put(clientVersionHeader, dataConnectSdkVersion)
if (appId.isNotBlank()) {
it.put(gmpAppIdHeader, appId)
}
Expand Down Expand Up @@ -182,6 +184,12 @@ internal class DataConnectGrpcMetadata(
private val googApiClientHeader: Metadata.Key<String> =
Metadata.Key.of(GOOG_API_CLIENT_HEADER, Metadata.ASCII_STRING_MARSHALLER)

private val clientPlatformHeader: Metadata.Key<String> =
Metadata.Key.of("x-client-platform", Metadata.ASCII_STRING_MARSHALLER)

private val clientVersionHeader: Metadata.Key<String> =
Metadata.Key.of("x-client-version", Metadata.ASCII_STRING_MARSHALLER)

@Suppress("SpellCheckingInspection")
private val gmpAppIdHeader: Metadata.Key<String> =
Metadata.Key.of("x-firebase-gmpid", Metadata.ASCII_STRING_MARSHALLER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,39 +124,49 @@ class DataConnectGrpcMetadataUnitTest {
}

@Test
fun `should include x-goog-request-params`() = runTest {
val dataConnectGrpcMetadataArb =
Arb.dataConnect.dataConnectGrpcMetadata(
connectorLocation = Arb.constant("q8mgtztcz2"),
)
fun `should include x-goog-request-params`() =
testMetadataIncludesHeader(
dataConnectGrpcMetadataArb =
Arb.dataConnect.dataConnectGrpcMetadata(
connectorLocation = Arb.constant("q8mgtztcz2"),
),
headerName = "x-goog-request-params",
getExpectedHeaderValue = { "location=q8mgtztcz2&frontend=data" },
)

checkAll(
propTestConfig,
dataConnectGrpcMetadataArb,
Arb.dataConnect.authTokenResult().orNull(nullProbability = 0.33),
Arb.dataConnect.appCheckTokenResult().orNull(nullProbability = 0.33),
Arb.enum<CallerSdkType>()
) { dataConnectGrpcMetadata, authToken, appCheckToken, callerSdkType ->
val metadata =
dataConnectGrpcMetadata.get(
authToken = authToken,
appCheckToken = appCheckToken,
callerSdkType = callerSdkType,
)
@Test
fun `should include x-client-platform`() =
testMetadataIncludesHeader(
headerName = "x-client-platform",
getExpectedHeaderValue = { "android" },
)

metadata.asClue {
it.keys() shouldContain "x-goog-request-params"
val metadataKey = Metadata.Key.of("x-goog-request-params", Metadata.ASCII_STRING_MARSHALLER)
it.get(metadataKey) shouldBe "location=q8mgtztcz2&frontend=data"
}
}
}
@Test
fun `should include x-client-version`() =
testMetadataIncludesHeader(
dataConnectGrpcMetadataArb =
Arb.dataConnect.dataConnectGrpcMetadata(
dataConnectSdkVersion = Arb.constant("v3q46qc2ax"),
),
headerName = "x-client-version",
getExpectedHeaderValue = { "v3q46qc2ax" },
)

@Test
fun `should include x-firebase-gmpid`() = runTest {
val dataConnectGrpcMetadataArb =
Arb.dataConnect.dataConnectGrpcMetadata(appId = Arb.constant("tvsxjeb745.appId"))
fun `should include x-firebase-gmpid`() =
testMetadataIncludesHeader(
dataConnectGrpcMetadataArb =
Arb.dataConnect.dataConnectGrpcMetadata(appId = Arb.constant("tvsxjeb745.appId")),
headerName = "x-firebase-gmpid",
getExpectedHeaderValue = { "tvsxjeb745.appId" },
)

private fun testMetadataIncludesHeader(
dataConnectGrpcMetadataArb: Arb<DataConnectGrpcMetadata> =
Arb.dataConnect.dataConnectGrpcMetadata(),
headerName: String,
getExpectedHeaderValue: (DataConnectGrpcMetadata) -> String,
) = runTest {
checkAll(
propTestConfig,
dataConnectGrpcMetadataArb,
Expand All @@ -172,9 +182,9 @@ class DataConnectGrpcMetadataUnitTest {
)

metadata.asClue {
it.keys() shouldContain "x-firebase-gmpid"
val metadataKey = Metadata.Key.of("x-firebase-gmpid", Metadata.ASCII_STRING_MARSHALLER)
it.get(metadataKey) shouldBe "tvsxjeb745.appId"
it.keys() shouldContain headerName.lowercase()
val metadataKey = Metadata.Key.of(headerName, Metadata.ASCII_STRING_MARSHALLER)
it.get(metadataKey) shouldBe getExpectedHeaderValue(dataConnectGrpcMetadata)
}
}
}
Expand Down
Loading
Loading