Skip to content

Commit

Permalink
feat: Track PG Adapter usage from user-agent headers (#1711)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
gauravsnj and gcf-owl-bot[bot] authored Feb 28, 2022
1 parent 8f30a52 commit cb640ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit cb640ab

Please sign in to comment.