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

fix: fix user agent format #3288

Merged
merged 2 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: fix user agent format
  • Loading branch information
mutianf committed Oct 13, 2021
commit 3bb4caba3452c898f3d60753294716772132805e
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import com.google.auth.Credentials;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials;
import com.google.cloud.bigtable.Version;
import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings;
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings;
import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStubSettings;
Expand Down Expand Up @@ -465,17 +464,15 @@ public ManagedChannelBuilder apply(ManagedChannelBuilder channelBuilder) {
private void configureHeaderProvider(StubSettings.Builder<?, ?> stubSettings) {
ImmutableMap.Builder<String, String> headersBuilder = ImmutableMap.<String, String>builder();
List<String> userAgentParts = Lists.newArrayList();
userAgentParts.add("hbase-" + VersionInfo.getVersion());
userAgentParts.add("bigtable-" + Version.VERSION);
userAgentParts.add("bigtable-hbase-" + BigtableHBaseVersion.getVersion());
userAgentParts.add("jdk-" + System.getProperty("java.specification.version"));
userAgentParts.add("hbase/" + VersionInfo.getVersion());
userAgentParts.add("bigtable-hbase/" + BigtableHBaseVersion.getVersion());

String customUserAgent = configuration.get(CUSTOM_USER_AGENT_KEY);
if (customUserAgent != null) {
userAgentParts.add(customUserAgent);
}

String userAgent = Joiner.on(",").join(userAgentParts);
String userAgent = Joiner.on(" ").join(userAgentParts);
headersBuilder.put(USER_AGENT_KEY.name(), userAgent);

String tracingCookie = configuration.get(BigtableOptionsFactory.BIGTABLE_TRACING_COOKIE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.auth.Credentials;
import com.google.cloud.bigtable.Version;
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
import com.google.cloud.bigtable.hbase.BigtableConfiguration;
Expand Down Expand Up @@ -127,11 +126,10 @@ public void testDataSettingsBasicKeys() throws IOException {
assertEquals(TEST_HOST + ":" + TEST_PORT, dataSettings.getStubSettings().getEndpoint());
Map<String, String> headers = dataSettings.getStubSettings().getHeaderProvider().getHeaders();
assertTrue(headers.get(GrpcUtil.USER_AGENT_KEY.name()).contains(userAgent));
assertTrue(headers.get(GrpcUtil.USER_AGENT_KEY.name()).contains("bigtable-" + Version.VERSION));
assertTrue(
headers
.get(GrpcUtil.USER_AGENT_KEY.name())
.contains("bigtable-hbase-" + BigtableHBaseVersion.getVersion()));
.contains("bigtable-hbase/" + BigtableHBaseVersion.getVersion()));
assertTrue(headers.get("cookie").equals(fakeTracingCookie));
assertEquals(
credentials, dataSettings.getStubSettings().getCredentialsProvider().getCredentials());
Expand Down