Skip to content

Commit

Permalink
feat: support customize options for grpc-node. (#1115)
Browse files Browse the repository at this point in the history
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. 
```
  • Loading branch information
summer-ji-eng committed Sep 27, 2021
1 parent 7db4889 commit 82fb0cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions test/unit/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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));
});
Expand All @@ -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);
});
Expand Down

0 comments on commit 82fb0cb

Please sign in to comment.