Merge pull request #1200 from murgatroid99/grpc-js_channel_args

grpc-js: Add more channel args
This commit is contained in:
Michael Lumish 2019-12-18 10:18:44 -08:00 committed by GitHub
commit 3402c706a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 12 deletions

View File

@ -3,7 +3,7 @@
Feature | `grpc` | `@grpc/grpc-js` Feature | `grpc` | `@grpc/grpc-js`
--------|--------|---------- --------|--------|----------
Client | :heavy_check_mark: | :heavy_check_mark: Client | :heavy_check_mark: | :heavy_check_mark:
Server | :heavy_check_mark: | :x: Server | :heavy_check_mark: | :heavy_check_mark:
Unary RPCs | :heavy_check_mark: | :heavy_check_mark: Unary RPCs | :heavy_check_mark: | :heavy_check_mark:
Streaming RPCs | :heavy_check_mark: | :heavy_check_mark: Streaming RPCs | :heavy_check_mark: | :heavy_check_mark:
Deadlines | :heavy_check_mark: | :heavy_check_mark: Deadlines | :heavy_check_mark: | :heavy_check_mark:
@ -17,8 +17,8 @@ Connection Keepalives | :heavy_check_mark: | :heavy_check_mark:
HTTP Connect Support | :heavy_check_mark: | :x: HTTP Connect Support | :heavy_check_mark: | :x:
Retries | :heavy_check_mark: | :x: Retries | :heavy_check_mark: | :x:
Stats/tracing/monitoring | :heavy_check_mark: | :x: Stats/tracing/monitoring | :heavy_check_mark: | :x:
Load Balancing | :heavy_check_mark: | :x: Load Balancing | :heavy_check_mark: | Pick first and round robin
Initial Metadata Options | :heavy_check_mark: | :x: Initial Metadata Options | :heavy_check_mark: | only `waitForReady`
Other Properties | `grpc` | `@grpc/grpc-js` Other Properties | `grpc` | `@grpc/grpc-js`
-----------------|--------|---------------- -----------------|--------|----------------
@ -37,5 +37,9 @@ In addition, all channel arguments defined in [this header file](https://github.
- `grpc.keepalive_time_ms` - `grpc.keepalive_time_ms`
- `grpc.keepalive_timeout_ms` - `grpc.keepalive_timeout_ms`
- `grpc.service_config` - `grpc.service_config`
- `grpc.max_concurrent_streams`
- `grpc.initial_reconnect_backoff_ms`
- `grpc.max_reconnect_backoff_ms`
- `grpc.use_local_subchannel_pool`
- `channelOverride` - `channelOverride`
- `channelFactoryOverride` - `channelFactoryOverride`

View File

@ -26,6 +26,10 @@ export interface ChannelOptions {
'grpc.keepalive_time_ms'?: number; 'grpc.keepalive_time_ms'?: number;
'grpc.keepalive_timeout_ms'?: number; 'grpc.keepalive_timeout_ms'?: number;
'grpc.service_config'?: string; 'grpc.service_config'?: string;
'grpc.max_concurrent_streams'?: number;
'grpc.initial_reconnect_backoff_ms'?: number;
'grpc.max_reconnect_backoff_ms'?: number;
'grpc.use_local_subchannel_pool'?: number;
[key: string]: string | number | undefined; [key: string]: string | number | undefined;
} }
@ -41,6 +45,10 @@ export const recognizedOptions = {
'grpc.keepalive_time_ms': true, 'grpc.keepalive_time_ms': true,
'grpc.keepalive_timeout_ms': true, 'grpc.keepalive_timeout_ms': true,
'grpc.service_config': true, 'grpc.service_config': true,
'grpc.max_concurrent_streams': true,
'grpc.initial_reconnect_backoff_ms': true,
'grpc.max_reconnect_backoff_ms': true,
'grpc.use_local_subchannel_pool': true,
}; };
export function channelOptionsEqual( export function channelOptionsEqual(

View File

@ -129,8 +129,9 @@ export class ChannelImplementation implements Channel {
private readonly credentials: ChannelCredentials, private readonly credentials: ChannelCredentials,
private readonly options: ChannelOptions private readonly options: ChannelOptions
) { ) {
// TODO(murgatroid99): check channel arg for getting a private pool /* The global boolean parameter to getSubchannelPool has the inverse meaning to what
this.subchannelPool = getSubchannelPool(true); * the grpc.use_local_subchannel_pool channel option means. */
this.subchannelPool = getSubchannelPool((options['grpc.use_local_subchannel_pool'] ?? 0) === 0);
const channelControlHelper: ChannelControlHelper = { const channelControlHelper: ChannelControlHelper = {
createSubchannel: ( createSubchannel: (
subchannelAddress: string, subchannelAddress: string,

View File

@ -45,6 +45,7 @@ import {
ServerStatusResponse, ServerStatusResponse,
} from './server-call'; } from './server-call';
import { ServerCredentials } from './server-credentials'; import { ServerCredentials } from './server-credentials';
import { ChannelOptions } from './channel-options';
function noop(): void {} function noop(): void {}
@ -95,8 +96,11 @@ export class Server {
>(); >();
private sessions = new Set<http2.ServerHttp2Session>(); private sessions = new Set<http2.ServerHttp2Session>();
private started = false; private started = false;
private options: ChannelOptions;
constructor(options?: object) {} constructor(options?: ChannelOptions) {
this.options = options ?? {};
}
addProtoService(): void { addProtoService(): void {
throw new Error('Not implemented. Use addService() instead'); throw new Error('Not implemented. Use addService() instead');
@ -197,13 +201,16 @@ export class Server {
const url = new URL(`http://${port}`); const url = new URL(`http://${port}`);
const options: ListenOptions = { host: url.hostname, port: +url.port }; const options: ListenOptions = { host: url.hostname, port: +url.port };
const serverOptions: http2.ServerOptions = {};
if ('grpc.max_concurrent_streams' in this.options) {
serverOptions.settings = {maxConcurrentStreams: this.options['grpc.max_concurrent_streams']};
}
if (creds._isSecure()) { if (creds._isSecure()) {
this.http2Server = http2.createSecureServer( const secureServerOptions = Object.assign(serverOptions, creds._getSettings()!);
creds._getSettings() as http2.SecureServerOptions this.http2Server = http2.createSecureServer(secureServerOptions);
);
} else { } else {
this.http2Server = http2.createServer(); this.http2Server = http2.createServer(serverOptions);
} }
this.http2Server.setTimeout(0, noop); this.http2Server.setTimeout(0, noop);

View File

@ -22,7 +22,7 @@ import { Http2CallStream } from './call-stream';
import { ChannelOptions } from './channel-options'; import { ChannelOptions } from './channel-options';
import { PeerCertificate, checkServerIdentity } from 'tls'; import { PeerCertificate, checkServerIdentity } from 'tls';
import { ConnectivityState } from './channel'; import { ConnectivityState } from './channel';
import { BackoffTimeout } from './backoff-timeout'; import { BackoffTimeout, BackoffOptions } from './backoff-timeout';
import { getDefaultAuthority } from './resolver'; import { getDefaultAuthority } from './resolver';
import * as logging from './logging'; import * as logging from './logging';
import { LogVerbosity } from './constants'; import { LogVerbosity } from './constants';
@ -170,6 +170,10 @@ export class Subchannel {
clearTimeout(this.keepaliveIntervalId); clearTimeout(this.keepaliveIntervalId);
this.keepaliveTimeoutId = setTimeout(() => {}, 0); this.keepaliveTimeoutId = setTimeout(() => {}, 0);
clearTimeout(this.keepaliveTimeoutId); clearTimeout(this.keepaliveTimeoutId);
const backoffOptions: BackoffOptions = {
initialDelay: options['grpc.initial_reconnect_backoff_ms'],
maxDelay: options['grpc.max_reconnect_backoff_ms']
};
this.backoffTimeout = new BackoffTimeout(() => { this.backoffTimeout = new BackoffTimeout(() => {
if (this.continueConnecting) { if (this.continueConnecting) {
this.transitionToState( this.transitionToState(
@ -182,7 +186,7 @@ export class Subchannel {
ConnectivityState.IDLE ConnectivityState.IDLE
); );
} }
}); }, backoffOptions);
} }
/** /**