Skip to content
Permalink
Browse files
fix: set x-goog-api-client as internal header (#293)
* fix: set x-goog-api-client as internal header

* review feedback
  • Loading branch information
kolea2 committed May 8, 2020
1 parent 9ea631a commit 3b58a4fa82e7a1e003bf119ce3b8b52b6eb52e47
@@ -519,7 +519,8 @@ private Builder() {
setTransportChannelProvider(defaultTransportChannelProvider());
setStreamWatchdogCheckInterval(baseDefaults.getStreamWatchdogCheckInterval());
setStreamWatchdogProvider(baseDefaults.getStreamWatchdogProvider());
setHeaderProvider(BigtableStubSettings.defaultApiClientHeaderProviderBuilder().build());
setInternalHeaderProvider(
BigtableStubSettings.defaultApiClientHeaderProviderBuilder().build());

setTracerFactory(
new OpencensusTracerFactory(
@@ -18,6 +18,8 @@
import static com.google.common.truth.Truth.assertThat;

import com.google.api.gax.batching.Batcher;
import com.google.api.gax.rpc.FixedHeaderProvider;
import com.google.api.gax.rpc.HeaderProvider;
import com.google.bigtable.v2.BigtableGrpc;
import com.google.bigtable.v2.CheckAndMutateRowRequest;
import com.google.bigtable.v2.CheckAndMutateRowResponse;
@@ -61,11 +63,14 @@ public class HeadersTest {
private static final String TABLE_NAME =
NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID);
private static final String APP_PROFILE_ID = "fake-profile";
private static final String TEST_FIXED_HEADER_STRING = "test_fixed_header";

private static final Metadata.Key<String> X_GOOG_REQUEST_PARAMS_KEY =
Metadata.Key.of("x-goog-request-params", Metadata.ASCII_STRING_MARSHALLER);
private static final Metadata.Key<String> API_CLIENT_HEADER_KEY =
Metadata.Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER);
private static final Metadata.Key<String> TEST_FIXED_HEADER =
Metadata.Key.of(TEST_FIXED_HEADER_STRING, Metadata.ASCII_STRING_MARSHALLER);

private Server server;
private BlockingQueue<Metadata> sentMetadata = new ArrayBlockingQueue<>(10);
@@ -91,9 +96,13 @@ public void setUp() throws Exception {
.setInstanceId(INSTANCE_ID)
.setAppProfileId(APP_PROFILE_ID);

HeaderProvider headerProvider =
FixedHeaderProvider.create(TEST_FIXED_HEADER_STRING, "test_header_value");

// Force immediate flush
settings
.stubSettings()
.setHeaderProvider(headerProvider)
.bulkMutateRowsSettings()
.setBatchingSettings(
settings
@@ -172,6 +181,9 @@ private void verifyHeaderSent() {
assertThat(apiClientValue).containsMatch("gl-java/[.\\d_]+");
assertThat(apiClientValue).containsMatch("gax/[.\\d_]+");
assertThat(apiClientValue).containsMatch("grpc/[.\\d_]+");

String fixedHeader = metadata.get(TEST_FIXED_HEADER);
assertThat(fixedHeader).isEqualTo("test_header_value");
}

private class MetadataInterceptor implements ServerInterceptor {

0 comments on commit 3b58a4f

Please sign in to comment.