Skip to content
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

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

Merged
merged 6 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
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 @@ -502,6 +502,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 @@ -518,6 +519,14 @@ public void testSetClientLibToken() {
.build();
assertThat(options.getClientLibToken()).isEqualTo(hibernateToken);

options =
SpannerOptions.newBuilder()
.setProjectId("some-project")
.setCredentials(NoCredentials.getInstance())
.setClientLibToken(pgAdapterToken)
.build();
assertThat(options.getClientLibToken()).isEqualTo(pgAdapterToken);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we prefer the use of assertEquals(expected, actual) (add import static org.junit.Assert.assertEquals at the top of the file to import it)

I know that it is not consistent with the other tests here, but the general rule of thumb is to use this method for new code, even when it is different from the surrounding code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @olavloite for mentioning this. I've changed it and will remember this in future


options =
SpannerOptions.newBuilder()
.setProjectId("some-project")
Expand Down