Skip to content

Commit 8105dea

Browse files
fix: set keepalive configuration (#836)
- [PHP reference implementation](googleapis/google-cloud-php#3565) This adds two gRPC keepalive options: - `GRPC_ARG_KEEPALIVE_TIME_MS` to 30s - `GRPC_ARG_KEEPALIVE_TIMEOUT_MS` to 10s
1 parent 448465d commit 8105dea

File tree

2 files changed

+85
-70
lines changed

2 files changed

+85
-70
lines changed

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ export class Bigtable {
390390
libName: 'gccl',
391391
libVersion: PKG.version,
392392
scopes,
393+
'grpc.keepalive_time_ms': 30000,
394+
'grpc.keepalive_timeout_ms': 10000,
393395
},
394396
options
395397
);

test/index.ts

+83-70
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,38 @@ describe('Bigtable', () => {
148148
assert.deepStrictEqual(bigtable.api, {});
149149
});
150150

151+
it('should set grpc keepalive options', () => {
152+
const bigtable = Bigtable();
153+
assert.strictEqual(
154+
bigtable.options.BigtableClient['grpc.keepalive_time_ms'],
155+
30000
156+
);
157+
assert.strictEqual(
158+
bigtable.options.BigtableClient['grpc.keepalive_timeout_ms'],
159+
10000
160+
);
161+
162+
assert.strictEqual(
163+
bigtable.options.BigtableInstanceAdminClient['grpc.keepalive_time_ms'],
164+
30000
165+
);
166+
assert.strictEqual(
167+
bigtable.options.BigtableInstanceAdminClient[
168+
'grpc.keepalive_timeout_ms'
169+
],
170+
10000
171+
);
172+
173+
assert.strictEqual(
174+
bigtable.options.BigtableTableAdminClient['grpc.keepalive_time_ms'],
175+
30000
176+
);
177+
assert.strictEqual(
178+
bigtable.options.BigtableTableAdminClient['grpc.keepalive_timeout_ms'],
179+
10000
180+
);
181+
});
182+
151183
it('should cache a local google-auth-library instance', () => {
152184
const fakeGoogleAuthInstance = {};
153185
const options = {
@@ -163,6 +195,8 @@ describe('Bigtable', () => {
163195
libName: 'gccl',
164196
libVersion: PKG.version,
165197
scopes: EXPECTED_SCOPES,
198+
'grpc.keepalive_time_ms': 30000,
199+
'grpc.keepalive_timeout_ms': 10000,
166200
},
167201
options
168202
)
@@ -185,38 +219,37 @@ describe('Bigtable', () => {
185219
};
186220

187221
const bigtable = new Bigtable(options);
188-
const defaultOptions = {
189-
a: 'b',
190-
c: 'd',
191-
libName: 'gccl',
192-
libVersion: PKG.version,
193-
scopes: EXPECTED_SCOPES,
194-
};
222+
const expectedOptions = Object.assign(
223+
{
224+
port: 443,
225+
sslCreds: undefined,
226+
libName: 'gccl',
227+
libVersion: PKG.version,
228+
scopes: EXPECTED_SCOPES,
229+
'grpc.keepalive_time_ms': 30000,
230+
'grpc.keepalive_timeout_ms': 10000,
231+
},
232+
options
233+
);
195234

196235
assert.deepStrictEqual(bigtable.options, {
197236
BigtableClient: Object.assign(
198237
{
199238
servicePath: 'bigtable.googleapis.com',
200-
port: 443,
201-
sslCreds: undefined,
202239
},
203-
defaultOptions
240+
expectedOptions
204241
),
205242
BigtableInstanceAdminClient: Object.assign(
206243
{
207244
servicePath: 'bigtableadmin.googleapis.com',
208-
port: 443,
209-
sslCreds: undefined,
210245
},
211-
defaultOptions
246+
expectedOptions
212247
),
213248
BigtableTableAdminClient: Object.assign(
214249
{
215250
servicePath: 'bigtableadmin.googleapis.com',
216-
port: 443,
217-
sslCreds: undefined,
218251
},
219-
defaultOptions
252+
expectedOptions
220253
),
221254
});
222255
});
@@ -227,11 +260,22 @@ describe('Bigtable', () => {
227260
const options = {
228261
a: 'b',
229262
c: 'd',
230-
libName: 'gccl',
231-
libVersion: PKG.version,
232-
scopes: EXPECTED_SCOPES,
233263
};
234264

265+
const expectedOptions = Object.assign(
266+
{
267+
servicePath: 'override',
268+
port: 8080,
269+
sslCreds: grpc.credentials.createInsecure(),
270+
libName: 'gccl',
271+
libVersion: PKG.version,
272+
scopes: EXPECTED_SCOPES,
273+
'grpc.keepalive_time_ms': 30000,
274+
'grpc.keepalive_timeout_ms': 10000,
275+
},
276+
options
277+
);
278+
235279
const bigtable = new Bigtable(options);
236280

237281
assert.strictEqual(
@@ -240,30 +284,9 @@ describe('Bigtable', () => {
240284
);
241285

242286
assert.deepStrictEqual(bigtable.options, {
243-
BigtableClient: Object.assign(
244-
{
245-
servicePath: 'override',
246-
port: 8080,
247-
sslCreds: grpc.credentials.createInsecure(),
248-
},
249-
options
250-
),
251-
BigtableInstanceAdminClient: Object.assign(
252-
{
253-
servicePath: 'override',
254-
port: 8080,
255-
sslCreds: grpc.credentials.createInsecure(),
256-
},
257-
options
258-
),
259-
BigtableTableAdminClient: Object.assign(
260-
{
261-
servicePath: 'override',
262-
port: 8080,
263-
sslCreds: grpc.credentials.createInsecure(),
264-
},
265-
options
266-
),
287+
BigtableClient: expectedOptions,
288+
BigtableInstanceAdminClient: expectedOptions,
289+
BigtableTableAdminClient: expectedOptions,
267290
});
268291
});
269292

@@ -272,40 +295,30 @@ describe('Bigtable', () => {
272295
apiEndpoint: 'customEndpoint:9090',
273296
a: 'b',
274297
c: 'd',
275-
libName: 'gccl',
276-
libVersion: PKG.version,
277-
scopes: EXPECTED_SCOPES,
278298
};
279299

300+
const expectedOptions = Object.assign(
301+
{
302+
servicePath: 'customEndpoint',
303+
port: 9090,
304+
sslCreds: grpc.credentials.createInsecure(),
305+
libName: 'gccl',
306+
libVersion: PKG.version,
307+
scopes: EXPECTED_SCOPES,
308+
'grpc.keepalive_time_ms': 30000,
309+
'grpc.keepalive_timeout_ms': 10000,
310+
},
311+
options
312+
);
313+
280314
const bigtable = new Bigtable(options);
281315

282316
assert.strictEqual(bigtable.customEndpoint, options.apiEndpoint);
283317

284318
assert.deepStrictEqual(bigtable.options, {
285-
BigtableClient: Object.assign(
286-
{
287-
servicePath: 'customEndpoint',
288-
port: 9090,
289-
sslCreds: grpc.credentials.createInsecure(),
290-
},
291-
options
292-
),
293-
BigtableInstanceAdminClient: Object.assign(
294-
{
295-
servicePath: 'customEndpoint',
296-
port: 9090,
297-
sslCreds: grpc.credentials.createInsecure(),
298-
},
299-
options
300-
),
301-
BigtableTableAdminClient: Object.assign(
302-
{
303-
servicePath: 'customEndpoint',
304-
port: 9090,
305-
sslCreds: grpc.credentials.createInsecure(),
306-
},
307-
options
308-
),
319+
BigtableClient: expectedOptions,
320+
BigtableInstanceAdminClient: expectedOptions,
321+
BigtableTableAdminClient: expectedOptions,
309322
});
310323
});
311324

0 commit comments

Comments
 (0)