Skip to content

Commit cb640ab

Browse files
feat: Track PG Adapter usage from user-agent headers (#1711)
* Added the string "pg-adapter" in the list of allowed client library token, so that when PG Adapter connects via client library by passing the string "pg-adapter" in the user-agent header, it doesn't get discarded. * Added an additional test case for the testSetClientLibToken test. * Changed assertThat to assertEquals * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Changed assertThat to assertEquals Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 8f30a52 commit cb640ab

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class SpannerOptions extends ServiceOptions<Spanner, SpannerOptions> {
8080
private static final String JDBC_API_CLIENT_LIB_TOKEN = "sp-jdbc";
8181
private static final String HIBERNATE_API_CLIENT_LIB_TOKEN = "sp-hib";
8282
private static final String LIQUIBASE_API_CLIENT_LIB_TOKEN = "sp-liq";
83+
private static final String PG_ADAPTER_CLIENT_LIB_TOKEN = "pg-adapter";
8384

8485
private static final String API_SHORT_NAME = "Spanner";
8586
private static final String DEFAULT_HOST = "https://spanner.googleapis.com";
@@ -657,7 +658,8 @@ public static class Builder
657658
ServiceOptions.getGoogApiClientLibName(),
658659
JDBC_API_CLIENT_LIB_TOKEN,
659660
HIBERNATE_API_CLIENT_LIB_TOKEN,
660-
LIQUIBASE_API_CLIENT_LIB_TOKEN);
661+
LIQUIBASE_API_CLIENT_LIB_TOKEN,
662+
PG_ADAPTER_CLIENT_LIB_TOKEN);
661663
private TransportChannelProvider channelProvider;
662664

663665
@SuppressWarnings("rawtypes")

google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.truth.Truth.assertThat;
2020
import static org.hamcrest.CoreMatchers.is;
2121
import static org.hamcrest.MatcherAssert.assertThat;
22+
import static org.junit.Assert.assertEquals;
2223
import static org.junit.Assert.assertSame;
2324
import static org.junit.Assert.assertThrows;
2425
import static org.mockito.Mockito.mock;
@@ -502,6 +503,7 @@ public void testDoNotCacheClosedSpannerInstance() {
502503
public void testSetClientLibToken() {
503504
final String jdbcToken = "sp-jdbc";
504505
final String hibernateToken = "sp-hib";
506+
final String pgAdapterToken = "pg-adapter";
505507
SpannerOptions options =
506508
SpannerOptions.newBuilder()
507509
.setProjectId("some-project")
@@ -522,8 +524,16 @@ public void testSetClientLibToken() {
522524
SpannerOptions.newBuilder()
523525
.setProjectId("some-project")
524526
.setCredentials(NoCredentials.getInstance())
527+
.setClientLibToken(pgAdapterToken)
525528
.build();
526-
assertThat(options.getClientLibToken()).isEqualTo(ServiceOptions.getGoogApiClientLibName());
529+
assertEquals(options.getClientLibToken(), pgAdapterToken);
530+
531+
options =
532+
SpannerOptions.newBuilder()
533+
.setProjectId("some-project")
534+
.setCredentials(NoCredentials.getInstance())
535+
.build();
536+
assertEquals(options.getClientLibToken(), ServiceOptions.getGoogApiClientLibName());
527537
}
528538

529539
@Test(expected = IllegalArgumentException.class)

0 commit comments

Comments
 (0)