Skip to content

Commit 666a374

Browse files
authored
Merge pull request #2645 from murgatroid99/master_merge_1.9.x
Merge 1.9.x into master
2 parents 2a7c906 + 3915f57 commit 666a374

30 files changed

+544
-161
lines changed

doc/environment_variables.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ can be set.
4242
- `subchannel_internals` - Traces HTTP/2 session state. Includes per-call logs.
4343
- `channel_stacktrace` - Traces channel construction events with stack traces.
4444
- `keepalive` - Traces gRPC keepalive pings
45-
- `index` - Traces module loading
4645
- `outlier_detection` - Traces outlier detection events
4746

4847
The following tracers are added by the `@grpc/grpc-js-xds` library:
@@ -62,4 +61,4 @@ can be set.
6261
- DEBUG - log all gRPC messages
6362
- INFO - log INFO and ERROR message
6463
- ERROR - log only errors (default)
65-
- NONE - won't log any
64+
- NONE - won't log any

packages/grpc-js-xds/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @grpc/grpc-js xDS plugin
22

3-
This package provides support for the `xds://` URL scheme to the `@grpc/grpc-js` library. The latest version of this package is compatible with `@grpc/grpc-js` version 1.2.x.
3+
This package provides support for the `xds://` URL scheme to the `@grpc/grpc-js` library. The latest version of this package is compatible with `@grpc/grpc-js` version 1.9.x.
44

55
## Installation
66

@@ -29,4 +29,6 @@ const client = new MyServiceClient('xds:///example.com:123');
2929
- [xDS Client-Side Fault Injection](https://github.com/grpc/proposal/blob/master/A33-Fault-Injection.md)
3030
- [Client Status Discovery Service](https://github.com/grpc/proposal/blob/master/A40-csds-support.md)
3131
- [Outlier Detection](https://github.com/grpc/proposal/blob/master/A50-xds-outlier-detection.md)
32-
- [xDS Retry Support](https://github.com/grpc/proposal/blob/master/A44-xds-retry.md)
32+
- [xDS Retry Support](https://github.com/grpc/proposal/blob/master/A44-xds-retry.md)
33+
- [xDS Aggregate and Logical DNS Clusters](https://github.com/grpc/proposal/blob/master/A37-xds-aggregate-and-logical-dns-clusters.md)'
34+
- [xDS Federation](https://github.com/grpc/proposal/blob/master/A47-xds-federation.md) (Currently experimental, enabled by environment variable `GRPC_EXPERIMENTAL_XDS_FEDERATION`)

packages/grpc-js-xds/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/grpc-js-xds",
3-
"version": "1.8.2",
3+
"version": "1.9.2",
44
"description": "Plugin for @grpc/grpc-js. Adds the xds:// URL scheme and associated features.",
55
"main": "build/src/index.js",
66
"scripts": {
@@ -9,7 +9,7 @@
99
"clean": "gts clean",
1010
"compile": "tsc",
1111
"fix": "gts fix",
12-
"prepare": "npm run compile",
12+
"prepare": "npm run generate-types && npm run compile",
1313
"pretest": "npm run compile",
1414
"posttest": "npm run check",
1515
"generate-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs deps/envoy-api/ deps/xds/ deps/googleapis/ deps/protoc-gen-validate/ -O src/generated/ --grpcLib @grpc/grpc-js envoy/service/discovery/v3/ads.proto envoy/service/load_stats/v3/lrs.proto envoy/config/listener/v3/listener.proto envoy/config/route/v3/route.proto envoy/config/cluster/v3/cluster.proto envoy/config/endpoint/v3/endpoint.proto envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto udpa/type/v1/typed_struct.proto xds/type/v3/typed_struct.proto envoy/extensions/filters/http/fault/v3/fault.proto envoy/service/status/v3/csds.proto envoy/extensions/load_balancing_policies/wrr_locality/v3/wrr_locality.proto envoy/extensions/load_balancing_policies/ring_hash/v3/ring_hash.proto envoy/extensions/load_balancing_policies/pick_first/v3/pick_first.proto",
@@ -50,7 +50,7 @@
5050
"xxhash-wasm": "^1.0.2"
5151
},
5252
"peerDependencies": {
53-
"@grpc/grpc-js": "~1.8.0"
53+
"@grpc/grpc-js": "~1.9.0"
5454
},
5555
"engines": {
5656
"node": ">=10.10.0"

packages/grpc-js-xds/src/resolver-xds.ts

+2
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,11 @@ class XdsResolver implements Resolver {
677677
destroy() {
678678
if (this.listenerResourceName) {
679679
ListenerResourceType.cancelWatch(this.xdsClient, this.listenerResourceName, this.ldsWatcher);
680+
this.isLdsWatcherActive = false;
680681
}
681682
if (this.latestRouteConfigName) {
682683
RouteConfigurationResourceType.cancelWatch(this.xdsClient, this.latestRouteConfigName, this.rdsWatcher);
684+
this.latestRouteConfigName = null;
683685
}
684686
}
685687

packages/grpc-js-xds/src/xds-client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,8 @@ class XdsSingleServerClient {
924924
}
925925

926926
onLrsStreamReceivedMessage() {
927-
this.adsBackoff.stop();
928-
this.adsBackoff.reset();
927+
this.lrsBackoff.stop();
928+
this.lrsBackoff.reset();
929929
}
930930

931931
handleLrsStreamEnd() {

packages/grpc-js-xds/test/client.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { credentials, loadPackageDefinition, ServiceError } from "@grpc/grpc-js";
18+
import { ChannelOptions, credentials, loadPackageDefinition, ServiceError } from "@grpc/grpc-js";
1919
import { loadSync } from "@grpc/proto-loader";
2020
import { ProtoGrpcType } from "./generated/echo";
2121
import { EchoTestServiceClient } from "./generated/grpc/testing/EchoTestService";
@@ -44,14 +44,14 @@ export class XdsTestClient {
4444
private client: EchoTestServiceClient;
4545
private callInterval: NodeJS.Timer;
4646

47-
constructor(target: string, bootstrapInfo: string) {
48-
this.client = new loadedProtos.grpc.testing.EchoTestService(target, credentials.createInsecure(), {[BOOTSTRAP_CONFIG_KEY]: bootstrapInfo});
47+
constructor(target: string, bootstrapInfo: string, options?: ChannelOptions) {
48+
this.client = new loadedProtos.grpc.testing.EchoTestService(target, credentials.createInsecure(), {...options, [BOOTSTRAP_CONFIG_KEY]: bootstrapInfo});
4949
this.callInterval = setInterval(() => {}, 0);
5050
clearInterval(this.callInterval);
5151
}
5252

53-
static createFromServer(targetName: string, xdsServer: XdsServer) {
54-
return new XdsTestClient(`xds:///${targetName}`, xdsServer.getBootstrapInfoString());
53+
static createFromServer(targetName: string, xdsServer: XdsServer, options?: ChannelOptions) {
54+
return new XdsTestClient(`xds:///${targetName}`, xdsServer.getBootstrapInfoString(), options);
5555
}
5656

5757
startCalls(interval: number) {
@@ -98,4 +98,8 @@ export class XdsTestClient {
9898
}
9999
sendInner(count, callback);
100100
}
101+
102+
getConnectivityState() {
103+
return this.client.getChannel().getConnectivityState(false);
104+
}
101105
}

packages/grpc-js-xds/test/test-core.ts

+31
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { XdsServer } from "./xds-server";
2222

2323
import { register } from "../src";
2424
import assert = require("assert");
25+
import { connectivityState } from "@grpc/grpc-js";
2526

2627
register();
2728

@@ -60,4 +61,34 @@ describe('core xDS functionality', () => {
6061
}, reason => done(reason));
6162
}, reason => done(reason));
6263
});
64+
it('should be able to enter and exit idle', function(done) {
65+
this.timeout(5000);
66+
const cluster = new FakeEdsCluster('cluster1', 'endpoint1', [{backends: [new Backend()], locality:{region: 'region1'}}]);
67+
const routeGroup = new FakeRouteGroup('listener1', 'route1', [{cluster: cluster}]);
68+
routeGroup.startAllBackends().then(() => {
69+
xdsServer.setEdsResource(cluster.getEndpointConfig());
70+
xdsServer.setCdsResource(cluster.getClusterConfig());
71+
xdsServer.setRdsResource(routeGroup.getRouteConfiguration());
72+
xdsServer.setLdsResource(routeGroup.getListener());
73+
xdsServer.addResponseListener((typeUrl, responseState) => {
74+
if (responseState.state === 'NACKED') {
75+
client.stopCalls();
76+
assert.fail(`Client NACKED ${typeUrl} resource with message ${responseState.errorMessage}`);
77+
}
78+
})
79+
client = XdsTestClient.createFromServer('listener1', xdsServer, {
80+
'grpc.client_idle_timeout_ms': 1000,
81+
});
82+
client.sendOneCall(error => {
83+
assert.ifError(error);
84+
assert.strictEqual(client.getConnectivityState(), connectivityState.READY);
85+
setTimeout(() => {
86+
assert.strictEqual(client.getConnectivityState(), connectivityState.IDLE);
87+
client.sendOneCall(error => {
88+
done(error);
89+
})
90+
}, 1100);
91+
});
92+
}, reason => done(reason));
93+
});
6394
});

packages/grpc-js/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Many channel arguments supported in `grpc` are not supported in `@grpc/grpc-js`.
6565
- `grpc.service_config_disable_resolution`
6666
- `grpc.client_idle_timeout_ms`
6767
- `grpc-node.max_session_memory`
68+
- `grpc-node.tls_enable_trace`
6869
- `channelOverride`
6970
- `channelFactoryOverride`
7071

packages/grpc-js/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/grpc-js",
3-
"version": "1.8.21",
3+
"version": "1.9.14",
44
"description": "gRPC Library for Node - pure JS implementation",
55
"homepage": "https://grpc.io/",
66
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
@@ -65,7 +65,7 @@
6565
"generate-test-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --include-dirs test/fixtures/ -O test/generated/ --grpcLib ../../src/index test_service.proto"
6666
},
6767
"dependencies": {
68-
"@grpc/proto-loader": "^0.7.0",
68+
"@grpc/proto-loader": "^0.7.8",
6969
"@types/node": ">=12.12.47"
7070
},
7171
"files": [

packages/grpc-js/src/backoff-timeout.ts

+15
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export class BackoffTimeout {
7878
* running is true.
7979
*/
8080
private startTime: Date = new Date();
81+
/**
82+
* The approximate time that the currently running timer will end. Only valid
83+
* if running is true.
84+
*/
85+
private endTime: Date = new Date();
8186

8287
constructor(private callback: () => void, options?: BackoffOptions) {
8388
if (options) {
@@ -100,6 +105,8 @@ export class BackoffTimeout {
100105
}
101106

102107
private runTimer(delay: number) {
108+
this.endTime = this.startTime;
109+
this.endTime.setMilliseconds(this.endTime.getMilliseconds() + this.nextDelay);
103110
clearTimeout(this.timerId);
104111
this.timerId = setTimeout(() => {
105112
this.callback();
@@ -178,4 +185,12 @@ export class BackoffTimeout {
178185
this.hasRef = false;
179186
this.timerId.unref?.();
180187
}
188+
189+
/**
190+
* Get the approximate timestamp of when the timer will fire. Only valid if
191+
* this.isRunning() is true.
192+
*/
193+
getEndTime() {
194+
return this.endTime;
195+
}
181196
}

packages/grpc-js/src/http_proxy.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
import { ChannelOptions } from './channel-options';
3131
import { GrpcUri, parseUri, splitHostPort, uriToString } from './uri-parser';
3232
import { URL } from 'url';
33+
import { DEFAULT_PORT } from './resolver-dns';
3334

3435
const TRACER_NAME = 'proxy';
3536

@@ -189,12 +190,19 @@ export function getProxiedConnection(
189190
if (parsedTarget === null) {
190191
return Promise.resolve<ProxyConnectionResult>({});
191192
}
193+
const splitHostPost = splitHostPort(parsedTarget.path);
194+
if (splitHostPost === null) {
195+
return Promise.resolve<ProxyConnectionResult>({});
196+
}
197+
const hostPort = `${splitHostPost.host}:${
198+
splitHostPost.port ?? DEFAULT_PORT
199+
}`;
192200
const options: http.RequestOptions = {
193201
method: 'CONNECT',
194-
path: parsedTarget.path,
202+
path: hostPort,
195203
};
196204
const headers: http.OutgoingHttpHeaders = {
197-
Host: parsedTarget.path,
205+
Host: hostPort,
198206
};
199207
// Connect to the subchannel address as a proxy
200208
if (isTcpSubchannelAddress(address)) {

packages/grpc-js/src/index.ts

-7
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,7 @@ import * as load_balancer_outlier_detection from './load-balancer-outlier-detect
276276
import * as channelz from './channelz';
277277
import { Deadline } from './deadline';
278278

279-
const clientVersion = require('../../package.json').version;
280-
281279
(() => {
282-
logging.trace(
283-
LogVerbosity.DEBUG,
284-
'index',
285-
'Loading @grpc/grpc-js version ' + clientVersion
286-
);
287280
resolver_dns.setup();
288281
resolver_uds.setup();
289282
resolver_ip.setup();

0 commit comments

Comments
 (0)