From 82fb0cb347211ffa511943febcb22c972f3407d3 Mon Sep 17 00:00:00 2001 From: Summer Ji Date: Mon, 27 Sep 2021 10:52:16 -0700 Subject: [PATCH] feat: support customize options for grpc-node. (#1115) Allow end user customize `grpc-node.` for `grpcOption` to create [grpc stub](https://github.com/googleapis/gax-nodejs/blob/main/src/grpc.ts#L430). ``` Some grpc-js users have experienced RESOURCE_EXHAUSTED errors as a result of underlying http2 sessions not being allowed to use enough memory. As of version 1.3.0, grpc-js provides a channel option called "grpc-node.max_session_memory" to adjust how much memory those sessions can use. The value is in megabytes and the default is 10. I suggest modifying that value to see if that helps. ``` --- src/grpc.ts | 3 +++ test/unit/grpc.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/grpc.ts b/src/grpc.ts index 5fde573d2..177781456 100644 --- a/src/grpc.ts +++ b/src/grpc.ts @@ -423,6 +423,9 @@ export class GrpcClient { } grpcOptions[key] = value as string | number; } + if (key.startsWith('grpc-node.')) { + grpcOptions[key] = value as string | number; + } }); const stub = new CreateStub( serviceAddress, diff --git a/test/unit/grpc.ts b/test/unit/grpc.ts index 42f0b023f..56d0b36da 100644 --- a/test/unit/grpc.ts +++ b/test/unit/grpc.ts @@ -188,6 +188,7 @@ describe('grpc', () => { }, 'grpc.channelFactoryOverride': () => {}, 'grpc.gcpApiConfig': {}, + 'grpc-node.max_session_memory': 10, }; // @ts-ignore return grpcClient.createStub(DummyStub, opts).then(stub => { @@ -201,6 +202,7 @@ describe('grpc', () => { 'callInvocationTransformer', // note: no grpc. prefix for grpc-gcp options 'channelFactoryOverride', 'gcpApiConfig', + 'grpc-node.max_session_memory', ].forEach(k => { assert(stub.options.hasOwnProperty(k)); }); @@ -214,6 +216,10 @@ describe('grpc', () => { (dummyStub.options['callInvocationTransformer'] as Function)(), 42 ); + assert.strictEqual( + dummyStub.options['grpc-node.max_session_memory'], + 10 + ); ['servicePath', 'port', 'other_dummy_options'].forEach(k => { assert.strictEqual(stub.options.hasOwnProperty(k), false); });