Skip to content

feat: Track PG Adapter usage from user-agent headers #1711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 28, 2022
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-spanner'
If you are using Gradle without BOM, add this to your dependencies

```Groovy
implementation 'com.google.cloud:google-cloud-spanner:6.19.1'
implementation 'com.google.cloud:google-cloud-spanner:6.20.0'
```

If you are using SBT, add this to your dependencies

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.19.1"
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.20.0"
```

## Authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class SpannerOptions extends ServiceOptions<Spanner, SpannerOptions> {
private static final String JDBC_API_CLIENT_LIB_TOKEN = "sp-jdbc";
private static final String HIBERNATE_API_CLIENT_LIB_TOKEN = "sp-hib";
private static final String LIQUIBASE_API_CLIENT_LIB_TOKEN = "sp-liq";
private static final String PG_ADAPTER_CLIENT_LIB_TOKEN = "pg-adapter";

private static final String API_SHORT_NAME = "Spanner";
private static final String DEFAULT_HOST = "https://spanner.googleapis.com";
Expand Down Expand Up @@ -657,7 +658,8 @@ public static class Builder
ServiceOptions.getGoogApiClientLibName(),
JDBC_API_CLIENT_LIB_TOKEN,
HIBERNATE_API_CLIENT_LIB_TOKEN,
LIQUIBASE_API_CLIENT_LIB_TOKEN);
LIQUIBASE_API_CLIENT_LIB_TOKEN,
PG_ADAPTER_CLIENT_LIB_TOKEN);
private TransportChannelProvider channelProvider;

@SuppressWarnings("rawtypes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -502,6 +503,7 @@ public void testDoNotCacheClosedSpannerInstance() {
public void testSetClientLibToken() {
final String jdbcToken = "sp-jdbc";
final String hibernateToken = "sp-hib";
final String pgAdapterToken = "pg-adapter";
SpannerOptions options =
SpannerOptions.newBuilder()
.setProjectId("some-project")
Expand All @@ -522,8 +524,16 @@ public void testSetClientLibToken() {
SpannerOptions.newBuilder()
.setProjectId("some-project")
.setCredentials(NoCredentials.getInstance())
.setClientLibToken(pgAdapterToken)
.build();
assertThat(options.getClientLibToken()).isEqualTo(ServiceOptions.getGoogApiClientLibName());
assertEquals(options.getClientLibToken(), pgAdapterToken);

options =
SpannerOptions.newBuilder()
.setProjectId("some-project")
.setCredentials(NoCredentials.getInstance())
.build();
assertEquals(options.getClientLibToken(), ServiceOptions.getGoogApiClientLibName());
}

@Test(expected = IllegalArgumentException.class)
Expand Down