Skip to content

Commit 2bb3a12

Browse files
authored
Retain GoogleAdsClient max inbound metadata and message size settings (#566)
Fixes #565
1 parent 3e82421 commit 2bb3a12

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

google-ads/src/main/java/com/google/ads/googleads/lib/GoogleAdsClient.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ public abstract class GoogleAdsClient extends AbstractGoogleAdsClient {
7070
/** The default endpoint for Google Ads API services. */
7171
private static final String DEFAULT_ENDPOINT = "googleads.googleapis.com:443";
7272

73+
/**
74+
* Default max inbound metadata (headers) size. Inbound headers for the Google Ads API may exceed
75+
* the default max of 8KB.
76+
*/
77+
@VisibleForTesting static final Integer DEFAULT_MAX_INBOUND_METADATA_SIZE = 16 * 1024 * 1024;
78+
79+
/**
80+
* Default max inbound message (response) size. Large response will often exceed the default of
81+
* 4MB.
82+
*/
83+
@VisibleForTesting static final Integer DEFAULT_MAX_INBOUND_MESSAGE_SIZE = 64 * 1024 * 1024;
84+
7385
static {
7486
// Alpha feature to optimize the client startup time.
7587
Primer.primeBasicsIfEnabled();
@@ -88,12 +100,8 @@ public static Builder newBuilder() {
88100
new RequestLogger(),
89101
clientBuilder.getHeaders(),
90102
clientBuilder.getEndpoint())))
91-
// Issue 131: inbound headers may exceed default (8kb) max header size.
92-
// Sets max header size to 16MB, which should be more than necessary.
93-
.setMaxInboundMetadataSize(16 * 1024 * 1024)
94-
// Sets max response size to 64MB, since large responses will often exceed the default
95-
// (4MB).
96-
.setMaxInboundMessageSize(64 * 1024 * 1024)
103+
.setMaxInboundMetadataSize(DEFAULT_MAX_INBOUND_METADATA_SIZE)
104+
.setMaxInboundMessageSize(DEFAULT_MAX_INBOUND_MESSAGE_SIZE)
97105
.build();
98106
clientBuilder
99107
.setEndpoint(DEFAULT_ENDPOINT)
@@ -584,6 +592,8 @@ public GoogleAdsClient build() {
584592
ImmutableList.of(
585593
new LoggingInterceptor(
586594
new RequestLogger(), getHeaders(), getEndpoint())))
595+
.setMaxInboundMetadataSize(DEFAULT_MAX_INBOUND_METADATA_SIZE)
596+
.setMaxInboundMessageSize(DEFAULT_MAX_INBOUND_MESSAGE_SIZE)
587597
.build();
588598
}
589599
if (transportChannelProvider.needsHeaders()) {

google-ads/src/test/java/com/google/ads/googleads/lib/GoogleAdsClientTest.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.google.ads.googleads.v10.services.SearchGoogleAdsStreamResponse;
4040
import com.google.api.gax.grpc.GaxGrpcProperties;
4141
import com.google.api.gax.grpc.GrpcStatusCode;
42+
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
4243
import com.google.api.gax.grpc.testing.LocalChannelProvider;
4344
import com.google.api.gax.grpc.testing.MockServiceHelper;
4445
import com.google.api.gax.rpc.ApiClientHeaderProvider;
@@ -190,10 +191,7 @@ public void testBuildFromPropertiesFile_withoutLoginCustomerId() throws IOExcept
190191

191192
// Build a new client from the file.
192193
GoogleAdsClient client =
193-
GoogleAdsClient.newBuilder()
194-
.fromPropertiesFile(propertiesFile)
195-
.setTransportChannelProvider(localChannelProvider)
196-
.build();
194+
GoogleAdsClient.newBuilder().fromPropertiesFile(propertiesFile).build();
197195
assertGoogleAdsClient(client, null, true);
198196
}
199197

@@ -253,7 +251,7 @@ public void setLoginCustomerId_canClearOnceSet() {
253251

254252
/** Tests building a client without the use of a properties file. */
255253
@Test
256-
public void buildWithoutPropertiesFile_supportsAllFields() throws IOException {
254+
public void buildWithoutPropertiesFile_supportsAllFields() {
257255
Credentials credentials =
258256
UserCredentials.newBuilder()
259257
.setClientId(CLIENT_ID)
@@ -265,7 +263,6 @@ public void buildWithoutPropertiesFile_supportsAllFields() throws IOException {
265263
.setCredentials(credentials)
266264
.setDeveloperToken(DEVELOPER_TOKEN)
267265
.setLoginCustomerId(LOGIN_CUSTOMER_ID)
268-
.setTransportChannelProvider(localChannelProvider)
269266
.build();
270267
assertGoogleAdsClient(client, true);
271268
}
@@ -888,6 +885,20 @@ private void assertGoogleAdsClient(
888885
serviceAccountCredentials.getScopes());
889886
}
890887

888+
if (client.getTransportChannelProvider() == client.getDefaultTransportChannelProvider()) {
889+
InstantiatingGrpcChannelProvider channelProvider =
890+
(InstantiatingGrpcChannelProvider) client.getTransportChannelProvider();
891+
assertEquals(
892+
"Max inbound metadata size",
893+
GoogleAdsClient.DEFAULT_MAX_INBOUND_METADATA_SIZE,
894+
channelProvider.getMaxInboundMetadataSize());
895+
assertEquals(
896+
"Max inbound message size",
897+
GoogleAdsClient.DEFAULT_MAX_INBOUND_MESSAGE_SIZE,
898+
// For some reason, this setting is only available on the builder.
899+
channelProvider.toBuilder().getMaxInboundMessageSize());
900+
}
901+
891902
assertEquals("Developer token", DEVELOPER_TOKEN, client.getDeveloperToken());
892903
assertEquals("Login customer id", loginCustomerId, client.getLoginCustomerId());
893904
}

0 commit comments

Comments
 (0)